From 25b32d7a88112847a949718e9a50d8a127f2f95b Mon Sep 17 00:00:00 2001 From: Ben Griffith Date: Mon, 7 Nov 2016 14:56:31 +0000 Subject: [PATCH 1/5] :bug: Fix false positives on variable declarations - no-duplicate-properties --- lib/rules/no-duplicate-properties.js | 9 ++++++++- tests/sass/no-duplicate-properties.sass | 5 +++++ tests/sass/no-duplicate-properties.scss | 6 ++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/rules/no-duplicate-properties.js b/lib/rules/no-duplicate-properties.js index ad65f43a..cd02274e 100644 --- a/lib/rules/no-duplicate-properties.js +++ b/lib/rules/no-duplicate-properties.js @@ -27,11 +27,18 @@ module.exports = { declaration.eachFor('property', function (item) { var property = ''; - item.content.forEach(function (subItem) { + + // Check if declaration is actually a variable declaration + if (item.content[0] && item.content[0].is('variable')) { + return; + } + + item.forEach(function (subItem) { // Although not a selector the method here helps us construct the proper property name // taking into account any interpolation etc property += selectorHelpers.constructSelector(subItem); }); + if (properties.indexOf(property) !== -1 && properties.length >= 1) { if (parser.options.exclude.indexOf(property) !== -1 && properties[properties.length - 1] !== property) { warnMessage = 'Excluded duplicate properties must directly follow each other.'; diff --git a/tests/sass/no-duplicate-properties.sass b/tests/sass/no-duplicate-properties.sass index fd4bb85c..20402c25 100644 --- a/tests/sass/no-duplicate-properties.sass +++ b/tests/sass/no-duplicate-properties.sass @@ -40,3 +40,8 @@ $paint-border-2: left border-#{$paint-border-1}: $size solid $color border-#{$paint-border-2}: $size solid $color border-#{$paint-border-2}: $size solid $color + +// issue #935 - ignore variables ++foo + $i: 0 + $i: 1 diff --git a/tests/sass/no-duplicate-properties.scss b/tests/sass/no-duplicate-properties.scss index eb9869c2..8ee2b7c7 100644 --- a/tests/sass/no-duplicate-properties.scss +++ b/tests/sass/no-duplicate-properties.scss @@ -48,3 +48,9 @@ $paint-border-2: left; border-#{$paint-border-2}: $size solid $color; border-#{$paint-border-2}: $size solid $color; } + +// issue #935 - ignore variables +@mixin foo { + $i: 0; + $i: 1; +} From 77449fa3a375f322a1e45916c4b15efe2a59c56b Mon Sep 17 00:00:00 2001 From: Ben Griffith Date: Mon, 7 Nov 2016 14:57:16 +0000 Subject: [PATCH 2/5] :bug: Fix false positives on variable declarations - declarations-before-nesting --- lib/rules/declarations-before-nesting.js | 8 ++++++++ tests/sass/declarations-before-nesting.sass | 7 +++++++ tests/sass/declarations-before-nesting.scss | 9 +++++++++ 3 files changed, 24 insertions(+) diff --git a/lib/rules/declarations-before-nesting.js b/lib/rules/declarations-before-nesting.js index 992cad24..d8eb5be1 100644 --- a/lib/rules/declarations-before-nesting.js +++ b/lib/rules/declarations-before-nesting.js @@ -22,6 +22,14 @@ module.exports = { } if (item.is('declaration')) { + var property = item.content[0]; + + if (property && property.is('property')) { + if (property.content[0] && property.content[0].is('variable')) { + return; + } + } + declarationIndex = j; declaration = item; } diff --git a/tests/sass/declarations-before-nesting.sass b/tests/sass/declarations-before-nesting.sass index 00bbb6a9..5b9b11ec 100644 --- a/tests/sass/declarations-before-nesting.sass +++ b/tests/sass/declarations-before-nesting.sass @@ -25,3 +25,10 @@ content: 'baz' content: 'baz' + +// issue #935 - ignore variables ++foo + #{$bar} + content: 'foobar' + + $baz: 'qux' diff --git a/tests/sass/declarations-before-nesting.scss b/tests/sass/declarations-before-nesting.scss index efb31d67..0251b92a 100644 --- a/tests/sass/declarations-before-nesting.scss +++ b/tests/sass/declarations-before-nesting.scss @@ -33,3 +33,12 @@ content: 'baz'; } + +// issue #935 - ignore variables +@mixin foo { + #{$bar} { + content: 'foobar'; + } + + $baz: 'qux'; +} From 827d6501105107b5adcddc7dc09749622edacdb7 Mon Sep 17 00:00:00 2001 From: Dan Purdy Date: Mon, 7 Nov 2016 14:57:18 +0000 Subject: [PATCH 3/5] :bug: Fix max warnings issues --- bin/sass-lint.js | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/bin/sass-lint.js b/bin/sass-lint.js index a6218b8f..c4ee7b54 100755 --- a/bin/sass-lint.js +++ b/bin/sass-lint.js @@ -6,18 +6,30 @@ var program = require('commander'), lint = require('../index'); var configPath, - configOptions = {}; + config, + configOptions = {}, + exitCode = 0; -var detectPattern = function (pattern) { - var detects; +var tooManyWarnings = function (detects, userConfig) { + var warningCount = lint.warningCount(detects).count; - detects = lint.lintFiles(pattern, configOptions, configPath); + return warningCount > 0 && warningCount > userConfig.options['max-warnings']; +}; + +var detectPattern = function (pattern, userConfig) { + var detects = lint.lintFiles(pattern, configOptions, configPath); if (program.verbose) { lint.outputResults(detects, configOptions, configPath); } - lint.failOnError(detects, configOptions, configPath); + if (lint.errorCount(detects).count || tooManyWarnings(detects, userConfig)) { + exitCode = 1; + } + + if (program.exit) { + lint.failOnError(detects, configOptions, configPath); + } }; program @@ -33,7 +45,6 @@ program .option('--max-warnings [integer]', 'Number of warnings to trigger nonzero exit code') .parse(process.argv); -// Create "options" and "files" dictionaries if they don't exist configOptions.files = configOptions.files || {}; configOptions.options = configOptions.options || {}; @@ -61,11 +72,18 @@ if (program.maxWarnings && program.maxWarnings !== true) { configOptions.options['max-warnings'] = program.maxWarnings; } +// load our config here so we only load it once for each file +config = lint.getConfig(configOptions, configPath); + if (program.args.length === 0) { - detectPattern(null); + detectPattern(null, config); } else { program.args.forEach(function (path) { - detectPattern(path); + detectPattern(path, config); }); } + +process.on('exit', function () { + process.exit(exitCode); // eslint-disable-line no-process-exit +}); From f17473893e37fa990702aefe5ea08b535553dd30 Mon Sep 17 00:00:00 2001 From: Dan Purdy Date: Mon, 7 Nov 2016 15:00:47 +0000 Subject: [PATCH 4/5] :mag: Add warning message to the docs --- docs/options/max-warnings.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/options/max-warnings.md b/docs/options/max-warnings.md index 32d6e8ed..64671686 100644 --- a/docs/options/max-warnings.md +++ b/docs/options/max-warnings.md @@ -2,6 +2,8 @@ An error will be thrown if the total number of warnings exceeds the `max-warnings` setting. +> Please note, if you're using this option with the sass-lint CLI and you're specifying the `--no-exit / -q` option too, you will not see an error but an error code of 1 will still be thrown. + ## Examples This can be set as a command-line option: @@ -26,4 +28,3 @@ var sassLint = require('sass-lint'), results = sassLint.lintFiles('sass/**/*.scss', config) sassLint.failOnError(results, config); ``` - From 65f4a3fbad4d11b02e2634781224fc9925370dea Mon Sep 17 00:00:00 2001 From: Dan Purdy Date: Mon, 7 Nov 2016 15:37:13 +0000 Subject: [PATCH 5/5] prepare 1.10.1 --- CHANGELOG.md | 10 ++++++++++ package.json | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ddd13e9e..c3e87163 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Sass Lint Changelog +## v1.10.1 + +**November 7th, 2016** + +**Fixes** + +* Fixed an issue with the `--no-exit` `-q` flag not being respected and unhandled errors/exceptions being thrown by the CLI +* Fixed an issue with variable declarations showing as properties in the `no-duplicate-properties` rule [#937](https://github.com/sasstools/sass-lint/pull/936) +* Fixed an issue with variable declarations showing as properties in the `declarations-before-nesting` rule [#937](https://github.com/sasstools/sass-lint/pull/936) + ## v1.10.0 **November 6th, 2016** diff --git a/package.json b/package.json index 131bdd60..3c5858eb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sass-lint", - "version": "1.10.0", + "version": "1.10.1", "description": "All Node Sass linter!", "main": "index.js", "scripts": {