8000 Release/1.5.0 by DanPurdy · Pull Request #491 · sasstools/sass-lint · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Release/1.5.0 #491

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 41 commits into from
Jan 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
5113675
Add failing test cases for item.first('atkeyword') TypeError
dotdat Nov 6, 2015
6d1fc27
Provide fix for item.first('atkeyword') TypeError
dotdat Nov 6, 2015
bba96e1
Merge pull request #449 from sasstools/release/1.4.0
DanPurdy Dec 10, 2015
64b1f16
Add missing contributor
DanPurdy Dec 10, 2015
56d0436
Merge pull request #450 from DanPurdy/feature/missing-changelog-contr…
benthemonkey Dec 14, 2015
7a722f6
:art: comment sassLint functions format failOnError
DanPurdy Dec 20, 2015
6ac47f3
:art: add correct exit code for cli
DanPurdy Dec 20, 2015
11b496b
:white_check_mark: add cli and main function tests
DanPurdy Dec 20, 2015
e2e78eb
:bug: Fix node 0.10 issue with exit codes
DanPurdy Dec 21, 2015
7b5c0ee
:art: Set severity and options at top of function
bquorning Dec 2, 2015
9635ded
:racehorse: Return parse errors as lint errors
DanPurdy Dec 21, 2015
aa4d36f
:white_check_mark: ClI tests for parse errors
DanPurdy Dec 21, 2015
3438132
:white_check_mark: Test parse error lint errors
DanPurdy Dec 21, 2015
ca32ff3
Merge pull request #436 from bquorning/set-severity-and-options-varia…
DanPurdy Dec 21, 2015
f315c98
Merge branch 'develop' into feature/parse-errors
DanPurdy Dec 21, 2015
2a15719
Merge branch 'develop' into feature/error-codes
DanPurdy Dec 21, 2015
beb391b
Merge branch 'develop' into fix-include-atkeyword-undefined
Dec 28, 2015
4609d8e
Apply editorconfig rules
Dec 28, 2015
3ab3b84
Merge pull request #422 from dotdat/fix-include-atkeyword-undefined
DanPurdy Dec 28, 2015
8000
d7d4cf0
Merge branch 'develop' into feature/parse-errors
DanPurdy Dec 28, 2015
8d1000b
If next if undefined - Fix for #468
mi2oon Jan 6, 2016
b8388a3
:memo: Add Brackets integration to the IDE Integration list
petetnt Jan 6, 2016
b7caa57
Merge pull request #471 from petetnt/patch-2
DanPurdy Jan 6, 2016
cea03d8
Merge branch 'develop' into patch-1
mi2oon Jan 7, 2016
fc3fc3b
Merge pull request #469 from mi2oon/patch-1
DanPurdy Jan 7, 2016
950cdce
Merge branch 'develop' into feature/parse-errors
DanPurdy Jan 7, 2016
ea57289
Merge pull request #459 from DanPurdy/feature/parse-errors
bgriffith Jan 20, 2016
0703962
:bug: Fix issue with negative z-index and space-around-operator
Jan 25, 2016
6893d0f
Merge pull request #482 from bgriffith/feature/ignore-negative-index
DanPurdy Jan 25, 2016
fda8715
Merge branch 'develop' of github.com:sasstools/sass-lint into feature…
DanPurdy Jan 25, 2016
cde7b33
Update README.md
Jan 26, 2016
bfe3ec0
Merge pull request #1 from idok/idok-patch-1
Jan 26, 2016
89e9d1a
Merge pull request #485 from idok/develop
DanPurdy Jan 28, 2016
076c622
Merge branch 'develop' into feature/error-codes
DanPurdy Jan 28, 2016
42a1fdc
Merge pull request #458 from DanPurdy/feature/error-codes
bgriffith Jan 28, 2016
062e410
:bug: Fix issue with leading negatives and space around operator rule
Jan 28, 2016
e2a6775
:bug: Fix issue with leading negatives and space around operator rule
Jan 28, 2016
199123b
Merge branch 'feature/fix-leading-negatives-take-2' of github.com:bgr…
Jan 28, 2016
b1ebf3b
Add extra check for existance of prev/next objects
Jan 28, 2016
0156215
Merge pull request #490 from bgriffith/feature/fix-leading-negatives-…
DanPurdy Jan 28, 2016
aad6be6
:shipit: Prepare 1.5.0 release
DanPurdy Jan 28, 2016
File filter

