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

Avoid counting immutable for the max-state-count rule #267

Merged
merged 1 commit into from
Nov 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
})
})