Skip to content

Commit

Permalink
fix: no-unused-vars false positive for unnamed payable parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
dbale-altoros committed Feb 7, 2023
1 parent 735dd49 commit d1fba2b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/rules/best-practises/no-unused-vars.js
Expand Up @@ -31,8 +31,19 @@ class NoUnusedVarsChecker extends BaseChecker {

if (!ignoreWhen(funcWithoutBlock, emptyBlock)) {
VarUsageScope.activate(node)
// filters 'payable' keyword as name when defining function like this:
// function foo(address payable) public view {}
node.parameters
.filter((parameter) => parameter.name)
.filter((parameter) => {
if (
parameter.typeName.name === 'address' &&
parameter.typeName.stateMutability === null &&
parameter.name === 'payable'
)
return null
else return parameter.name
})

.forEach((parameter) => {
this._addVariable(parameter)
})
Expand Down
3 changes: 3 additions & 0 deletions test/rules/best-practises/no-unused-vars.js
Expand Up @@ -10,6 +10,9 @@ describe('Linter - no-unused-vars', () => {
contractWith('function a(uint a, uint b) public { uint c = a + b; }'),
contractWith('function foo(uint a) { assembly { let t := a } }'),
contractWith('function foo(uint a) { uint b = a; } '),
contractWith('function foo(address payable unUsed1, address payable) { this; } '),
contractWith('function foo(string memory, uint unUsed2) { this; } '),
contractWith('function foo(string calldata, uint unUsed3) { this; } '),
]

UNUSED_VARS.forEach((curData) =>
Expand Down

0 comments on commit d1fba2b

Please sign in to comment.