Authoring Custom Patterns
We recommend authoring Grit patterns in
.md files, as this format allows you to combine documentation, GritQL, and source code examples in a single file.
We recommend installing the Grit extension to get syntax highlighting and authoring assistance for Grit patterns.
You can watch this video to see the extension in action.
Patterns can be stored in
*.md files within a
.grit/patterns folder at the root of your repo.
- The name of the file is used as the name of the pattern.
- The first fenced code block in the file is used as the GritQL pattern body.
- Subheadings are used for test cases, where each test case should have a before and after code block.
- Cases which shouldn't be transformed should only have a single code block.
You can find many examples in the Grit standard library.
Here is an example of a markdown pattern file:
# Remove console.log Remove console.log in production code. ```grit `console.log($_)` => . ``` ## Test case one ```typescript console.error("keep this"); console.log('remove this!'); ``` ```typescript console.error("keep this"); ```