-
Notifications
You must be signed in to change notification settings - Fork 0
fix(core): use ripgrep search backend when a .boltignore governs the repo #107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,26 +29,34 @@ const MAX_SUBMATCHES = 100 | |
| // directory) to keep root-anchored rules like `/src/generated/` correctly | ||
| // scoped. User globs and output paths are translated between the two bases. | ||
| function boltignore(cwd: string) { | ||
| const root = (() => { | ||
| let dir = cwd | ||
| while (true) { | ||
| if (fs.existsSync(path.join(dir, ".git"))) return dir | ||
| const parent = path.dirname(dir) | ||
| if (parent === dir) return cwd | ||
| dir = parent | ||
| } | ||
| })() | ||
| const file = path.join(root, ".boltignore") | ||
| if (!fs.existsSync(file)) return { cwd, args: [], search: ".", prefix: "" } | ||
| const search = path.relative(root, cwd) | ||
| const base = root(cwd) | ||
| const file = path.join(base, ".boltignore") | ||
| if (!fs.statSync(file, { throwIfNoEntry: false })?.isFile()) return { cwd, args: [], search: ".", prefix: "" } | ||
| const search = path.relative(base, cwd) | ||
| return { | ||
| cwd: root, | ||
| cwd: base, | ||
| args: [`--ignore-file=${file}`], | ||
| search: search || ".", | ||
| prefix: search ? `${search.replaceAll("\\", "/")}/` : "", | ||
| } | ||
| } | ||
|
|
||
| function root(cwd: string) { | ||
| let dir = cwd | ||
| while (true) { | ||
| if (fs.existsSync(path.join(dir, ".git"))) return dir | ||
| const parent = path.dirname(dir) | ||
| if (parent === dir) return cwd | ||
| dir = parent | ||
| } | ||
| } | ||
|
Comment on lines
+44
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| // Whether a .boltignore governs this directory. Search backends without | ||
| // ignore-file support (fff) must fall back to ripgrep when this is true. | ||
| export function ignored(cwd: string) { | ||
| return fs.statSync(path.join(root(cwd), ".boltignore"), { throwIfNoEntry: false })?.isFile() === true | ||
| } | ||
|
Comment on lines
+56
to
+58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| // -g globs follow .gitignore rules relative to the ripgrep working directory: | ||
| // slash-less globs match basenames at any depth and survive re-basing, while | ||
| // globs with a non-trailing slash are anchored and must be re-anchored onto | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is considered a best practice to avoid 'polluting' the global scope with variables that are intended to be local to the script. Global variables created from a script can produce name collisions with global variables created from another script, which will usually lead to runtime errors or unexpected behavior. It is mostly useful for browser scripts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
False positive: the file is an ES module, so this function declaration is module-scoped, not global. The rule targets browser scripts where top-level declarations pollute the global object.