Skip to content

Commit

Permalink
avoid counting immutable for the max-state-count rule
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandomg committed Oct 28, 2020
1 parent 445bf32 commit a36546b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/rules/best-practises/max-states-count.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ class MaxStatesCountChecker extends BaseChecker {
ContractDefinition(node) {
const countOfVars = _(node.subNodes)
.filter(({ type }) => type === 'StateVariableDeclaration')
.flatMap(subNode => subNode.variables.filter(variable => !variable.isDeclaredConst))
.flatMap(({ variables }) =>
variables.filter(({ isDeclaredConst, isImmutable }) => !isDeclaredConst && !isImmutable)
)
.value().length

if (countOfVars > this.maxStatesCount) {
Expand Down
14 changes: 14 additions & 0 deletions test/rules/best-practises/max-states-count.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,18 @@ describe('Linter - max-states-count', () => {

assertNoErrors(report)
})

it('should not count immutable variables', () => {
const code = contractWith(`
uint public immutable a;
uint public b;
uint public c;
function f() {}
`)

const report = linter.processStr(code, { rules: { 'max-states-count': ['error', 2] } })

assertNoErrors(report)
})
})

0 comments on commit a36546b

Please sign in to comment.