Skip to content

Commit 0f28919

Browse files
Revert "chore: format markdown"
This reverts commit edb690c.
1 parent a1b3377 commit 0f28919

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+381
-396
lines changed

website/advanced/custom-language.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ You need to add a new entry under the `customLanguages` key with the name of you
100100
ruleDirs: ["./rules"]
101101
customLanguages:
102102
mojo:
103-
libraryPath: mojo.so # path to dynamic library
104-
extensions: [mojo, 🔥] # file extensions for this language
105-
expandoChar: _ # optional char to replace $ in your pattern
103+
libraryPath: mojo.so # path to dynamic library
104+
extensions: [mojo, 🔥] # file extensions for this language
105+
expandoChar: _ # optional char to replace $ in your pattern
106106
```
107107
108108
The `libraryPath` property specifies the path to the dynamic library relative to the `sgconfig.yml` file or an absolute path. The `extensions` property specifies a list of file extensions for this language.
@@ -130,7 +130,7 @@ Or you can write a rule in yaml like this:
130130

131131
```yaml
132132
id: my-first-mojo-rule
133-
language: mojo # the name we register before!
133+
language: mojo # the name we register before!
134134
severity: hint
135135
rule:
136136
pattern: print

website/advanced/faq.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Different results are usually caused by incomplete or wrong code snippet in the
5757
```yaml
5858
rule:
5959
pattern:
60-
context: "int main() { return 0; }"
60+
context: 'int main() { return 0; }'
6161
selector: function
6262
```
6363

