Skip to content

Commit

Permalink
Merge pull request #91 from nventuro/feat/disable-previous-line
Browse files Browse the repository at this point in the history
Added disable-previous-line.
  • Loading branch information
Franco Victorio committed Dec 21, 2018
2 parents f389547 + 99efbf9 commit fb52933
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 9 deletions.
10 changes: 10 additions & 0 deletions lib/comment-directive-parser.js
Expand Up @@ -34,6 +34,16 @@ class CommentDirectiveParser {
return
}

if (text.includes('solhint-disable-previous-line')) {
const rules = this.parseRuleIds(text, 'solhint-disable-previous-line')

if (curLine > 0) {
ruleStore.disableRules(curLine - 1, rules)
}

return
}

if (text.includes('solhint-disable')) {
const rules = this.parseRuleIds(text, 'solhint-disable')

Expand Down
44 changes: 35 additions & 9 deletions test/comment-directives.js
Expand Up @@ -21,11 +21,11 @@ describe('Linter', () => {
assertNoErrors(report)
})

it('should disable only one compiler error', () => {
it('should disable only one compiler error on next line', () => {
const report = linter.processStr(
`
// solhint-disable-next-line
pragma solidity ^0.4.4;
pragma solidity 0.3.4;
pragma solidity 0.3.4;
`,
noIndent()
Expand All @@ -34,11 +34,37 @@ describe('Linter', () => {
assertErrorCount(report, 1)
})

it('should disable only one compiler error using multiline comment', () => {
it('should disable only one compiler error on previous line', () => {
const report = linter.processStr(
`
pragma solidity 0.3.4;
// solhint-disable-previous-line
pragma solidity 0.3.4;
`,
noIndent()
)

assertErrorCount(report, 1)
})

it('should disable only one compiler error on next line using multiline comment', () => {
const report = linter.processStr(
`
/* solhint-disable-next-line */
pragma solidity ^0.4.4;
pragma solidity 0.3.4;
pragma solidity 0.3.4;
`,
noIndent()
)

assertErrorCount(report, 1)
})

it('should disable only one compiler error on previous line using multiline comment', () => {
const report = linter.processStr(
`
pragma solidity 0.3.4;
/* solhint-disable-previous-line */
pragma solidity 0.3.4;
`,
noIndent()
Expand All @@ -51,7 +77,7 @@ describe('Linter', () => {
const report = linter.processStr(
`
// solhint-disable compiler-gt-0_4
pragma solidity ^0.4.4;
pragma solidity ^0.4.4;
pragma solidity 0.3.4; // disabled error: Compiler version must be greater that 0.4
`,
noIndent()
Expand All @@ -67,7 +93,7 @@ describe('Linter', () => {
/* solhint-disable compiler-gt-0_4 */
pragma solidity 0.3.4;
/* solhint-enable compiler-gt-0_4 */
pragma solidity 0.3.4;
pragma solidity 0.3.4;
`,
noIndent()
)
Expand All @@ -82,7 +108,7 @@ describe('Linter', () => {
/* solhint-disable compiler-gt-0_4 */
pragma solidity ^0.4.4;
/* solhint-enable compiler-gt-0_4 */
pragma solidity ^0.4.4;
pragma solidity ^0.4.4;
`,
noIndent()
)
Expand All @@ -96,7 +122,7 @@ describe('Linter', () => {
`
/* solhint-disable */
pragma solidity ^0.4.4;
pragma solidity 0.3.4;
pragma solidity 0.3.4;
`,
noIndent()
)
Expand All @@ -110,7 +136,7 @@ describe('Linter', () => {
/* solhint-disable */
pragma solidity ^0.4.4;
/* solhint-enable */
pragma solidity ^0.4.4;
pragma solidity ^0.4.4;
`,
noIndent()
)
Expand Down

0 comments on commit fb52933

Please sign in to comment.