From ae4c3ad41fd98c66f6df5273286f689452a89abe Mon Sep 17 00:00:00 2001 From: Dan Purdy Date: Tue, 27 Oct 2015 22:00:22 +0000 Subject: [PATCH 1/3] :white_check_mark: Add more space-before-brace tests --- tests/rules/space-before-brace.js | 4 ++-- tests/sass/space-before-brace.scss | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/tests/rules/space-before-brace.js b/tests/rules/space-before-brace.js index 05971260..e0254486 100644 --- a/tests/rules/space-before-brace.js +++ b/tests/rules/space-before-brace.js @@ -12,7 +12,7 @@ describe('space before brace - scss', function () { lint.test(file, { 'space-before-brace': 1 }, function (data) { - lint.assert.equal(3, data.warningCount); + lint.assert.equal(5, data.warningCount); done(); }); }); @@ -26,7 +26,7 @@ describe('space before brace - scss', function () { } ] }, function (data) { - lint.assert.equal(4, data.warningCount); + lint.assert.equal(11, data.warningCount); done(); }); }); diff --git a/tests/sass/space-before-brace.scss b/tests/sass/space-before-brace.scss index c1a35c20..9e3e599d 100644 --- a/tests/sass/space-before-brace.scss +++ b/tests/sass/space-before-brace.scss @@ -20,7 +20,37 @@ .qux { content: 'bar'; + font:{ + family: fantasy; + } @include breakpoint{ content: bar; + font: { + family: fantasy; + } + } +} + + +.other { + content: 'bar'; + font: { + family: fantasy; + } + @include breakpoint { + content: bar; + font{ + family: fantasy; + } + } +} + +.selector { + content: ''; + + .mergeable { + font: { + family: fantasy; + } } } From 06332199c2feec104dfb2d2ca765a3cf6e10af5d Mon Sep 17 00:00:00 2001 From: Dan Purdy Date: Tue, 27 Oct 2015 22:01:38 +0000 Subject: [PATCH 2/3] :bug: Fix issue with nested values space-before-brace --- lib/rules/space-before-brace.js | 76 ++++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 26 deletions(-) diff --git a/lib/rules/space-before-brace.js b/lib/rules/space-before-brace.js index da1daa60..bdcff459 100644 --- a/lib/rules/space-before-brace.js +++ b/lib/rules/space-before-brace.js @@ -3,6 +3,10 @@ var helpers = require('../helpers'); var getLastWhitespace = function (node) { + if (node === false) { + return null; + } + if (typeof node !== 'object') { return false; } @@ -20,35 +24,55 @@ module.exports = { }, 'detect': function (ast, parser) { var result = []; + if (ast.syntax === 'scss') { + ast.traverseByTypes(['block', 'atrulers', 'declaration'], function (block, i, parent) { + var previous = false, + whitespace, + warn = {}; - ast.traverseByTypes(['block', 'atrulers'], function (block, i, parent) { - var previous = parent.get(i - 1), - whitespace = getLastWhitespace(previous); - - if (whitespace === false) { - if (parser.options.include) { - result = helpers.addUnique(result, { - 'ruleId': parser.rule.name, - 'line': block.start.line, - 'column': block.start.column - 1, - 'message': 'Whitespace required before {', - 'severity': parser.severity - }); + if ((block.is('block') || block.is('atrulers')) && !parent.is('value')) { + previous = parent.get(i - 1); } - } - else { - if (!parser.options.include) { - result = helpers.addUnique(result, { - 'ruleId': parser.rule.name, - 'line': whitespace.start.line, - 'column': whitespace.start.column, - 'message': 'Whitespace not allowed before {', - 'severity': parser.severity - }); + else if (block.is('declaration')) { + if (block.contains('value')) { + for (var j = 0; j < block.content.length; j++) { + if (block.content[j].is('value') && block.content[j].content[0].is('block')) { + previous = block.content[j - 1]; + warn.line = block.content[j].content[0].start.line; + warn.col = block.content[j].content[0].start.column; + } + } + } } - } - }); - + whitespace = getLastWhitespace(previous); + if (whitespace === false) { + if (parser.options.include) { + if (!warn.hasOwnProperty('line')) { + warn.line = block.start.line; + warn.col = block.start.column; + } + result = helpers.addUnique(result, { + 'ruleId': parser.rule.name, + 'line': warn.line, + 'column': warn.col - 1, + 'message': 'Whitespace required before {', + 'severity': parser.severity + }); + } + } + else { + if (!parser.options.include && whitespace !== null) { + result = helpers.addUnique(result, { + 'ruleId': parser.rule.name, + 'line': whitespace.start.line, + 'column': whitespace.start.column, + 'message': 'Whitespace not allowed before {', + 'severity': parser.severity + }); + } + } + }); + } return result; } }; From 4d53b610896b96388e4f74ffcada298238f5dc9a Mon Sep 17 00:00:00 2001 From: Dan Purdy Date: Wed, 28 Oct 2015 14:17:57 +0000 Subject: [PATCH 3/3] Fix test source --- tests/sass/space-before-brace.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/sass/space-before-brace.scss b/tests/sass/space-before-brace.scss index 9e3e599d..c5758d9b 100644 --- a/tests/sass/space-before-brace.scss +++ b/tests/sass/space-before-brace.scss @@ -39,7 +39,7 @@ } @include breakpoint { content: bar; - font{ + font:{ family: fantasy; } }