Skip to content

Commit e351d6c

Browse files
authored
Add tests for ast-grep rules (nushell#16817)
- Updated schema urls to use `rust_rule`, which provides tree-sitter node name completions. - Added tests for all existing lints. - Ran tests and generated snapshots
1 parent dba8fee commit e351d6c

20 files changed

+255
-8
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/ast-grep/ast-grep/main/schemas/rust_rule.json
2+
3+
id: format-in-nu-macro
4+
language: rust
5+
severity: error
6+
message: "`nu!` macro already supports format strings, use of `format!` is unnecessary"
7+
8+
rule:
9+
pattern:
10+
context: $FORMAT!($$$_)
11+
selector: identifier
12+
kind: identifier
13+
regex: "^format$"
14+
inside:
15+
stopBy: end
16+
kind: token_tree
17+
inside:
18+
pattern: nu!($$$_)
19+
20+
labels:
21+
FORMAT:
22+
style: primary

ast-grep/rules/if-matches-chain.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# yaml-language-server: $schema=https://raw.githubusercontent.com/ast-grep/ast-grep/main/schemas/rule.json
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/ast-grep/ast-grep/main/schemas/rust_rule.json
22

33
id: if-matches-chain
44
language: rust

ast-grep/rules/if-matches.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# yaml-language-server: $schema=https://raw.githubusercontent.com/ast-grep/ast-grep/main/schemas/rule.json
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/ast-grep/ast-grep/main/schemas/rust_rule.json
22

33
id: if-matches
44
language: rust

ast-grep/rules/internal_span.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# yaml-language-server: $schema=https://raw.githubusercontent.com/ast-grep/ast-grep/main/schemas/rule.json
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/ast-grep/ast-grep/main/schemas/rust_rule.json
22

33
id: internal_span
44
language: rust

ast-grep/rules/let-if-let.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# yaml-language-server: $schema=https://raw.githubusercontent.com/ast-grep/ast-grep/main/schemas/rule.json
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/ast-grep/ast-grep/main/schemas/rust_rule.json
22

33
id: let-if-let-some
44
language: rust

ast-grep/rules/long-string.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# yaml-language-server: $schema=https://raw.githubusercontent.com/ast-grep/ast-grep/main/schemas/rule.json
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/ast-grep/ast-grep/main/schemas/rust_rule.json
22

33
id: long-string
44
language: rust

ast-grep/rules/span-unknown.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# yaml-language-server: $schema=https://raw.githubusercontent.com/ast-grep/ast-grep/main/schemas/rule.json
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/ast-grep/ast-grep/main/schemas/rust_rule.json
22

33
id: span-unknown
44
language: rust
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
id: format-in-nu-macro
2+
snapshots:
3+
? |
4+
let actual = nu!(format!(
5+
r#"{sample}
6+
| chunk-by {{|it| $it.cool}}
7+
| length"#,
8+
));
9+
: labels:
10+
- source: format
11+
style: primary
12+
start: 17
13+
end: 23
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
id: if-matches-chain
2+
snapshots:
3+
? |
4+
if matches!(shape, SyntaxShape::Closure(_)) {
5+
parse_closure();
6+
} else if matches!(shape, SyntaxShape::Block(_)) {
7+
parse_block();
8+
} else if matches!(shape, SyntaxShape::MatchBlock) {
9+
parse_match_block();
10+
} else {
11+
parse_other();
12+
}
13+
: labels:
14+
- source: |-
15+
if matches!(shape, SyntaxShape::Closure(_)) {
16+
parse_closure();
17+
} else if matches!(shape, SyntaxShape::Block(_)) {
18+
parse_block();
19+
} else if matches!(shape, SyntaxShape::MatchBlock) {
20+
parse_match_block();
21+
} else {
22+
parse_other();
23+
}
24+
style: primary
25+
start: 0
26+
end: 236
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
id: if-matches
2+
snapshots:
3+
? |
4+
if matches!(shape, SyntaxShape::Closure(_)) {
5+
parse_closure();
6+
} else {
7+
dont();
8+
}
9+
: fixed: |
10+
if let SyntaxShape::Closure(_) = shape {
11+
parse_closure();
12+
} else {
13+
dont();
14+
}
15+
labels:
16+
- source: matches!(shape, SyntaxShape::Closure(_))
17+
style: primary
18+
start: 3
19+
end: 43
20+
- source: |-
21+
if matches!(shape, SyntaxShape::Closure(_)) {
22+
parse_closure();
23+
} else {
24+
dont();
25+
}
26+
style: secondary
27+
start: 0
28+
end: 85

0 commit comments

Comments
 (0)