@@ -7,7 +7,7 @@ description:
7
7
options.
8
8
---
9
9
10
- ### Path-based instructions[ ] ( https://coderabbit.ai/docs/prompt-customization #path-based-instructions)
10
+ ### Path-based instructions { #path-based-instructions}
11
11
12
12
This section explains how to add custom code review instructions for the entire
13
13
project or specific file paths in your project using glob patterns. Developers
@@ -16,22 +16,22 @@ instructions are needed only if you want the reviewer to follow specific
16
16
instructions besides the standard review.
17
17
18
18
Adding file path prompts allows developers to specify custom instructions for
19
- different parts of the codebase. For example, you may want to enforce style
19
+ different parts of the codebase. For example, you may want to enforce a style
20
20
guide by file types or directories.
21
21
22
- ### Sample Usage[ ] ( https://coderabbit.ai/docs/prompt-customization #sample-usage)
22
+ ### Sample Usage { #sample-usage}
23
23
24
- ** path: ** ` **/*.js `
24
+ - ** ` path ` ** : ` **/*.js `
25
25
26
- ** instructions: ** Review the JavaScript code against the Google JavaScript style
27
- guide and point out any mismatches
26
+ ** ` instructions ` ** : Review the JavaScript code against the Google JavaScript
27
+ style guide and point out any mismatches
28
28
29
- ** path: ** ` tests/**.* `
29
+ - ** ` path ` ** : ` tests/**.* `
30
30
31
- ** instructions: ** Review the following unit test code written using the Mocha
32
- test library. Ensure that: The code adheres to best practices associated with
33
- Mocha. Descriptive test names are used to clearly convey the intent of each
34
- test.
31
+ ** ` instructions ` ** : Review the following unit test code written using the
32
+ Mocha test library. Ensure that: The code adheres to best practices associated
33
+ with Mocha. Descriptive test names are used to clearly convey the intent of
34
+ each test.
35
35
36
36
::: note
37
37
@@ -45,27 +45,33 @@ test.
45
45
46
46
## Abstract Syntax Tree (AST) instructions
47
47
48
- :::note ** Deep dive into AST patterns and ast-grep rules**
48
+ ::: note
49
+
50
+ ** Deep dive into AST patterns and ` ast-grep ` rules**
49
51
50
- - AST patterns [ wikipedia] ( https://en.wikipedia.org/wiki/Abstract_syntax_tree )
51
- - ast-grep
52
+ - Abstract Syntax Tree (AST)
53
+ [ Wikipedia article] ( https://en.wikipedia.org/wiki/Abstract_syntax_tree )
54
+ - ` ast-grep `
52
55
[ official documentation] ( https://ast-grep.github.io/guide/rule-config.html )
53
- for detailed guides. :::
56
+ for detailed guides.
54
57
55
- This section explains how to add custom code review instructions using ast-grep
56
- rules. ast-grep is a tool used for searching code using abstract syntax trees
57
- (AST) patterns.
58
+ :::
58
59
59
- By default, you can add ast-grep rules by following these steps:
60
+ This section explains how to add custom code review instructions using
61
+ ` ast-grep ` rules. ` ast-grep ` is a tool used for searching code using abstract
62
+ syntax trees (AST) patterns.
60
63
61
- 1 . Create a folder that keeps all the ast-grep rules in your project directory.
62
- 2 . Add individual ` .yaml ` files for each ast-grep rule within the newly created
63
- folder.
64
- 3 . Ensure that each ` .yaml ` file contains the necessary ast-grep rule
64
+ By default, you can add ` ast-grep ` rules by following these steps:
65
+
66
+ 1 . Create a directory that keeps all the ` ast-grep ` rules in your project
67
+ directory.
68
+ 2 . Add individual ` .yaml ` files for each ` ast-grep ` rule within the newly
69
+ created directory.
70
+ 3 . Ensure that each ` .yaml ` file contains the necessary ` ast-grep ` rule
65
71
configurations.
66
72
4 . Ensure that all rules contains a ` message ` property, that will be used in the
67
73
review process.
68
- 5 . Add the rules folder to the ` .coderabbit.yml ` file under ` tools.ast-grep `
74
+ 5 . Add the rules' directory to the ` .coderabbit.yml ` file under ` tools.ast-grep `
69
75
configuration.
70
76
71
77
``` yaml
@@ -74,17 +80,17 @@ reviews:
74
80
# ...
75
81
tools :
76
82
ast-grep :
77
- rules_folder : " custom-name"
83
+ rules_directory : " custom-name"
78
84
# ...
79
85
```
80
86
81
87
### The rule object
82
88
83
- Rule object is the core concept of ast-grep's rule system and every other
89
+ Rule object is the core concept of ` ast-grep ` rule system and every other
84
90
feature is built on top of it.
85
91
86
92
Below is the full list of fields in a rule object. Every rule field is optional
87
- and can be omitted but at least one field should be present in a rule. A node
93
+ and can be omitted, but at least one field should be present in a rule. A node
88
94
will match a rule if and only if it satisfies all fields in the rule object.
89
95
90
96
``` yaml
@@ -121,7 +127,7 @@ The rule object is inspired by the CSS selectors but with more composability and
121
127
expressiveness. Thinking about how selectors in CSS works can help you
122
128
understand the rule object!
123
129
124
- > Read ast-grep
130
+ > Read ` ast-grep` >
125
131
> [documentation](https://ast-grep.github.io/guide/rule-config.html) for
126
132
> detailed guides.
127
133
@@ -140,7 +146,7 @@ Relational rule defines the relationship between two syntax nodes. There are
140
146
four kinds of relational rule : ` inside` , `has`, `follows` and `precedes`.
141
147
142
148
All four relational rules accept a sub-rule object as their value. The sub-rule
143
- will match the surrounding node while the relational rule itself will match the
149
+ will match the surrounding node, while the relational rule itself will match the
144
150
target node.
145
151
146
152
> Official documentation guide on
@@ -156,10 +162,10 @@ rule:
156
162
157
163
# ### Composite rule
158
164
159
- Composite rule defines the logical relationship between multiple sub-rules.
165
+ A composite rule defines the logical relationship between multiple sub-rules.
160
166
There are three kinds of composite rule : ` all` , `any` and `not`.
161
167
162
- **all**
168
+ **` all` **
163
169
164
170
The `all` rule matches if all sub-rules match.
165
171
@@ -170,7 +176,7 @@ rule:
170
176
- kind: expression_statement
171
177
` ` `
172
178
173
- **any**
179
+ **` any` **
174
180
175
181
` any` rule matches if any sub-rule matches.
176
182
@@ -182,7 +188,7 @@ rule:
182
188
- pattern: let a = $A
183
189
` ` `
184
190
185
- **not**
191
+ **` not` **
186
192
187
193
` not` applies negation to a sub-rule. It matches if the sub-rule does not match.
188
194
@@ -198,13 +204,13 @@ rule:
198
204
199
205
# ## Reusing rule as utility
200
206
201
- ast-grep chooses to use YAML for rule representation. While this decision makes
202
- writing rules easier, it does impose some limitations on the rule authoring. One
203
- of the limitations is that rule objects cannot be reused.
207
+ ` ast-grep` chooses to use YAML for rule representation. While this decision
208
+ makes writing rules easier, it does impose some limitations on the rule
209
+ authoring. One of the limitations is that rule objects cannot be reused.
204
210
205
211
# ### Local utility rule
206
212
207
- Local utility rules are defined in the utils field of the config file. utils is
213
+ Local utility rules are defined in the utils field of the config file. Utils is
208
214
a string-keyed dictionary.
209
215
210
216
For example, the following config file defines a local utility rule
@@ -226,9 +232,9 @@ rule:
226
232
Global utility rules are defined in a separate file. But they are available
227
233
across all rule configurations in the project.
228
234
229
- To create global utility rules, you need to have the `rules` folder created on
230
- the root of your project and another `utils` directory inside the root of your
231
- project.
235
+ To create global utility rules, you need to have the `rules` directory created
236
+ on the root of your project and another `utils` directory inside the root of
237
+ your project.
232
238
233
239
` ` ` yaml
234
240
my-awesome-project # project root
@@ -238,17 +244,17 @@ my-awesome-project # project root
238
244
| |- is-literal.yml
239
245
` ` `
240
246
241
- > Also, you need to add the `rules` and `utils` folders to the `.coderabbit.yml`
242
- > file under `tools.ast-grep` configuration.
247
+ > Also, you need to add the `rules` and `utils` directories to the
248
+ > `.coderabbit.yml` file under `tools.ast-grep` configuration.
243
249
244
250
` ` ` yaml
245
251
#...
246
252
reviews:
247
253
#...
248
254
tools:
249
255
ast-grep:
250
- rules_folder : "rules"
251
- utils_folder : "utils"
256
+ rules_directory : "rules"
257
+ utils_directory : "utils"
252
258
#...
253
259
` ` `
254
260
@@ -272,7 +278,8 @@ rule:
272
278
273
279
# ## Multiple Languages Support
274
280
275
- CodeRabbit supports multiple programming languages for defining ast-grep rules.
281
+ CodeRabbit supports multiple programming languages for defining `ast-grep`
282
+ rules.
276
283
277
284
- JavaScript
278
285
- Typescript
@@ -284,7 +291,7 @@ CodeRabbit supports multiple programming languages for defining ast-grep rules.
284
291
- Python
285
292
- C
286
293
287
- Below are examples of ast-grep rules in different languages :
294
+ Below are examples of ` ast-grep` rules in different languages :
288
295
289
296
# ### JavaScript
290
297
@@ -309,7 +316,7 @@ rule:
309
316
regex: "^import$"
310
317
` ` `
311
318
312
- **No console.log allowed except console.error on the catch block**
319
+ **No console.log allowed except ` console.error` on the catch block**
313
320
314
321
` ` ` yaml
315
322
id: no-console-except-error
@@ -335,9 +342,9 @@ programmers use structs and function pointers to simulate classes and methods.
335
342
336
343
However, this style can have some drawbacks, such as :
337
344
338
- - extra memory allocation and reallocation for the struct and the function
345
+ - Extra memory allocation and reallocation for the struct and the function
339
346
pointer.
340
- - indirection overhead when calling the function pointer.
347
+ - Indirection overhead when calling the function pointer.
341
348
342
349
A possible alternative is to use a plain function call with the struct pointer
343
350
as the first argument.
0 commit comments