Skip to content

Commit

Permalink
Add rule flagging unused function parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
bbannier committed Dec 29, 2023
1 parent eb10565 commit e31b68b
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
56 changes: 56 additions & 0 deletions rule-tests/__snapshots__/unused-parameter-snapshot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
id: unused-parameter
snapshots:
'function foo(x: uint8) {}':
labels:
- source: x
style: primary
start: 13
end: 14
- source: foo
style: secondary
start: 9
end: 12
- source: '{}'
style: secondary
start: 23
end: 25
- source: 'function foo(x: uint8) {}'
style: secondary
start: 0
end: 25
'function foo(x: uint8, y: uint8) { x; }':
labels:
- source: y
style: primary
start: 23
end: 24
- source: x
style: secondary
start: 13
end: 14
- source: '{ x; }'
style: secondary
start: 33
end: 39
- source: 'function foo(x: uint8, y: uint8) { x; }'
style: secondary
start: 0
end: 39
'function foo(x: uint8, y: uint8) {}':
labels:
- source: x
style: primary
start: 13
end: 14
- source: foo
style: secondary
start: 9
end: 12
- source: '{}'
style: secondary
start: 33
end: 35
- source: 'function foo(x: uint8, y: uint8) {}'
style: secondary
start: 0
end: 35
10 changes: 10 additions & 0 deletions rule-tests/unused-parameter-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
id: unused-parameter
valid:
- "function foo() {}"
- "function foo(x: uint8) { x; }"
- "function foo(x: uint8, y: uint8) { x; y; }"
- "function foo(x: uint8, y: uint8);"
invalid:
- "function foo(x: uint8) {}"
- "function foo(x: uint8, y: uint8) { x; }"
- "function foo(x: uint8, y: uint8) {}"
25 changes: 25 additions & 0 deletions rules/unused-parameter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
id: unused-parameter
message: Parameter is not used
severity: error
language: spicy
rule:
kind: "ident"
pattern: $ID
all:
# Reject the original function ident. All parameter idents follow it, but
# it doesn't follow anything itself.
- follows:
kind: "ident"
stopBy: end

- inside:
kind: "function_decl"
all:
- has:
kind: "block"
- not:
has:
kind: "block"
has:
pattern: $ID
stopBy: end

0 comments on commit e31b68b

Please sign in to comment.