Skip to content

Commit

Permalink
Add rule indentifying empty hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
bbannier committed Dec 4, 2023
1 parent 541e627 commit 4d36b0e
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 0 deletions.
13 changes: 13 additions & 0 deletions rule-tests/__snapshots__/empty-hook-inline-snapshot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
id: empty-hook-inline
snapshots:
'type X = unit { x: uint8 {} };':
fixed: 'type X = unit { x: uint8 ; };'
labels:
- source: '{}'
style: primary
start: 25
end: 27
- source: 'x: uint8 {}'
style: secondary
start: 16
end: 27
17 changes: 17 additions & 0 deletions rule-tests/__snapshots__/empty-hook-snapshot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
id: empty-hook
snapshots:
on X::x {}:
fixed: ''
labels:
- source: on X::x {}
style: primary
start: 0
end: 10
- source: '{}'
style: secondary
start: 8
end: 10
- source: '{}'
style: secondary
start: 8
end: 10
5 changes: 5 additions & 0 deletions rule-tests/empty-hook-inline-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
id: empty-hook-inline
valid:
- "type X = unit { x: uint8 {1;} };"
invalid:
- "type X = unit { x: uint8 {} };"
6 changes: 6 additions & 0 deletions rule-tests/empty-hook-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
id: empty-hook
valid:
- "on X::x {1;}"
- "on X::x {1;2;}"
invalid:
- "on X::x {}"
14 changes: 14 additions & 0 deletions rules/empty-hook-inline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
id: empty-hook-inline
message: Remove empty hook
severity: error
language: spicy

rule:
kind: "block"
inside:
kind: "field_decl"
not:
has:
kind: "statement"

fix: ";"
16 changes: 16 additions & 0 deletions rules/empty-hook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
id: empty-hook
message: Remove empty hook
severity: error
language: spicy

rule:
kind: "hook_decl"
has:
kind: "statement"
has:
kind: "block"
not:
has:
kind: "statement"

fix: ""

0 comments on commit 4d36b0e

Please sign in to comment.