Skip to content

Commit

Permalink
feat: add languageGlobs tips for rule reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
HerringtonDarkholme committed Jan 19, 2025
1 parent ae0725b commit 27fba38
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions website/reference/sgconfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,25 @@ ast-grep uses file extensions to discover and parse files in certain languages.

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.

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

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.
**Example:**

```yml
languageGlobs:
html: ['*.vue', '*.svelte', '*.astro']
json: ['.eslintrc']
cpp: ['*.c'] # override the default parsers
tsx: ['*.ts'] # useful for rule reuse
```

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.


:::tip Simliar languages
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.
:::

## `customLanguages` <Badge type="warning" text="Experimental" />

* type: `HashMap<String, CustomLang>`
Expand Down

0 comments on commit 27fba38

Please sign in to comment.