I'm using ast-grep to detect patterns in Java files, but the files and ignores filter configuration isn't working as expected.
According to the documentation, we can apply pattern matching to specific files or ignore certain files using:
files:
- src/**/*.js
- src/**/*.ts
ignores:
- test/**/*.js
- test/**/*.ts
I have a project structure with both src and tst directories, and I'm trying to match patterns ONLY in the source files, but not in test files.
Here's my pattern detector configuration:
id: detect_initialise
language: java
rule:
kind: expression_statement
regex: Service.initialize
files:
- "**/src/**/*.java"
ignores:
- "**/tst/**/*.java"
I'm executing the ast-grep command on the project workspace using this Python code:
command = [
f"{AST_GREP_CMD}",
"scan",
"-r",
f"{str(path_to_ast-grep_recipe)}",
f"{project_repo_path}",
]
ast_grep_dryrun_result = self.executor.run(command)
Issue
The pattern is being matched in Java classes from BOTH src and tst directories, even though I've set the files filter to only include src directories and explicitly added an ignore rule for tst directories.
I expected the results to only include matches from files in the src directory, but the output contains matches from both src and tst directories.
- Is my syntax for the
filesandignorefields correct? - Are there any known issues or limitations with the file filtering in ast-grep?
- Is there something I'm missing in how ast-grep processes these files/ignores configurations?