Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude abi.encodeX calls from func-named-parameters #583

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions lib/rules/naming/func-named-parameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ const meta = {
description: 'Function call with four NAMED parameters',
code: 'functionName({ sender: _senderAddress, amount: 1e18, token: _tokenAddress, receiver: _receiverAddress })',
},
{
description: 'abi.encodeX call with four UNNAMED parameters',
code: 'abi.encodePacked(_senderAddress, 1e18, _tokenAddress, _receiverAddress )',
},
],
bad: [
{
Expand Down Expand Up @@ -67,12 +71,24 @@ class FunctionNamedParametersChecker extends BaseChecker {
const qtyNamed = node.names.length
const qtyArgs = node.arguments.length

if (qtyArgs !== 0) {
if (qtyNamed === 0 && qtyArgs > this.maxUnnamedArguments) {
this.error(
node,
`Named parameters missing. MIN unnamed arguments is ${this.maxUnnamedArguments}`
)
if (!this.isAbiCall(node)) {
if (qtyArgs !== 0) {
if (qtyNamed === 0 && qtyArgs > this.maxUnnamedArguments) {
this.error(
node,
`Named parameters missing. MIN unnamed arguments is ${this.maxUnnamedArguments}`
)
}
}
}
}

isAbiCall(node) {
if (node.expression.type === 'MemberAccess') {
if (node.expression.expression.type === 'Identifier') {
if (node.expression.expression.name === 'abi') {
return true
}
}
}
}
Expand Down
Loading