You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: website/advanced/language-injection.md
+7-7Lines changed: 7 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -24,7 +24,7 @@ Let's start with a simple example of searching for JavaScript and CSS within HTM
24
24
ast-grep has builtin support to search JavaScript and CSS inside HTML files.
25
25
26
26
27
-
### **Using `sg run`**: find patterns of CSS in an HTML file
27
+
### **Using `ast-grep run`**: find patterns of CSS in an HTML file
28
28
29
29
Suppose we have an HTML file like below:
30
30
@@ -43,7 +43,7 @@ Suppose we have an HTML file like below:
43
43
Running this ast-grep command will extract the matching CSS style code out of the HTML file!
44
44
45
45
```sh
46
-
sg run -p 'color: $COLOR'
46
+
ast-grep run -p 'color: $COLOR'
47
47
```
48
48
49
49
ast-grep outputs this beautiful CLI report.
@@ -55,7 +55,7 @@ test.html
55
55
ast-grep works well even if just providing the pattern without specifying the pattern language!
56
56
57
57
58
-
### **Using `sg scan`**: find JavaScript in HTML with rule files
58
+
### **Using `ast-grep scan`**: find JavaScript in HTML with rule files
59
59
60
60
You can also use ast-grep's [rule file](https://ast-grep.github.io/guide/rule-config.html) to search injected languages.
61
61
@@ -70,10 +70,10 @@ rule:
70
70
message: Prefer use appropriate custom UI instead of obtrusive alert call.
71
71
```
72
72
73
-
The rule above will detect usage of `alert` in JavaScript. Running the rule via `sg scan`.
73
+
The rule above will detect usage of `alert` in JavaScript. Running the rule via `ast-grep scan`.
74
74
75
75
```sh
76
-
sg scan --rule no-alert.yml
76
+
ast-grep scan --rule no-alert.yml
77
77
```
78
78
79
79
The command leverages built-in behaviors in ast-grep to handle language injection seamlessly. It will produce the following warning message for the HTML file above.
@@ -159,7 +159,7 @@ With the above `languageInjections` configuration, ast-grep will:
159
159
You can search the CSS inside JavaScript in the project configuration folder using this command:
160
160
161
161
```sh
162
-
sg -p 'background: $COLOR' -C 2
162
+
ast-grep -p 'background: $COLOR' -C 2
163
163
```
164
164
165
165
It will produce the match result:
@@ -223,7 +223,7 @@ const artistsQuery = graphql`
223
223
We can search the GraphQL fragment via this `--inline-rules` scan.
0 commit comments