Skip to content

Commit 19dead4

Browse files
doc: add project inspect cli example
fix #658
1 parent 465249c commit 19dead4

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

website/guide/project/project-config.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,32 @@ We can also use directories in `node_modules` to reuse preconfigured rules publi
3939
More broadly speaking, any git hosted projects can be imported as rule sets by using [`git submodule`](https://www.git-scm.com/book/en/v2/Git-Tools-Submodules).
4040
:::
4141
42-
##
42+
## Project Discovery
43+
44+
ast-grep will try to find the `sgconfig.yml` file in the current working directory. If it is not found, it will traverse up the directory tree until it finds one. You can also specify the path to the configuration file using the `--config` option.
45+
46+
```bash
47+
ast-grep scan --config path/to/config.yml
48+
```
49+
50+
:::tip Global Configuration
51+
You can put an `sgconfig.yml` in your home directory to set global configurations for `ast-grep`. XDG configuration directory is **NOT** supported yet.
52+
:::
53+
54+
Project file discovery and `--config` option are also effective in the `ast-grep run` command. So you can use configurations like [custom languages](/reference/sgconfig.html#customlanguages) and [language globs](/reference/sgconfig.html#languageglobs). Note that `run` command does not require a `sgconfig.yml` file and will stil search code without it, but `scan` command will report an error if project config is not found.
55+
56+
## Project Inspection
57+
58+
You can use the [`--inspect summary`](/reference/cli/scan.html#inspect-granularity) flag to see the project directory ast-grep is using.
59+
60+
```bash
61+
ast-grep scan --inspect summary
62+
```
63+
64+
It will print the project directory and the configuration file path.
65+
66+
```bash
67+
sg: summary|project: isProject=true,projectDir=/path/to/project
68+
```
69+
70+
Output format can be found in the [GitHub issue](https://github.com/ast-grep/ast-grep/issues/1574).

0 commit comments

Comments
 (0)