Project Configuration
Root Configuration File
ast-grep supports using YAML to configure its linting rules to scan your code repository. We need a root configuration file sgconfig.yml
to specify directories where sg
can find all rules.
In your project root, add sgconfig.yml
with content as below.
ruleDirs:
- rules
This instructs ast-grep to use all files recursively inside the rules
folder as rule files.
For example, suppose we have the following file structures.
my-awesome-project
|- rules
| |- no-var.yml
| |- no-bit-operation.yml
| |- my_custom_rules
| |- custom-rule.yml
| |- fancy-rule.yml
|- sgconfig.yml
|- not-a-rule.yml
All the YAML files under rules
folder will be treated as rule files by sg
, whilenot-a-rule.yml
is ignored by ast-grep.
Note, the sg scan
command requires you have an sgconfig.yml
in your project root.
Pro tip
We can also use directories in node_modules
to reuse preconfigured rules published on npm!
More broadly speaking, any git hosted projects can be imported as rule sets by using git submodule
.