Skip to content

[bug] support case insensitive option in files/ignores #2432

@olson-dan

Description

@olson-dan

Please read the FAQ for the bug you encountered.

  • I have read the existing FAQ

⏯ Playground Link

https://ast-grep.github.io/playground.html#eyJtb2RlIjoiQ29uZmlnIiwibGFuZyI6ImNwcCIsInF1ZXJ5IjoiJEZJRUxEID0gJElOSVQiLCJyZXdyaXRlIjoiRGVidWcuYXNzZXJ0Iiwic3RyaWN0bmVzcyI6InNtYXJ0Iiwic2VsZWN0b3IiOiIiLCJjb25maWciOiJpZDogbm9faGVsbG9fd29ybGRcbmxhbmd1YWdlOiBjXG5tZXNzYWdlOiBcIk5vIGhlbGxvIHdvcmxkcyBhbGxvd2VkIVwiXG5zZXZlcml0eTogZXJyb3JcbnJ1bGU6XG4gIGtpbmQ6IHN0cmluZ19saXRlcmFsXG4gIHJlZ2V4OiBcIkhlbGxvIFdvcmxkXCJcbmlnbm9yZXM6XG4gIC0gXCIqKi9mb29iYXIvKi5jXCIiLCJzb3VyY2UiOiJpbnQgbWFpbigpIHsgcHJpbnRmKFwiSGVsbG8gV29ybGRcXG5cIik7IHJldHVybiAwOyB9In0=

💻 Code

int main() { printf("Hello World\n"); return 0; }

🙁 Actual behavior

Windows is a case-insensitive filesystem but still assigns casing to folders. Paths on Windows are often treated case-insensitively by software as a result, but ast-grep treats the case-sensitively. This is causing problems for my usage, because I cannot effectively use ignores... inconsistent casing on CI/CD machines and other issues mostly beyond my control prevent me from having deterministic behavior of the rules.

I put together a repro, and the above playground link probably doesn't make sense without it.

Using this folder structure:

> coreutils du .
0       .\x\FooBar
0       .\x
0       .\y\foobar
0       .\y
0       .

I placed the same C file into each subfolder.

> echo 'int main() { printf("Hello World\n"); return 0; }' > .\y\foobar\main.c
> echo 'int main() { printf("Hello World\n"); return 0; }' > .\x\FooBar\main.c

Then, I scan with a rule that I expect to ignore both .c files:

> bat .\no_hello_world.yaml
───────┬──────────────────────────────────────────
       │ File: .\no_hello_world.yaml
───────┼──────────────────────────────────────────
   1   │ id: no_hello_world
   2   │ language: c
   3   │ message: "No hello worlds allowed!"
   4   │ severity: error
   5   │ rule:
   6   │   kind: string_literal
   7   │   regex: "Hello World"
   8   │ ignores:
   9   │   - "**/foobar/*.c"
───────┴──────────────────────────────────────────
> ast-grep scan --rule .\no_hello_world.yaml .
error[no_hello_world]: No hello worlds allowed!
  ┌─ x\FooBar\main.c:1:21
  │
1 │ int main() { printf("Hello World\n"); return 0; }
  │                     ^^^^^^^^^^^^^^^

Error: 1 error(s) found in code.
Help: Scan succeeded and found error level diagnostics in the codebase.

🙂 Expected behavior

Expected behavior for most software on windows would be for the ignores rule to be applied case-insensitively. Would be great if this could be changed, and thanks for making ast-grep... we love this tool!

Additional information about the issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions