-
Notifications
You must be signed in to change notification settings - Fork 0
fix(cli): let ast-grep rules see inside hidden directories #153
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
Open
thecodedrift
wants to merge
2
commits into
main
Choose a base branch
from
fix/hidden-scan
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+402
−2
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| --- | ||
| "@taskless/cli": patch | ||
| --- | ||
|
|
||
| Let ast-grep rules see inside hidden directories such as `.github/`. | ||
|
|
||
| ast-grep's file walker skips dot-directories unless told otherwise, and | ||
| `runAstGrepScan` never told it otherwise. No `sg` rule could match anything | ||
| under `.github/`, `.circleci/`, `.vscode/` or `.husky/`, so `check` reported | ||
| nothing and exited 0 on a workflow file it flags correctly the moment the same | ||
| bytes live in a non-hidden directory. Vale has no such blind spot, which left | ||
| the two static engines disagreeing about whether `.github/` existed at all. | ||
| Both `check` and the runtime engine's ast-grep narrow now pass | ||
| `--no-ignore hidden`. | ||
|
|
||
| Only `hidden` is passed, and deliberately not `vcs`: `.gitignore` is still | ||
| respected, so the wider walk does not start reporting findings in `dist/` or | ||
| anywhere else a project has already said it does not want scanned. Rule | ||
| discovery is untouched — `ruleDirs` walks by its own rules, so a rule's | ||
| `.tests/` directory is still skipped rather than parsed as a rule. | ||
|
|
||
| `.taskless/` is excluded from the wider walk, because it is hidden too and | ||
| reaching it is not a fix. A rule definition is structured YAML full of `id:`, | ||
| `language:`, `severity:` and `rule:` keys, so an ordinary user-written Yaml rule | ||
| fires on the CLI's own rule files — a finding in a directory the user did not | ||
| author and cannot edit without disabling their rule. The exclusion applies only | ||
| when `check` walks the whole project on its own; an explicit path stays a | ||
| request, which is the rule the Vale runner already follows. | ||
|
|
||
| `.git/` is excluded on the same terms. ast-grep has no exclusion of its own for | ||
| it and `.gitignore` does not list it, so the default hidden-directory skip was | ||
| the only thing holding it back: without this, a whole-project `check` descended | ||
| into `.git/objects` and `.git/logs` on every run, and `.git/hooks/*` scripts | ||
| matched language rules never meant to lint VCS internals. | ||
|
|
||
| Both engines now decide "whole project" the same way, and it is no longer | ||
| `paths.length === 0`. An explicit `.` is normalized to the literal path `"."` | ||
| before it reaches either runner, so a length test read the most ordinary way of | ||
| asking for a whole-project check as a user-named path and skipped the exclusions | ||
| — `check` was clean while `check .` reported findings inside `.taskless/`. Vale | ||
| was already wrong in the same way and for the same reason, independently of the | ||
| hidden-directory change, so the predicate is now shared rather than written | ||
| twice. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /** | ||
| * Whether a set of positional paths means "walk the whole project". | ||
| * | ||
| * Both static engines apply their CLI-managed-directory exclusions only on a | ||
| * whole-project walk, because an explicit path is a request: silently declining | ||
| * to check a file someone named would be worse than checking one they did not. | ||
| * That rule needs a correct answer to "did we choose this, or did the user?", | ||
| * and both engines were getting it from `paths.length === 0`. | ||
| * | ||
| * **That test is wrong for `.`, and the mistake is silent.** `filterExistingPaths` | ||
| * (`commands/check.ts`) normalizes a positional path resolving to cwd into the | ||
| * literal string `"."` rather than dropping back to an empty array, so | ||
| * `taskless check .` — a near-default invocation — arrives with `paths = ["."]`. | ||
| * Under a length test that reads as a user request and skips the exclusions, | ||
| * which is how `check .` came to report findings inside `.taskless/` while a | ||
| * bare `check` did not. | ||
| * | ||
| * A single explicit `.` is a request for the project, not for the CLI's own | ||
| * config inside it, so it is a whole-project walk. A path *under* `.taskless/` | ||
| * is still honored: that names the config directly. | ||
| * | ||
| * Shared rather than duplicated because the two engines diverging here is | ||
| * exactly the class of bug this fixes — one of them was already wrong in the | ||
| * same way. | ||
| */ | ||
| export function isWholeProjectWalk(paths: string[]): boolean { | ||
| if (paths.length === 0) return true; | ||
| return paths.length === 1 && CWD_ALIASES.has(paths[0] ?? ""); | ||
| } | ||
|
|
||
| /** | ||
| * Spellings of "here" that `filterExistingPaths` can emit or a shell can pass. | ||
| * `"."` is what the normalizer produces; the others reach us straight from argv. | ||
| */ | ||
| const CWD_ALIASES = new Set([".", "./", ".\\"]); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.