Skip to content

Commit

Permalink
Merge pull request protofire#291 from protofire/pragma-experimental-c…
Browse files Browse the repository at this point in the history
…ompiler-rule

Check name of pragma for compiler-rule
  • Loading branch information
fvictorio authored May 26, 2021
2 parents 15a964c + 19a1b89 commit b4ac341
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/rules/security/compiler-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ class CompilerVersionChecker extends BaseChecker {
}

PragmaDirective(node) {
if (!semver.satisfies(semver.minVersion(node.value), this.requirement)) {
if (
node.name === 'solidity' &&
!semver.satisfies(semver.minVersion(node.value), this.requirement)
) {
this.warn(
node,
`Compiler version ${node.value} does not satisfy the ${this.requirement} semver requirement`
Expand Down
15 changes: 15 additions & 0 deletions test/rules/security/compiler-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,19 @@ describe('Linter - compiler-version', () => {

assert.equal(report.errorCount, 0)
})

it(`should not report compiler version error with correct pragma and pragma experimental`, () => {
const report = linter.processStr(
`pragma solidity ^0.7.4;
pragma experimental ABIEncoderV2;
contract Main {
}`,
{
rules: { 'compiler-version': ['error', '^0.7.4'] }
}
)

assert.equal(report.errorCount, 0)
})
})

0 comments on commit b4ac341

Please sign in to comment.