From c096e241fb301a92379d791f9b684dcddcfa14da Mon Sep 17 00:00:00 2001 From: Ben Griffith Date: Tue, 27 Oct 2015 17:24:49 +0000 Subject: [PATCH 1/4] :bug: Fix trailing-semicolon issue with nested properties --- lib/rules/trailing-semicolon.js | 52 ++++++++++++++++-------------- tests/sass/trailing-semicolon.scss | 10 +++++- 2 files changed, 37 insertions(+), 25 deletions(-) diff --git a/lib/rules/trailing-semicolon.js b/lib/rules/trailing-semicolon.js index ee072e56..8a42375d 100644 --- a/lib/rules/trailing-semicolon.js +++ b/lib/rules/trailing-semicolon.js @@ -23,38 +23,42 @@ module.exports = { } block.forEach('declaration', function (item, i, parent) { - if (helpers.isEqual(last, item)) { - next = parent.content[i + 1]; + if (item.contains('value')) { + if (!item.last('value').contains('block')) { + if (helpers.isEqual(last, item)) { + if (parent.content[i + 1]) { + next = parent.content[i + 1]; - if (next.type === 'declarationDelimiter') { - if (!parser.options.include) { - result = helpers.addUnique(result, { - 'ruleId': parser.rule.name, - 'severity': parser.severity, - 'line': item.end.line, - 'column': item.end.column, - 'message': 'No trailing semicolons allowed' - }); - } - } - else { - if (parser.options.include) { - result = helpers.addUnique(result, { - 'ruleId': parser.rule.name, - 'severity': parser.severity, - 'line': item.last('value').start.line, - 'column': item.last('value').start.column, - 'message': 'Trailing semicolons required' - }); + if (next.type === 'declarationDelimiter') { + if (!parser.options.include) { + result = helpers.addUnique(result, { + 'ruleId': parser.rule.name, + 'severity': parser.severity, + 'line': item.end.line, + 'column': item.end.column, + 'message': 'No trailing semicolons allowed' + }); + } + } + else { + if (parser.options.include) { + result = helpers.addUnique(result, { + 'ruleId': parser.rule.name, + 'severity': parser.severity, + 'line': item.last('value').start.line, + 'column': item.last('value').start.column, + 'message': 'Trailing semicolons required' + }); + } + } + } } } } - }); }); } - return result; } }; diff --git a/tests/sass/trailing-semicolon.scss b/tests/sass/trailing-semicolon.scss index 30625d4b..29fb2b85 100644 --- a/tests/sass/trailing-semicolon.scss +++ b/tests/sass/trailing-semicolon.scss @@ -1,5 +1,5 @@ .foo { - content: 'bar'; + content: 'bar' } .bar { @@ -10,3 +10,11 @@ content: 'waldo' } } + +.foo { + font: { + family: 'Arial'; + weight: bold; + size: 2rem; + } +} From 9baf22960468f6c1eb41e001164d96b5646e1766 Mon Sep 17 00:00:00 2001 From: Ben Griffith Date: Tue, 27 Oct 2015 17:33:56 +0000 Subject: [PATCH 2/4] Replace type checking with .is --- lib/rules/trailing-semicolon.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rules/trailing-semicolon.js b/lib/rules/trailing-semicolon.js index 8a42375d..2c542a4c 100644 --- a/lib/rules/trailing-semicolon.js +++ b/lib/rules/trailing-semicolon.js @@ -29,7 +29,7 @@ module.exports = { if (parent.content[i + 1]) { next = parent.content[i + 1]; - if (next.type === 'declarationDelimiter') { + if (next.is('declarationDelimiter')) { if (!parser.options.include) { result = helpers.addUnique(result, { 'ruleId': parser.rule.name, From 18c5083defb925ccc633359be7bf3e56526edb4b Mon Sep 17 00:00:00 2001 From: Ben Griffith Date: Tue, 27 Oct 2015 17:45:00 +0000 Subject: [PATCH 3/4] Fix issue with no-trailing-semicolon and nested selectors --- lib/rules/trailing-semicolon.js | 4 +++- tests/rules/trailing-semicolon.js | 2 +- tests/sass/trailing-semicolon.scss | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/rules/trailing-semicolon.js b/lib/rules/trailing-semicolon.js index 2c542a4c..ed9c419f 100644 --- a/lib/rules/trailing-semicolon.js +++ b/lib/rules/trailing-semicolon.js @@ -24,7 +24,9 @@ module.exports = { block.forEach('declaration', function (item, i, parent) { if (item.contains('value')) { - if (!item.last('value').contains('block')) { + var valueNode = item.last('value').content[0]; + + if (!valueNode.is('block')) { if (helpers.isEqual(last, item)) { if (parent.content[i + 1]) { next = parent.content[i + 1]; diff --git a/tests/rules/trailing-semicolon.js b/tests/rules/trailing-semicolon.js index 5b5410c8..e5c32bcd 100644 --- a/tests/rules/trailing-semicolon.js +++ b/tests/rules/trailing-semicolon.js @@ -12,7 +12,7 @@ describe('trailing semicolon - scss', function () { lint.test(file, { 'trailing-semicolon': 1 }, function (data) { - lint.assert.equal(2, data.warningCount); + lint.assert.equal(3, data.warningCount); done(); }); }); diff --git a/tests/sass/trailing-semicolon.scss b/tests/sass/trailing-semicolon.scss index 29fb2b85..9cb8bedc 100644 --- a/tests/sass/trailing-semicolon.scss +++ b/tests/sass/trailing-semicolon.scss @@ -4,7 +4,7 @@ .bar { content: 'qux'; - content: 'baz', 'fail' + padding: 0 .qux { content: 'waldo' From 2cbe196e46eae8dc496b95bc3b0aee0cfce9cbb9 Mon Sep 17 00:00:00 2001 From: Ben Griffith Date: Wed, 28 Oct 2015 13:55:40 +0000 Subject: [PATCH 4/4] :white_check_mark: Add further test cases and include:false tests --- tests/rules/trailing-semicolon.js | 16 +++++++++++++++- tests/sass/trailing-semicolon.scss | 22 +++++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/tests/rules/trailing-semicolon.js b/tests/rules/trailing-semicolon.js index e5c32bcd..34a05efe 100644 --- a/tests/rules/trailing-semicolon.js +++ b/tests/rules/trailing-semicolon.js @@ -12,7 +12,21 @@ describe('trailing semicolon - scss', function () { lint.test(file, { 'trailing-semicolon': 1 }, function (data) { - lint.assert.equal(3, data.warningCount); + lint.assert.equal(5, data.warningCount); + done(); + }); + }); + + it('[include: false]', function (done) { + lint.test(file, { + 'trailing-semicolon': [ + 1, + { + 'include': false + } + ] + }, function (data) { + lint.assert.equal(1, data.warningCount); done(); }); }); diff --git a/tests/sass/trailing-semicolon.scss b/tests/sass/trailing-semicolon.scss index 9cb8bedc..c92a00fa 100644 --- a/tests/sass/trailing-semicolon.scss +++ b/tests/sass/trailing-semicolon.scss @@ -11,10 +11,30 @@ } } -.foo { +.qux { font: { family: 'Arial'; weight: bold; size: 2rem; } } + +.baz { + font: { + family: 'Arial'; + weight: bold; + size: 2rem + } +} + +.norf { + border: { + top: { + color: red; + + left: { + radius: 5px + } + } + } +}