From f1743456b112ccb8b9366833ba4edfc8588ced58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Venturo?= Date: Thu, 20 Dec 2018 11:01:09 -0300 Subject: [PATCH 1/3] Added disable-previous-line. --- lib/comment-directive-parser.js | 10 ++++++++++ test/comment-directives.js | 29 +++++++++++++++++++++-------- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/lib/comment-directive-parser.js b/lib/comment-directive-parser.js index 37f2f3b3..34a743a2 100644 --- a/lib/comment-directive-parser.js +++ b/lib/comment-directive-parser.js @@ -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') diff --git a/test/comment-directives.js b/test/comment-directives.js index e70b320e..98d616df 100644 --- a/test/comment-directives.js +++ b/test/comment-directives.js @@ -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() @@ -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() @@ -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() @@ -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() ) @@ -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() ) @@ -96,7 +109,7 @@ describe('Linter', () => { ` /* solhint-disable */ pragma solidity ^0.4.4; - pragma solidity 0.3.4; + pragma solidity 0.3.4; `, noIndent() ) @@ -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() ) From b963b98e77924dde0e6e95d3b166c04098e8f236 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Venturo?= Date: Thu, 20 Dec 2018 11:25:37 -0300 Subject: [PATCH 2/3] Fixed some comment directive tests. --- test/comment-directives.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/comment-directives.js b/test/comment-directives.js index e70b320e..fb74baef 100644 --- a/test/comment-directives.js +++ b/test/comment-directives.js @@ -25,7 +25,7 @@ describe('Linter', () => { const report = linter.processStr( ` // solhint-disable-next-line - pragma solidity ^0.4.4; + pragma solidity 0.3.4; pragma solidity 0.3.4; `, noIndent() @@ -38,7 +38,7 @@ describe('Linter', () => { const report = linter.processStr( ` /* solhint-disable-next-line */ - pragma solidity ^0.4.4; + pragma solidity 0.3.4; pragma solidity 0.3.4; `, noIndent() From 3c0bb6c35d34528b551dda85ff5efc5c13bb412b Mon Sep 17 00:00:00 2001 From: fvictorio Date: Thu, 20 Dec 2018 12:19:02 -0300 Subject: [PATCH 3/3] Add test for multiline disable-previous-line comment --- test/comment-directives.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/test/comment-directives.js b/test/comment-directives.js index 98d616df..156e4ba0 100644 --- a/test/comment-directives.js +++ b/test/comment-directives.js @@ -47,7 +47,7 @@ describe('Linter', () => { assertErrorCount(report, 1) }) - it('should disable only one compiler error using multiline comment', () => { + it('should disable only one compiler error on next line using multiline comment', () => { const report = linter.processStr( ` /* solhint-disable-next-line */ @@ -60,6 +60,19 @@ describe('Linter', () => { assertErrorCount(report, 1) }) + it('should disable only one compiler error on previous line using multiline comment', () => { + const report = linter.processStr( + ` + pragma solidity ^0.4.4; + /* solhint-disable-previous-line */ + pragma solidity 0.3.4; + `, + noIndent() + ) + + assertErrorCount(report, 1) + }) + it('should disable only compiler version error', () => { const report = linter.processStr( `