Skip to content

Commit f12ecca

Browse files
committed
Clean up ignore utility comments and inline options type
- remove comments └── apps └── editor └── src └── utils └── ignore ├── ignore.spec.ts ├── ignore.ts └── index.ts
1 parent a00a199 commit f12ecca

2 files changed

Lines changed: 1 addition & 36 deletions

File tree

‎apps/editor/src/utils/ignore/ignore.ts‎

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
export type Ignore_Options = {
2-
/** Match case-insensitively. Defaults to `true`, like the `ignore` package. */
3-
ignore_case?: boolean
4-
}
5-
61
type Rule = {
72
regex: RegExp
83
negative: boolean
@@ -24,7 +19,6 @@ const has_trailing_backslash = (text: string): boolean => {
2419
return count % 2 === 1
2520
}
2621

27-
// Trailing spaces are dropped unless the last one is escaped with a backslash.
2822
const trim_trailing_spaces = (line: string): string => {
2923
let end = line.length
3024
while (end > 0 && line[end - 1] === ' ') end--
@@ -38,8 +32,6 @@ const trim_trailing_spaces = (line: string): string => {
3832
return line.slice(0, end)
3933
}
4034

41-
// Translates the bracket expression starting at `glob[start] === '['`.
42-
// Returns `undefined` when it is never closed, which makes the rule match nothing.
4335
const parse_bracket = (
4436
glob: string,
4537
start: number
@@ -58,9 +50,7 @@ const parse_bracket = (
5850
while (i < glob.length) {
5951
let char = glob[i]
6052

61-
// A `]` right after `[` or `[!` is a literal member, not the terminator
6253
if (char === ']' && !is_first) {
63-
// A bracket expression never matches a path separator
6454
const source = negated
6555
? `[^/${members}]`
6656
: members
@@ -84,7 +74,6 @@ const parse_bracket = (
8474
i++
8575
if (to === undefined) return undefined
8676
}
87-
// An out-of-order range matches nothing (and is a syntax error in JS)
8877
if (char <= to) {
8978
members += `${escape_member(char)}-${escape_member(to)}`
9079
}
@@ -98,7 +87,6 @@ const parse_bracket = (
9887
return undefined
9988
}
10089

101-
// Translates a glob (no leading slash, no trailing slash) to a regex source.
10290
const glob_to_source = (glob: string): string | undefined => {
10391
let source = ''
10492
let i = 0
@@ -118,11 +106,9 @@ const glob_to_source = (glob: string): string | undefined => {
118106

119107
if (end - i >= 2 && at_segment_start && at_segment_end) {
120108
if (end === glob.length) {
121-
// trailing `/**` matches everything inside, but not the folder itself
122109
source += `${ANY}+`
123110
i = end
124111
} else {
125-
// `**/` matches zero or more directories
126112
source += `(?:${ANY}*/)?`
127113
i = end + 1
128114
}
@@ -154,16 +140,13 @@ const parse_rule = (raw: string, ignore_case: boolean): Rule | undefined => {
154140
const negative = body.startsWith('!')
155141
if (negative) body = body.slice(1)
156142

157-
// `\!foo` and `\#foo` are literal patterns
158143
body = body.replace(/^\\([!#])/, '$1')
159144

160145
const dir_only = body.endsWith('/')
161146
if (dir_only) body = body.slice(0, -1)
162147

163148
if (!body || has_trailing_backslash(body)) return undefined
164149

165-
// A separator at the beginning or middle anchors the pattern to the root,
166-
// otherwise it can match at any depth.
167150
const anchored = body.includes('/')
168151
if (body.startsWith('/')) body = body.slice(1)
169152
if (!body) return undefined
@@ -180,18 +163,12 @@ const parse_rule = (raw: string, ignore_case: boolean): Rule | undefined => {
180163
}
181164
}
182165

183-
/**
184-
* Minimal gitignore matcher.
185-
*
186-
* Paths must be relative to the directory the rules belong to. Pass a trailing
187-
* slash for directories (`dir/`), since a rule like `dir/` only matches those.
188-
*/
189166
export class Ignore {
190167
private _rules: Rule[] = []
191168
private _cache = new Map<string, boolean>()
192169
private _ignore_case: boolean
193170

194-
constructor(options?: Ignore_Options) {
171+
constructor(options?: { ignore_case?: boolean }) {
195172
this._ignore_case = options?.ignore_case ?? true
196173
}
197174

@@ -214,8 +191,6 @@ export class Ignore {
214191
const is_dir = normalized.endsWith('/')
215192
const segments = normalized.split('/').filter(Boolean)
216193

217-
// Walk down from the top: once a parent directory is ignored, everything
218-
// below it is ignored and can't be re-included.
219194
let current = ''
220195
for (let i = 0; i < segments.length; i++) {
221196
current = current ? `${current}/${segments[i]}` : segments[i]
@@ -232,7 +207,6 @@ export class Ignore {
232207
if (cached !== undefined) return cached
233208

234209
let result = false
235-
// The last matching rule wins
236210
for (let i = this._rules.length - 1; i >= 0; i--) {
237211
const rule = this._rules[i]
238212
if (rule.dir_only && !is_dir) continue

‎pnpm-lock.yaml‎

Lines changed: 0 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)