The guide explains how to add custom review instructions for the entire project.
For example, you may want to enforce a style guide by file types or directories.
View complete list of default blocked paths
Path Pattern | Description |
---|---|
!**/dist/** | Build output directory |
!**/node_modules/** | Node.js dependencies |
!**/.svelte-kit/** | SvelteKit build directory |
!**/.webpack/** | Webpack build directory |
!**/.yarn/** | Yarn cache directory |
!**/.docusaurus/** | Docusaurus build directory |
!**/.temp/** | Temporary files directory |
!**/.cache/** | Cache directory |
!**/.next/** | Next.js build directory |
!**/.nuxt/** | Nuxt.js build directory |
Path Pattern | Description |
---|---|
!**/package-lock.json | npm lock file |
!**/yarn.lock | Yarn lock file |
!**/pnpm-lock.yaml | pnpm lock file |
!**/bun.lockb | Bun lock file |
!**/*.lock | Generic lock files |
Path Pattern | Description |
---|---|
!**/generated/** | Generated code directory |
!**/@generated/** | Generated code directory (alternative) |
!**/__generated__/** | Generated code directory (alternative) |
!**/__generated/** | Generated code directory (alternative) |
!**/_generated/** | Generated code directory (alternative) |
!**/gen/** | Generated code directory (alternative) |
!**/@gen/** | Generated code directory (alternative) |
!**/__gen__/** | Generated code directory (alternative) |
!**/__gen/** | Generated code directory (alternative) |
!**/_gen/** | Generated code directory (alternative) |
Path Pattern | Description |
---|---|
!**/*.app | Application bundle |
!**/*.bin | Binary file |
!**/*.class | Java compiled class |
!**/*.dll | Windows dynamic library |
!**/*.dylib | macOS dynamic library |
!**/*.exe | Windows executable |
!**/*.o | Object file |
!**/*.so | Shared object file |
!**/*.wasm | WebAssembly file |
Path Pattern | Description |
---|---|
!**/*.bz2 | Bzip2 archive |
!**/*.gz | Gzip archive |
!**/*.xz | XZ archive |
!**/*.zip | ZIP archive |
!**/*.7z | 7-Zip archive |
!**/*.rar | RAR archive |
!**/*.zst | Zstandard archive |
!**/*.tar | TAR archive |
!**/*.jar | Java archive |
!**/*.war | Web application archive |
!**/*.nar | NAR archive |
Path Pattern | Description |
---|---|
!**/*.mp3 | MP3 audio |
!**/*.wav | WAV audio |
!**/*.wma | WMA audio |
!**/*.mp4 | MP4 video |
!**/*.avi | AVI video |
!**/*.mkv | MKV video |
!**/*.wmv | WMV video |
!**/*.m4a | M4A audio |
!**/*.m4v | M4V video |
!**/*.3gp | 3GP video |
!**/*.3g2 | 3G2 video |
!**/*.rm | RealMedia video |
!**/*.mov | QuickTime video |
!**/*.flv | Flash video |
!**/*.swf | Flash animation |
!**/*.flac | FLAC audio |
!**/*.ogg | OGG audio |
Path Pattern | Description |
---|---|
!**/*.ico | Icon file |
!**/*.svg | SVG image |
!**/*.jpeg | JPEG image |
!**/*.jpg | JPEG image |
!**/*.png | PNG image |
!**/*.gif | GIF image |
!**/*.bmp | BMP image |
!**/*.tiff | TIFF image |
!**/*.webm | WebM image |
!**/*.ttf | TrueType font |
!**/*.otf | OpenType font |
!**/*.woff | Web Open Font Format |
!**/*.woff2 | Web Open Font Format 2 |
!**/*.eot | Embedded OpenType font |
Path Pattern | Description |
---|---|
!**/*.pdf | PDF document |
!**/*.doc | Word document |
!**/*.docx | Word document |
!**/*.xls | Excel spreadsheet |
!**/*.xlsx | Excel spreadsheet |
!**/*.ppt | PowerPoint presentation |
!**/*.pptx | PowerPoint presentation |
!**/*.csv | CSV data file |
!**/*.tsv | TSV data file |
!**/*.dat | Data file |
!**/*.db | Database file |
!**/*.parquet | Parquet data file |
Path Pattern | Description |
---|---|
!**/tags | Tags file |
!**/.tags | Tags file |
!**/TAGS | Tags file |
!**/.TAGS | Tags file |
!**/.DS_Store | macOS system file |
!**/.cscope.files | Cscope files |
!**/.cscope.out | Cscope output |
!**/.cscope.in.out | Cscope input/output |
!**/.cscope.po.out | Cscope output |
!**/*.log | Log file |
!**/*.map | Source map |
!**/*.out | Output file |
!**/*.sum | Checksum file |
!**/*.work | Work file |
!**/*.md5sum | MD5 checksum file |
Path Pattern | Description |
---|---|
!**/*.tga | Targa image |
!**/*.dds | DirectDraw surface |
!**/*.psd | Photoshop document |
!**/*.fbx | FBX 3D model |
!**/*.obj | OBJ 3D model |
!**/*.blend | Blender file |
!**/*.dae | COLLADA 3D model |
!**/*.gltf | GL Transmission Format |
!**/*.hlsl | HLSL shader |
!**/*.glsl | GLSL shader |
!**/*.unity | Unity scene |
!**/*.umap | Unreal map |
!**/*.prefab | Unity prefab |
!**/*.mat | Material file |
!**/*.shader | Shader file |
!**/*.shadergraph | Shader graph |
!**/*.sav | Save file |
!**/*.scene | Scene file |
!**/*.asset | Asset file |
Path Pattern | Description |
---|---|
!**/*.pyc | Python compiled file |
!**/*.pyd | Python dynamic module |
!**/*.pyo | Python optimized file |
!**/*.pkl | Python pickle file |
!**/*.pickle | Python pickle file |
Path Pattern | Description |
---|---|
!**/*.pb.go | Protocol buffer Go file |
!**/*.pb.gw.go | Protocol buffer gateway Go file |
Path Pattern | Description |
---|---|
!**/*.tfstate | Terraform state file |
!**/*.tfstate.backup | Terraform state backup |
Path Pattern | Description |
---|---|
!**/*.min.js | Minified JavaScript |
!**/*.min.js.map | Minified JavaScript source map |
!**/*.min.js.css | Minified CSS |
ast-grep
to power this feature. ast-grep
is written in Rust and uses the tree-sitter parser to generate the AST for popular languages. ast-grep
is written and maintained by Herrington Darkholme.
ast-grep
Playground is quite effective in designing and testing AST rules on source code snippets. You can access the playground here.ast-grep
rulesast-grep
official documentation for detailed guides.ast-grep
rules. ast-grep
is a tool used for searching code using abstract syntax trees (AST) patterns.
By default, you can add ast-grep
rules by following these steps:
ast-grep
rules in your project directory..yaml
files for each ast-grep
rule within the newly created directory..yaml
file contains the necessary ast-grep
rule configurations.message
property that will be used during the review process..coderabbit.yml
file under tools.ast-grep
configuration.packages
property to the configuration to specify the packages that should be installed before running the ast-grep
tool. Please read the packages
section for detailed information.ast-grep
rule system and every other feature is built on top of it.
Below is the full list of fields in a rule object. Every rule field is optional and can be omitted, but at least one field should be present in a rule. A node will match a rule if and only if it satisfies all fields in the rule object.
Read ast-grep
> documentation for detailed guides.
pattern
, kind
and regex
.
Official documentation guide on Atomic Rule
inside
, has
, follows
and precedes
.
All four relational rules accept a sub-rule object as their value. The sub-rule will match the surrounding node, while the relational rule itself will match the target node.
Official documentation guide on Relational Rule
all
, any
and not
.
all
The all
rule matches if all sub-rules match.
any
any
rule matches if any sub-rule matches.
not
not
applies negation to a sub-rule. It matches if the sub-rule does not match.
Official documentation guide on Composite Rule
ast-grep
chooses to use YAML for rule representation. While this decision makes writing rules easier, it does impose some limitations on the rule authoring. One of the limitations is that rule objects cannot be reused.
is-literal
:
rules
directory created on the root of your project and another utils
directory inside the root of your project.
Also, you need to add therules
andutils
directories to the.coderabbit.yml
file undertools.ast-grep
configuration. The rules can also be inside a package. If you have a package that contains rules, you can add the package name to thepackages
field in the.coderabbit.yml
file.
Official documentation guide on Utility Rule
ast-grep
rules.
CodeRabbit provides a set of packages that you can use out of the box. You can also create your own packages and share them with the community or just use them within your organization.
Packages provided by CodeRabbit are:
ast-grep-essentials
: A set of essential security rules. Because we value security, this package gets its own property in the .coderabbit.yml
file, to make it easier to install and not overwrite. Check the package repository for more information.packages
field in the .coderabbit.yml
file.
ast-grep
rules. You can add the package name to the packages
field in the .coderabbit.yml
file.
Requirements for a package:
ast-grep
rule format
rules
and utils
directories are keywords, and it should be the same. Inside each directory, the structure is up to you. You can also have any other root directories or files beside the two shown above.
organization/repository
ast-grep
rules.
ast-grep
rules in different languages:
console.error
on the catch block