Skip to content

Commit 27fba38

Browse files
feat: add languageGlobs tips for rule reuse
1 parent ae0725b commit 27fba38

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

website/reference/sgconfig.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,25 @@ ast-grep uses file extensions to discover and parse files in certain languages.
7979

8080
The key of this option is the language name. The values are a list of [glob patterns](https://www.wikiwand.com/en/Glob_(programming)) that match the files you want to process.
8181

82-
**Example:**
82+
Note, `languageGlobs` takes precedence over the default language parser so you can reassign the parser for a specific file extension.
8383

84-
The following configuration tells ast-grep to treat the files with `.vue`, `.svelte`, and `.astro` extensions as HTML files, and the extension-less file `.eslintrc` as JSON files.
84+
**Example:**
8585

8686
```yml
8787
languageGlobs:
8888
html: ['*.vue', '*.svelte', '*.astro']
8989
json: ['.eslintrc']
90+
cpp: ['*.c'] # override the default parsers
91+
tsx: ['*.ts'] # useful for rule reuse
9092
```
9193

94+
The above configuration tells ast-grep to treat the files with `.vue`, `.svelte`, and `.astro` extensions as HTML files, and the extension-less file `.eslintrc` as JSON files. It also overrides the default parser for C files and TS files.
95+
96+
97+
:::tip Simliar languages
98+
This option can override the default language parser for a specific file extension, which is useful for rule reuse between similar languages like C/Cpp, or TS/TSX.
99+
:::
100+
92101
## `customLanguages` <Badge type="warning" text="Experimental" />
93102

94103
* type: `HashMap<String, CustomLang>`

0 commit comments

Comments
 (0)