Skip to content

Commit

Permalink
doc: add project inspect cli example
Browse files Browse the repository at this point in the history
fix #658
  • Loading branch information
HerringtonDarkholme committed Jan 28, 2025
1 parent 465249c commit 19dead4
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion website/guide/project/project-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,32 @@ We can also use directories in `node_modules` to reuse preconfigured rules publi
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).
:::
##
## Project Discovery
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.
```bash
ast-grep scan --config path/to/config.yml
```

:::tip Global Configuration
You can put an `sgconfig.yml` in your home directory to set global configurations for `ast-grep`. XDG configuration directory is **NOT** supported yet.
:::

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.

## Project Inspection

You can use the [`--inspect summary`](/reference/cli/scan.html#inspect-granularity) flag to see the project directory ast-grep is using.

```bash
ast-grep scan --inspect summary
```

It will print the project directory and the configuration file path.

```bash
sg: summary|project: isProject=true,projectDir=/path/to/project
```

Output format can be found in the [GitHub issue](https://github.com/ast-grep/ast-grep/issues/1574).

0 comments on commit 19dead4

Please sign in to comment.