Skip to content

Commit

Permalink
Added disable-previous-line.
Browse files Browse the repository at this point in the history
  • Loading branch information
nventuro committed Dec 20, 2018
1 parent f389547 commit f174345
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
10 changes: 10 additions & 0 deletions lib/comment-directive-parser.js
Original file line number Diff line number Diff line change
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
29 changes: 21 additions & 8 deletions test/comment-directives.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,24 @@ 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.4.4;
pragma solidity 0.3.4;
`,
noIndent()
)

assertErrorCount(report, 1)
})

it('should disable only one compiler error on previous line', () => {
const report = linter.processStr(
`
pragma solidity ^0.4.4;
// solhint-disable-previous-line
pragma solidity 0.3.4;
`,
noIndent()
Expand All @@ -38,7 +51,7 @@ describe('Linter', () => {
const report = linter.processStr(
`
/* solhint-disable-next-line */
pragma solidity ^0.4.4;
pragma solidity ^0.4.4;
pragma solidity 0.3.4;
`,
noIndent()
Expand All @@ -51,7 +64,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 +80,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 +95,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 +109,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 +123,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 f174345

Please sign in to comment.