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.

VS Code

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.

Authoring Walkthrough

Markdown Format

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.
  • Within the sample patterns, you can use // @filename: example.js to represent multiple input/output files that should be tested as a group - like this example.


You can find many examples in the Grit standard library.

Here is an example of a markdown pattern file:

YAML .grit/patterns/
# Remove console.log

Remove console.log in production code.

`console.log($_)` => .

## Test case one

console.error("keep this");
console.log('remove this!');

console.error("keep this");