diff --git a/rule-tests/__snapshots__/unused-parameter-snapshot.yml b/rule-tests/__snapshots__/unused-parameter-snapshot.yml new file mode 100644 index 0000000..695bdf2 --- /dev/null +++ b/rule-tests/__snapshots__/unused-parameter-snapshot.yml @@ -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 diff --git a/rule-tests/unused-parameter-test.yml b/rule-tests/unused-parameter-test.yml new file mode 100644 index 0000000..4f58583 --- /dev/null +++ b/rule-tests/unused-parameter-test.yml @@ -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) {}" diff --git a/rules/unused-parameter.yml b/rules/unused-parameter.yml new file mode 100644 index 0000000..04cd14c --- /dev/null +++ b/rules/unused-parameter.yml @@ -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