@@ -113,7 +113,7 @@ The workaround is using [`constraints`](https://ast-grep.github.io/guide/project
113113
rule:
114114
pattern: $HOOK($$$ARGS)
115115
constraints:
116-
HOOK: { regex: "^use" }
116+
HOOK: { regex: '^use' }
117117
```
118118

119119
[Example usage](/playground.html#eyJtb2RlIjoiQ29uZmlnIiwibGFuZyI6ImphdmFzY3JpcHQiLCJxdWVyeSI6ImZvbygkJCRBLCBiLCAkJCRDKSIsInJld3JpdGUiOiIiLCJjb25maWciOiJydWxlOlxuICBwYXR0ZXJuOiAkSE9PSygkJCRBUkdTKVxuY29uc3RyYWludHM6XG4gIEhPT0s6IHsgcmVnZXg6IF51c2UgfSIsInNvdXJjZSI6ImZ1bmN0aW9uIFJlYWN0Q29tcG9uZW50KCkge1xuICAgIGNvbnN0IGRhdGEgPSBub3RIb28oKVxuICAgIGNvbnN0IFtmb28sIHNldEZvb10gPSB1c2VTdGF0ZSgnJylcbn0ifQ==).
@@ -153,10 +153,10 @@ id: recursive-call
153153
language: JavaScript
154154
rule:
155155
all:
156-
- pattern: function $F() { $$$ }
157-
- has:
158-
pattern: $F()
159-
stopBy: end
156+
- pattern: function $F() { $$$ }
157+
- has:
158+
pattern: $F()
159+
stopBy: end
160160
```
161161

162162
```js [match.js]
@@ -177,10 +177,10 @@ id: recursive-call
177177
language: JavaScript
178178
rule:
179179
all:
180-
- has: # N.B. has is the first rule
181-
pattern: $F()
182-
stopBy: end
183-
- pattern: function $F() { $$$ }
180+
- has: # N.B. has is the first rule
181+
pattern: $F()
182+
stopBy: end
183+
- pattern: function $F() { $$$ }
184184
```
185185

186186
In this case, the `has` rule matches first and captures `$F` as `foo` since `foo()` is the first function call matching the pattern `$F()`. The later rule `function $F() { $$$ }` will only find the `foo` declaration instead of `recurse`.
@@ -208,8 +208,8 @@ For example, to match class field in JavaScript, a kind + pattern rule [will not
208208

209209
```yaml
210210
# these are two separate rules
211-
pattern: a = 123 # rule 1
212-
kind: field_definition # rule 2
211+
pattern: a = 123 # rule 1
212+
kind: field_definition # rule 2
213213
```
214214

215215
This is because pattern `a = 123` is parsed as [`assignment_expression`](/playground.html#eyJtb2RlIjoiUGF0Y2giLCJsYW5nIjoiamF2YXNjcmlwdCIsInF1ZXJ5IjoiYSA9IDEyMyIsInJld3JpdGUiOiIiLCJzdHJpY3RuZXNzIjoic21hcnQiLCJzZWxlY3RvciI6IiIsImNvbmZpZyI6IiIsInNvdXJjZSI6IiJ9). Pattern and kind are two separate rules. And using them together will match nothing because no AST will have both `assignment_expression` and `field_definition` kind at once.
@@ -219,8 +219,8 @@ Instead, you need to use pattern object to provide enough context code for the p
219219
```yaml
220220
# this is one single pattern rule!
221221
pattern:
222-
context: "class A { a = 123 }" # provide full context code
223-
selector: field_definition # select the effective pattern
222+
context: 'class A { a = 123 }' # provide full context code
223+
selector: field_definition # select the effective pattern
224224
```
225225

226226
Note the rule above is one single pattern rule, instead of two. The `context` field provides the full unambiguous code snippet of `class`. So the `a = 123` will be parsed as `field_definition`. The `selector` field then selects the `field_definition` node as the [effective pattern](/advanced/pattern-parse.html#steps-to-create-a-pattern) matcher.

website/advanced/find-n-patch.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,11 @@ To do this, we register a rewriter that acts as a separate rewriter rule for eac
128128

129129
```yaml
130130
rewriters:
131-
- id: rewrite-identifer
132-
rule:
133-
pattern: $IDENT
134-
kind: identifier
135-
fix: import $IDENT from './barrel/$IDENT'
131+
- id: rewrite-identifer
132+
rule:
133+
pattern: $IDENT
134+
kind: identifier
135+
fix: import $IDENT from './barrel/$IDENT'
136136
```
137137

138138
The `rewrite-identifier` above will:
@@ -168,11 +168,11 @@ The final rule will be like this. See the [online playground](https://ast-grep.g
168168
rule:
169169
pattern: import {$$$IDENTS} from './barrel'
170170
rewriters:
171-
- id: rewrite-identifer
172-
rule:
173-
pattern: $IDENT
174-
kind: identifier
175-
fix: import $IDENT from './barrel/$IDENT'
171+
- id: rewrite-identifer
172+
rule:
173+
pattern: $IDENT
174+
kind: identifier
175+
fix: import $IDENT from './barrel/$IDENT'
176176
transform:
177177
IMPORTS:
178178
rewrite:

website/advanced/language-injection.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,10 @@ You can add the `languageInjections` section in the project configuration file `
111111

112112
```yaml
113113
languageInjections:
114-
- hostLanguage: js
115-
rule:
116-
pattern: styled.$TAG`$CONTENT`
117-
injected: css
114+
- hostLanguage: js
115+
rule:
116+
pattern: styled.$TAG`$CONTENT`
117+
injected: css
118118
```
119119
120120
Let's break the configuration down.
@@ -183,8 +183,8 @@ First, we need to register graphql as a custom language in ast-grep. See [custom
183183
customLanguages:
184184
graphql:
185185
libraryPath: graphql.so # the graphql tree-sitter parser dynamic library
186-
extensions: [graphql] # graphql file extension
187-
expandoChar: $ # see reference above for explanation
186+
extensions: [graphql] # graphql file extension
187+
expandoChar: $ # see reference above for explanation
188188
```
189189

190190
### Define graphql injection in `sgconfig.yml`.
@@ -193,10 +193,10 @@ Next, we need to customize what region should be parsed as graphql string in Jav
193193

194194
```yaml
195195
languageInjections:
196-
- hostLanguage: js
197-
rule:
198-
pattern: graphql`$CONTENT`
199-
injected: graphql
196+
- hostLanguage: js
197+
rule:
198+
pattern: graphql`$CONTENT`
199+
injected: graphql
200200
```
201201
202202
### Search GraphQL in JavaScript

website/advanced/pattern-parse.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ Without other hints, ast-grep will parse it as labeled statement by default. To
103103

104104
```yaml
105105
pattern:
106-
context: "{ a: 123 }"
106+
context: '{ a: 123 }'
107107
selector: pair
108108
```
109109

@@ -155,8 +155,8 @@ Examples:
155155

156156
```yaml
157157
program
158-
expression_statement
159-
number <--- effective node
158+
expression_statement
159+
number <--- effective node
160160
```
161161

162162
See [Playground](/playground.html#eyJtb2RlIjoiUGF0Y2giLCJsYW5nIjoiamF2YXNjcmlwdCIsInF1ZXJ5IjoiMTIzIiwicmV3cml0ZSI6IiIsInN0cmljdG5lc3MiOiJzbWFydCIsInNlbGVjdG9yIjoiIiwiY29uZmlnIjoiIiwic291cmNlIjoiIn0=).
@@ -165,11 +165,11 @@ See [Playground](/playground.html#eyJtb2RlIjoiUGF0Y2giLCJsYW5nIjoiamF2YXNjcmlwdC
165165

166166
```yaml
167167
program
168-
expression_statement
169-
call_expression <--- effective node
170-
identifier
171-
arguments
172-
identifier
168+
expression_statement
169+
call_expression <--- effective node
170+
identifier
171+
arguments
172+
identifier
173173
```
174174

175175
See [Playground](/playground.html#eyJtb2RlIjoiUGF0Y2giLCJsYW5nIjoiamF2YXNjcmlwdCIsInF1ZXJ5IjoiZm9vKGJhcikiLCJyZXdyaXRlIjoiIiwic3RyaWN0bmVzcyI6InNtYXJ0Iiwic2VsZWN0b3IiOiJjYWxsX2V4cHJlc3Npb24iLCJjb25maWciOiIiLCJzb3VyY2UiOiIifQ==).

website/blog/yaml-vs-dsl.md

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ head:
1616
- - meta
1717
- property: og:description
1818
content: YAML and DSL are two different approaches to configure rule in structural search. The question "which is better" is largely subjective.
19+
1920
---
2021

2122
# YAML vs DSL: comparison is subjective
2223

2324
As stated in the [tool comparison](/advanced/tool-comparison.html#gritql), YAML configuration and DSL (Domain Specific Language) are two different approaches to configure rules in structural search. The question "which is better" is largely subjective.
2425

25-
However, recently I have received some feedback that YAML is **objectively** not as good as DSL, and I would like to clarify some points.
26+
However, recently I have received some feedback that YAML is __objectively__ not as good as DSL, and I would like to clarify some points.
27+
2628

2729
The original argument is quoted as follows:
2830

@@ -54,6 +56,7 @@ This argument is a [slippery slope fallacy](https://en.wikipedia.org/wiki/Slippe
5456

5557
Using one concept in your library, framework or tool does not imply that you have to design a whole new syntax for it. The similar comparison will be frontend frameworks. Some frameworks like React and Vue use [hook](https://react.dev/reference/react/hooks) or [signals](https://dev.to/this-is-learning/the-evolution-of-signals-in-javascript-8ob) to represent state changes. But using these building blocks does not grant the verdict to design a new language for your frontend framework. Even the most avant-garde company only introduces [new syntax](https://flow.org/en/docs/react/hook-syntax/) in JavaScript, not inventing a new language.
5658

59+
5760
### Subjective opinion is not objective fact
5861

5962
> I think GritQL queries are significantly easier to read than ast-grep's mix of DSL of YAML.
@@ -85,9 +88,9 @@ Biome's DSL is a mix of several different paradigms: declarative, logic, and imp
8588
}
8689
```
8790

88-
- `$method('$message')` is a declarative pattern matching syntax.
89-
- `where` and `<:` are related to [logic programming](https://en.wikipedia.org/wiki/Logic_programming#:~:text=Logic%20programming%20is%20a%20programming,solve%20problems%20in%20the%20domain.) paradigm, say, [Prolog](https://en.wikipedia.org/wiki/Prolog) or SQL.
90-
- `if` is a typical imperative programming paradigm
91+
* `$method('$message')` is a declarative pattern matching syntax.
92+
* `where` and `<:` are related to [logic programming](https://en.wikipedia.org/wiki/Logic_programming#:~:text=Logic%20programming%20is%20a%20programming,solve%20problems%20in%20the%20domain.) paradigm, say, [Prolog](https://en.wikipedia.org/wiki/Prolog) or SQL.
93+
* `if` is a typical imperative programming paradigm
9194

9295
The mixture of paradigms does not blend well. At least, in the eye of a programming language veteran, it is too messy for a DSL for linting or structural search. We are not designing a next-era programming language.
9396

@@ -156,9 +159,9 @@ They all look like function calls, but they are not. See explanation below for t
156159

157160
These three concepts are very similar, but they have slightly different usage in the DSL.
158161

159-
- `pattern` is used in `<:` or somewhere else, I dunno, the doc does not explain it well.
160-
- `predicate` is used in `where` condition.
161-
- `function` is used in `assignment`, `insertion` or `rewrite`.
162+
* `pattern` is used in `<:` or somewhere else, I dunno, the doc does not explain it well.
163+
* `predicate` is used in `where` condition.
164+
* `function` is used in `assignment`, `insertion` or `rewrite`.
162165

163166
Example:
164167

@@ -186,19 +189,19 @@ If you still have patience, you need one last thing to learn: variable scope.
186189

187190
I have no better explanation for it since I don't understand it well, so I will quote the [official documentation](https://docs.grit.io/language/bubble):
188191

189-
> Once a metavariable is bound to a value, it retains this value throughout the target code. Therefore, the scope of the metavariable spans the entire target file.
192+
> Once a metavariable is bound to a value, it retains this value throughout the target code. Therefore, the scope of the metavariable spans the entire target file.
190193
191194
To fully understand it, you also need to know `bubble`, `bubble($argument)` and pattern auto wrap.
192195

193196
## What can go even more wrong?
194197

195198
Integrating a custom linting rule from another parser ecosystem to your own has several more decisions to make. Making bad decisions can lead to even more confusion.
196199

197-
- Your pattern syntax includes non standard syntax, like `$...`. You need to [change your parser](https://github.com/biomejs/biome/blob/31e439674493da76e0ce213e5660be3d903efbef/crates/biome_js_parser/src/syntax/jsx/mod.rs#L321) to support it.
198-
- You need to make a decision if you want to support existing pattern libraries. But these patterns are built upon [tree-sitter](https://tree-sitter.github.io/tree-sitter/). So you have to [map tree-sitter AST to your own](https://github.com/biomejs/biome/blob/7bf9a608e1592fd595f658f5f800e12d51835d34/crates/biome_grit_patterns/src/grit_target_language/js_target_language.rs#L42-L55)
199-
- Even worse, if you chose to support existing pattern libraries, you also need to work on a general algorithm to handle incompatibility between different ASTs. For example, different AST structures, different node names, different node properties, etc.
200-
- If you only supports part of it, how can you teach your users what is supported and what is not, without [reading the source](https://github.com/biomejs/biome/blob/7bf9a608e1592fd595f658f5f800e12d51835d34/crates/biome_grit_patterns/src/grit_target_language/js_target_language.rs#L48-L50)?
201-
- You also need to update your playground or editor plugins to support mapping between tree-sitter AST and your own AST. And teach users to use it.
200+
* Your pattern syntax includes non standard syntax, like `$...`. You need to [change your parser](https://github.com/biomejs/biome/blob/31e439674493da76e0ce213e5660be3d903efbef/crates/biome_js_parser/src/syntax/jsx/mod.rs#L321) to support it.
201+
* You need to make a decision if you want to support existing pattern libraries. But these patterns are built upon [tree-sitter](https://tree-sitter.github.io/tree-sitter/). So you have to [map tree-sitter AST to your own](https://github.com/biomejs/biome/blob/7bf9a608e1592fd595f658f5f800e12d51835d34/crates/biome_grit_patterns/src/grit_target_language/js_target_language.rs#L42-L55)
202+
* Even worse, if you chose to support existing pattern libraries, you also need to work on a general algorithm to handle incompatibility between different ASTs. For example, different AST structures, different node names, different node properties, etc.
203+
* If you only supports part of it, how can you teach your users what is supported and what is not, without [reading the source](https://github.com/biomejs/biome/blob/7bf9a608e1592fd595f658f5f800e12d51835d34/crates/biome_grit_patterns/src/grit_target_language/js_target_language.rs#L48-L50)?
204+
* You also need to update your playground or editor plugins to support mapping between tree-sitter AST and your own AST. And teach users to use it.
202205

203206
## Conclusion
204207

@@ -210,11 +213,11 @@ If you are a library or framework author, you can make decision based on your ow
210213

211214
Consider these points when you want to have objective comparison:
212215

213-
- Documentation?
214-
- User Education? Howe you teach users to write your DSL?
215-
- Tooling support like [playground](/playground.html).
216-
- Editor support beyong syntax highlighting. Say LSP.
217-
- Integration with API, how you bring type-safe DSL into your general purpose programming language, like [graphql](https://github.com/Quramy/ts-graphql-plugin) and [styled component](https://github.com/styled-components/typescript-styled-plugin).
218-
- Broader ecosystem support, such as GitHub language detection, AI support, etc.
216+
* Documentation?
217+
* User Education? Howe you teach users to write your DSL?
218+
* Tooling support like [playground](/playground.html).
219+
* Editor support beyong syntax highlighting. Say LSP.
220+
* Integration with API, how you bring type-safe DSL into your general purpose programming language, like [graphql](https://github.com/Quramy/ts-graphql-plugin) and [styled component](https://github.com/styled-components/typescript-styled-plugin).
221+
* Broader ecosystem support, such as GitHub language detection, AI support, etc.
219222

220223
If you are going to use native tooling in your JavaScript/TypeScript project, I recommend you to use [oxlint](https://oxc.rs/) and, if you need simple custom rules, [ast-grep](https://ast-grep.github.io/).

website/catalog/c/rewrite-method-to-function-call.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ transform:
2626
MAYBE_COMMA:
2727
replace:
2828
source: $$$ARGS
29-
replace: "^.+"
30-
by: ", "
29+
replace: '^.+'
30+
by: ', '
3131
fix:
3232
$METHOD(&$R$MAYBE_COMMA$$$ARGS)
3333
```

website/catalog/c/yoda-condition.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ In programming jargon, a [Yoda condition](https://en.wikipedia.org/wiki/Yoda_con
1616
id: may-the-force-be-with-you
1717
language: c
1818
rule:
19-
pattern: $A == $B # Find equality comparison
20-
inside: # inside an if_statement
19+
pattern: $A == $B # Find equality comparison
20+
inside: # inside an if_statement
2121
kind: parenthesized_expression
22-
inside: { kind: if_statement }
23-
constraints: # with the constraint that
24-
B: { kind: number_literal } # right side is a number
22+
inside: {kind: if_statement}
23+
constraints: # with the constraint that
24+
B: { kind: number_literal } # right side is a number
2525
fix: $B == $A
2626
```
2727

website/catalog/cpp/fix-format-vuln.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ constraints:
2525
VAR: # not a literal string
2626
not:
2727
any:
28-
- { kind: string_literal }
29-
- { kind: concatenated_string }
28+
- { kind: string_literal }
29+
- { kind: concatenated_string }
3030
fix: $PRINTF($S, "%s", $VAR)
3131
```
3232

website/catalog/go/match-function-call.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ id: match-function-call
2020
language: go
2121
rule:
2222
pattern:
23-
context: "func t() { fmt.Println($A) }"
23+
context: 'func t() { fmt.Println($A) }'
2424
selector: call_expression
2525
```
2626

0 commit comments

Comments
 (0)