Skip to content

Commit

Permalink
Merge pull request #267 from protofire/fix/258-immutable-as-state-var…
Browse files Browse the repository at this point in the history
…iables
  • Loading branch information
fvictorio committed Nov 8, 2020
2 parents f5b2d23 + a36546b commit e864c8a
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 e864c8a

Please sign in to comment.