Filter by extension

Filter by extension


Conversations
8000 Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions CHANGELOG.md
8000
Original file line number Diff line numberDiff line change
@@ -1,5 +1,24 @@
# Sass Lint Changelog

## v1.5.0
**January 28, 2016**

New year blues

**Changes**
* AST parse errors will now be returned to the user as `Fatal` lint errors this prevents un-handled errors breaking builds [#459](https://github.com/sasstools/sass-lint/pull/459)
* Sass-lint plugin for Brackets added to the README [#470](https://github.com/sasstools/sass-lint/issues/470)
* Sass-lint plugin for IntelliJ IDEA, RubyMine, WebStorm, PhpStorm, PyCharm, added to the README [#484](https://github.com/sasstools/sass-lint/issues/484)


**CLI**
* Updated error codes, whenever errors are present even when cli is using the `--no-exit` flag a error code of 1 will be output [#221](https://github.com/sasstools/sass-lint/issues/221)

**Fixes**
* Fixed an issue where an error of `next is undefined` would be thrown in the `space-after-colon` rule [#468](https://github.com/sasstools/sass-lint/issues/468)
* Fixed an issue with negative z-index values in the `space-around-operator` rule [#454](https://github.com/sasstools/sass-lint/issues/454)
* Fixed another minor issue with `space-around-operator` to prevent a possible crash [#483](https://github.com/sasstools/sass-lint/issues/483)

## v1.4.0
**December 10, 2015**

Expand Down Expand Up @@ -39,6 +58,7 @@ The long overdue update!
* [Dan Purdy](https://github.com/DanPurdy)
* [Ben Rothman](https://github.com/benthemonkey)
* [Don Abrams](https://github.com/donabrams)
* [Andrew Hays](https://github.com/Dru89)
* [Kaelig](https://github.com/kaelig)

**A big thankyou to everyone who reported issues or contributed to the discussion around issues**
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,5 @@ Our AST is [Gonzales-PE](https://github.com/tonyganch/gonzales-pe/tree/dev). Eac

* [Atom](https://atom.io/packages/linter-sass-lint)
* [Sublime Text](https://github.com/skovhus/SublimeLinter-contrib-sass-lint)
* [Brackets](https://github.com/petetnt/brackets-sass-lint)
* [IntelliJ IDEA, RubyMine, WebStorm, PhpStorm, PyCharm](https://github.com/idok/sass-lint-plugin)
11 changes: 10 additions & 1 deletion bin/sass-lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ var program = require('commander'),

var configPath,
ignores,
configOptions = {};
configOptions = {},
exitCode = 0;

var detectPattern = function (pattern) {
var detects;
Expand All @@ -18,6 +19,10 @@ var detectPattern = function (pattern) {
lint.outputResults(detects, configOptions, configPath);
}

if (lint.errorCount(detects).count) {
exitCode = 1;
}

if (program.exit) {
lint.failOnError(detects);
}
Expand Down Expand Up @@ -86,3 +91,7 @@ else {
detectPattern(path);
});
}

process.on('exit', function () {
process.exit(exitCode); // eslint-disable-line no-process-exit
});
148 changes: 127 additions & 21 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,119 @@ var slConfig = require('./lib/config'),
slRules = require('./lib/rules'),< 5D32 /td>
glob = require('glob'),
path = require('path'),
jsonFormatter = require('eslint/lib/formatters/json'),
fs = require('fs-extra');


var sassLint = function (config) {
config = require('./lib/config')(config);
return;
};

/**
* Takes any user specified options and a configPath
* which returns a compiled config object
*
* @param {object} config user specified rules/options passed in
* @param {string} configPath path to a config file
* @returns {object} the compiled config object
*/
sassLint.getConfig = function (config, configPath) {
return slConfig(config, configPath);
};

sassLint.resultCount = function (results) {
var flagCount = 0,
jsonResults = JSON.parse(jsonFormatter(results));
/**
* Parses our results object to count errors and return
* paths to files with detected errors.
*
* @param {object} results our results object
* @returns {object} errors object containing the error count and paths for files incl. errors
*/
sassLint.errorCount = function (results) {
var errors = {
count: 0,
files: []
};

results.forEach(function (result) {
if (result.errorCount) {
errors.count += result.errorCount;
errors.files.push(result.filePath);
}
});

for (var i = 0; i < jsonResults.length; i++) {
flagCount += (jsonResults[i].warningCount + jsonResults[i].errorCount);
}
return errors;
};

/**
* Parses our results object to count warnings and return
* paths to files with detected warnings.
*
* @param {object} results our results object
* @returns {object} warnings object containing the error count and paths for files incl. warnings
*/
sassLint.warningCount = function (results) {
var warnings = {
count: 0,
files: []
};

results.forEach(function (result) {
if (result.warningCount) {
warnings.count += result.warningCount;
warnings.files.push(result.filePath);
}
});

return flagCount;
return warnings;
};

/**
* Parses our results object to count warnings and errors and return
* a cumulative count of both
*
* @param {object} results our results object
* @returns {int} the cumulative count of errors and warnings detected
*/
sassLint.resultCount = function (results) {
var warnings = this.warningCount(results),
errors = this.errorCount(results);

return warnings.count + errors.count;
};

/**
* Runs each rule against our AST tree and returns our main object of detected
* errors, warnings, messages and filenames.
*
* @param {object} file file object from fs.readFileSync
* @param {object} options user specified rules/options passed in
* @param {string} configPath path to a config file
* @returns {object} an object containing error & warning counts plus lint messages for each parsed file
*/
sassLint.lintText = function (file, options, configPath) {
var rules = slRules(this.getConfig(options, configPath)),
ast = groot(file.text, file.format, file.filename),
ast = {},
detects,
results = [],
errors = 0,
warnings = 0;

if (ast.content.length > 0) {
try {
ast = groot(file.text, file.format, file.filename);
}
catch (e) {
var line = e.line || 1;
errors++;

results = [{
ruleId: 'Fatal',
line: line,
column: 1,
message: e.message,
severity: 2
}];
}

if (ast.content && ast.content.length > 0) {
rules.forEach(function (rule) {
detects = rule.rule.detect(ast, rule);
results = results.concat(detects);
Expand All @@ -54,7 +133,6 @@ sassLint.lintText = function (file, options, configPath) {
});
}


results.sort(helpers.sortDetects);

return {
Expand All @@ -65,6 +143,16 @@ sassLint.lintText = function (file, options, configPath) {
};
};

/**
* Takes a glob pattern or target string and creates an array of files as targets for
* linting taking into account any user specified ignores. For each resulting file sassLint.lintText
* is called which returns an object of results for that file which we push to our results object.
*
* @param {string} files a glob pattern or single file path as a lint target
* @param {object} options user specified rules/options passed in
* @param {string} configPath path to a config file
* @returns {object} results object containing all results
*/
sassLint.lintFiles = function (files, options, configPath) {
var that = this,
results = [],
Expand Down Expand Up @@ -99,7 +187,14 @@ sassLint.lintFiles = function (files, options, configPath) {
return results;
};


/**
* Handles formatting of results using EsLint formatters
*
* @param {object} results our results object
* @param {object} options user specified rules/options passed in
* @param {string} configPath path to a config file
* @returns {object} results our results object in the user specified format
*/
sassLint.format = function (results, options, configPath) {
var config = this.getConfig(options, configPath),
format = config.options.formatter.toLowerCase();
Expand All @@ -109,6 +204,15 @@ sassLint.format = function (results, options, configPath) {
return formatted(results);
};

/**
* Handles outputting results whether this be straight to the console/stdout or to a file.
* Passes results to the format function to ensure results are output in the chosen format
*
* @param {object} results our results object
* @param {object} options user specified rules/options passed in
* @param {string} configPath path to a config file
* @returns {object} results our results object
*/
sassLint.outputResults = function (results, options, configPath) {
var config = this.getConfig(options, configPath);

Expand All @@ -132,16 +236,18 @@ sassLint.outputResults = function (results, options, configPath) {
return results;
};

/**
* Throws an error if there are any errors detected. The error includes a count of all errors
* and a list of all files that include errors.
*
* @param {object} results our results object
* @returns {void}
*/
sassLint.failOnError = function (results) {
var result,
i;
var errorCount = this.errorCount(results);

for (i = 0; i < results.length; i++) {
result = results[i];

if (result.errorCount > 0) {
throw new Error(result.errorCount + ' errors detected in ' + result.filePath);
}
if (errorCount.count > 0) {
throw new Error(errorCount.count + ' errors were detected in \n- ' + errorCount.files.join('\n- '));
}
};

Expand Down
16 changes: 12 additions & 4 deletions lib/groot.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
var gonzales = require('gonzales-pe');

module.exports = function (text, syntax, filename) {
var fileInfo = filename ? ' at ' + filename : '',
tree;
var tree;

// Run `.toString()` to allow Buffers to be passed in
text = text.toString();
Expand All @@ -18,11 +17,20 @@ module.exports = function (text, syntax, filename) {
});
}
catch (e) {
throw new Error('Parsing error' + fileInfo + ': ' + e.message);
throw {
message: e.message,
file: filename,
line: e.line
};
}

if (typeof tree === 'undefined') {
throw new Error('Undefined tree' + fileInfo + ': ' + text.toString() + ' => ' + tree.toString());
throw {
message: 'Undefined tree',
file: filename,
text: text.toString(),
tree: tree.toString()
};
}

return tree;
Expand Down
17 changes: 13 additions & 4 deletions lib/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,30 @@ module.exports = function (config) {
Object.keys(config.rules).forEach(function (rule) {
var fullRule = config.rules[rule],
loadRule,
severity,
options,
ruleSearch;

if (typeof fullRule === 'number') {
severity = fullRule;
options = {};
}
else {
severity = fullRule[0];
options = fullRule[1];
}

// Only seek out rules that are enabled
if ((typeof fullRule === 'number' && fullRule !== 0) || (typeof fullRule === 'object' && fullRule[0] !== 0)) {
if (severity !== 0) {
ruleSearch = searchArray(rules, rule);
if (ruleSearch >= 0) {
loadRule = require(rules[ruleSearch]);

options = typeof fullRule === 'object' ? fullRule[1] : {};

options = merge.recursive(true, loadRule.defaults, options);

handlers.push({
'rule': loadRule,
'severity': typeof fullRule === 'number' ? fullRule : fullRule[0],
'severity': severity,
'options': options
});
}
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/extends-before-declarations.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ module.exports = {
var lastDeclaration = null;

block.forEach(function (item, j) {
if (item.type === 'include' || item.type === 'extend') {
if ((item.type === 'include' || item.type === 'extend') &&
item.first('atkeyword')) {
if (item.first('atkeyword').first('ident').content === 'extend') {
if (j > lastDeclaration && lastDeclaration !== null) {
item.forEach('simpleSelector', function () {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/space-after-colon.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = {
if (delimiter.content === ':') {
var next = parent.content[i + 1];

if (next.is('space')) {
if (next && next.is('space')) {
if (!parser.options.include) {
result = helpers.addUnique(result, {
'ruleId': parser.rule.name,
Expand Down
Loading
0