From 6c8f13fa29d74152816c85f8feacf41eee0f76e9 Mon Sep 17 00:00:00 2001 From: Dan Purdy Date: Sat, 2 Sep 2017 16:25:34 +0100 Subject: [PATCH] :bug: ignore interpolation in class-name-format --- lib/helpers.js | 5 ++++- tests/rules/class-name-format.js | 32 +++++++++++++++---------------- tests/sass/class-name-format.sass | 17 ++++++++++++++++ tests/sass/class-name-format.scss | 21 ++++++++++++++++++++ 4 files changed, 58 insertions(+), 17 deletions(-) diff --git a/lib/helpers.js b/lib/helpers.js index 0b9af3ce..725d31bc 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -309,7 +309,10 @@ helpers.attemptTraversal = function (node, traversalPath) { currentNodeList = [], processChildNode = function processChildNode (child) { child.forEach(traversalPath[i], function (n) { - nextNodeList.push(n); + if (n.content && n.content.some && n.contains('interpolation')) { + return false; + } + return nextNodeList.push(n); }); }; diff --git a/tests/rules/class-name-format.js b/tests/rules/class-name-format.js index c5f5365c..751b05a2 100644 --- a/tests/rules/class-name-format.js +++ b/tests/rules/class-name-format.js @@ -12,7 +12,7 @@ describe('class name format - scss', function () { lint.test(file, { 'class-name-format': 1 }, function (data) { - lint.assert.equal(31, data.warningCount); + lint.assert.equal(33, data.warningCount); done(); }); }); @@ -26,7 +26,7 @@ describe('class name format - scss', function () { } ] }, function (data) { - lint.assert.equal(30, data.warningCount); + lint.assert.equal(32, data.warningCount); done(); }); }); @@ -40,7 +40,7 @@ describe('class name format - scss', function () { } ] }, function (data) { - lint.assert.equal(40, data.warningCount); + lint.assert.equal(42, data.warningCount); done(); }); }); @@ -54,7 +54,7 @@ describe('class name format - scss', function () { } ] }, function (data) { - lint.assert.equal(40, data.warningCount); + lint.assert.equal(43, data.warningCount); done(); }); }); @@ -68,7 +68,7 @@ describe('class name format - scss', function () { } ] }, function (data) { - lint.assert.equal(36, data.warningCount); + lint.assert.equal(37, data.warningCount); done(); }); }); @@ -82,7 +82,7 @@ describe('class name format - scss', function () { } ] }, function (data) { - lint.assert.equal(17, data.warningCount); + lint.assert.equal(18, data.warningCount); done(); }); }); @@ -110,7 +110,7 @@ describe('class name format - scss', function () { } ] }, function (data) { - lint.assert.equal(42, data.warningCount); + lint.assert.equal(45, data.warningCount); done(); }); }); @@ -126,7 +126,7 @@ describe('class name format - scss', function () { } ] }, function (data) { - lint.assert.equal(38, data.warningCount); + lint.assert.equal(41, data.warningCount); lint.assert.equal(data.messages[0].message, message); done(); }); @@ -143,7 +143,7 @@ describe('class name format - sass', function () { lint.test(file, { 'class-name-format': 1 }, function (data) { - lint.assert.equal(31, data.warningCount); + lint.assert.equal(33, data.warningCount); done(); }); }); @@ -157,7 +157,7 @@ describe('class name format - sass', function () { } ] }, function (data) { - lint.assert.equal(30, data.warningCount); + lint.assert.equal(32, data.warningCount); done(); }); }); @@ -171,7 +171,7 @@ describe('class name format - sass', function () { } ] }, function (data) { - lint.assert.equal(40, data.warningCount); + lint.assert.equal(42, data.warningCount); done(); }); }); @@ -185,7 +185,7 @@ describe('class name format - sass', function () { } ] }, function (data) { - lint.assert.equal(40, data.warningCount); + lint.assert.equal(43, data.warningCount); done(); }); }); @@ -199,7 +199,7 @@ describe('class name format - sass', function () { } ] }, function (data) { - lint.assert.equal(36, data.warningCount); + lint.assert.equal(37, data.warningCount); done(); }); }); @@ -213,7 +213,7 @@ describe('class name format - sass', function () { } ] }, function (data) { - lint.assert.equal(17, data.warningCount); + lint.assert.equal(18, data.warningCount); done(); }); }); @@ -241,7 +241,7 @@ describe('class name format - sass', function () { } ] }, function (data) { - lint.assert.equal(42, data.warningCount); + lint.assert.equal(45, data.warningCount); done(); }); }); @@ -257,7 +257,7 @@ describe('class name format - sass', function () { } ] }, function (data) { - lint.assert.equal(38, data.warningCount); + lint.assert.equal(41, data.warningCount); lint.assert.equal(data.messages[0].message, message); done(); }); diff --git a/tests/sass/class-name-format.sass b/tests/sass/class-name-format.sass index f63b1fe9..0b22788e 100644 --- a/tests/sass/class-name-format.sass +++ b/tests/sass/class-name-format.sass @@ -94,3 +94,20 @@ .strict-bem__elem_key--fail color: red + + +// Issue #988 - Fix interpolation in class names + +.#{$primary-class}--small + color: red + + &__child + color: red + +.test + &#{$primary-class} + color: red + + &__block + &--mod + color: blue diff --git a/tests/sass/class-name-format.scss b/tests/sass/class-name-format.scss index bbb2452e..cffedbc0 100644 --- a/tests/sass/class-name-format.scss +++ b/tests/sass/class-name-format.scss @@ -133,3 +133,24 @@ .strict-bem__elem_key--fail { color: red; } + +// Issue #988 - Fix interpolation in class names + +.#{$primary-class}--small { + color: red; + &__child { + color: red; + } +} + +.test { + &#{$primary-class} { + color: red; + } + + &__block { + &--mod { + color: blue; + } + } +}