Skip to content

Commit

Permalink
Merge branch 'develop' into feature/fix-shorthand-values
Browse files Browse the repository at this point in the history
  • Loading branch information
bgriffith committed Oct 26, 2016
2 parents 0a0277a + d31e7e5 commit c1aa039
Show file tree
Hide file tree
Showing 25 changed files with 289 additions and 100 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ node_js:
- '5'
- node
- iojs
before_script: npm link
after_success: npm run coveralls
notifications:
slack:
Expand Down
29 changes: 24 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,14 @@ For all [rules](https://github.com/sasstools/sass-lint/tree/master/docs/rules),

If you want to configure options, set the rule to an array, where the first item in the array is the severity, and the second item in the array is an object including the options you would like to set.

An example configuration of a rule with options look like the following:
Here is an example configuration of a rule, where we are specifying that breaking the [indentation rule](https://github.com/sasstools/sass-lint/blob/master/docs/rules/indentation.md) should be treated as an error (its severity set to two), and setting the `size` option of the rule to 2 spaces:

```yml
indentation:
- 2
-
size: 2
rules:
indentation:
- 2
-
size: 2
```

### [Rules Documentation](https://github.com/sasstools/sass-lint/tree/master/docs/rules)
Expand Down Expand Up @@ -169,6 +170,24 @@ For further information you can visit our CLI documentation linked below.

---

## Front matter

Certain static site generators such as [Jekyll](http://jekyllrb.com/docs/frontmatter/) include the YAML front matter block at the top of their scss file. Sass-lint by default checks a file for this block and attempts to parse your Sass without this front matter. You can see an example of a front matter block below.

```scss

---
# Only the main Sass file needs front matter (the dashes are enough)
---

.test {
color: red;
}

```

---

## Contributions

We welcome all contributions to this project but please do read our [contribution guidelines](https://github.com/sasstools/sass-lint/blob/master/CONTRIBUTING.md) first, especially before opening a pull request. It would also be good to read our [code of conduct](https://github.com/sasstools/sass-lint/blob/master/CODE_OF_CONDUCT.md).
Expand Down
2 changes: 0 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ install:
- ps: Install-Product node $env:nodejs_version
# install modules
- npm install
# link
- npm link

# Post-install test scripts.
test_script:
Expand Down
57 changes: 12 additions & 45 deletions bin/sass-lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,7 @@ var program = require('commander'),
lint = require('../index');

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

var tooManyWarnings = function (detects) {
var warningCount = lint.warningCount(detects).count;

return warningCount > 0 && warningCount > program.maxWarnings;
};
configOptions = {};

var detectPattern = function (pattern) {
var detects;
Expand All @@ -25,13 +17,7 @@ var detectPattern = function (pattern) {
lint.outputResults(detects, configOptions, configPath);
}

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

if (program.exit) {
lint.failOnError(detects);
}
lint.failOnError(detects, configOptions, configPath);
};

program
Expand All @@ -47,47 +33,32 @@ 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 || {};

if (program.config && program.config !== true) {
configPath = program.config;
}

if (program.ignore && program.ignore !== true) {
ignores = program.ignore.split(', ');
if (configOptions.hasOwnProperty('files')) {
configOptions.files.ignore = ignores;
}
else {
configOptions.files = {
'ignore': ignores
};
}
configOptions.files.ignore = program.ignore.split(', ');
}

if (program.syntax && ['sass', 'scss'].indexOf(program.syntax) > -1) {
configOptions.syntax = program.syntax;
}

if (program.format && program.format !== true) {
if (configOptions.hasOwnProperty('options')) {
configOptions.options.formatter = program.format;
}
else {
configOptions.options = {
'formatter': program.format
};
}
configOptions.options.formatter = program.format;
}

if (program.output && program.output !== true) {
if (configOptions.hasOwnProperty('options')) {
configOptions.options['output-file'] = program.output;
}
else {
configOptions.options = {
'output-file': program.output
};
}
configOptions.options['output-file'] = program.output;
}

if (program.maxWarnings && program.maxWarnings !== true) {
configOptions.options['max-warnings'] = program.maxWarnings;
}

if (program.args.length === 0) {
Expand All @@ -98,7 +69,3 @@ else {
detectPattern(path);
});
}

process.on('exit', function () {
process.exit(exitCode); // eslint-disable-line no-process-exit
});
29 changes: 29 additions & 0 deletions docs/options/max-warnings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Max warnings

An error will be thrown if the total number of warnings exceeds the `max-warnings` setting.

## Examples

This can be set as a command-line option:

``` bash
$ sass-lint --max-warnings 50
```

In `.sass-lint.yml`:

``` yaml
options:
max-warnings: 50
```

Or inside a script:

``` javascript
var sassLint = require('sass-lint'),
config = {options: {'max-warnings': 50}};

results = sassLint.lintFiles('sass/**/*.scss', config)
sassLint.failOnError(results, config);
```

2 changes: 2 additions & 0 deletions docs/sass-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ options:
formatter: html
# Output file instead of logging results
output-file: 'linters/sass-lint.html'
# Raise an error if more than 50 warnings are generated
max-warnings: 50
# File Options
files:
include: 'sass/**/*.s+(a|c)ss'
Expand Down
25 changes: 21 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var slConfig = require('./lib/config'),
groot = require('./lib/groot'),
exceptions = require('./lib/exceptions'),
helpers = require('./lib/helpers'),
slRules = require('./lib/rules'),
glob = require('glob'),
Expand Down Expand Up @@ -284,14 +285,30 @@ sassLint.outputResults = function (results, options, configPath) {
* 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
* @param {object} results - our results object
* @param {object} [options] - extra options to use when running failOnError, e.g. max-warnings
* @param {string} [configPath] - path to the config file
* @returns {void}
*/
sassLint.failOnError = function (results) {
var errorCount = this.errorCount(results);
sassLint.failOnError = function (results, options, configPath) {
// Default parameters
options = typeof options !== 'undefined' ? options : {};
configPath = typeof configPath !== 'undefined' ? configPath : null;

var errorCount = this.errorCount(results),
warningCount = this.warningCount(results),
configOptions = this.getConfig(options, configPath).options;

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

if (!isNaN(configOptions['max-warnings']) && warningCount.count > configOptions['max-warnings']) {
throw new exceptions.MaxWarningsExceededError(
'Number of warnings (' + warningCount.count +
') exceeds the allowed maximum of ' + configOptions['max-warnings'] +
'.\n'
);
}
};

Expand Down
19 changes: 19 additions & 0 deletions lib/exceptions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';

var util = require('util');

module.exports = {
SassLintFailureError: function (message) {
Error.captureStackTrace(this, this.constructor);
this.name = 'SassLintFailureError';
this.message = message;
},
MaxWarningsExceededError: function (message) {
Error.captureStackTrace(this, this.constructor);
this.name = 'MaxWarningsExceededError';
this.message = message;
}
};

util.inherits(module.exports.SassLintFailureError, Error);
util.inherits(module.exports.MaxWarningsExceededError, Error);
8 changes: 7 additions & 1 deletion lib/groot.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@
//////////////////////////////
'use strict';

var gonzales = require('gonzales-pe');
var gonzales = require('gonzales-pe'),
fm = require('front-matter');

module.exports = function (text, syntax, filename) {
var tree;

// Run `.toString()` to allow Buffers to be passed in
text = text.toString();

// if we're skipping front matter do it here, fall back to just our text in case it fails
if (fm.test(text)) {
text = fm(text).body || text;
}

try {
tree = gonzales.parse(text, {
'syntax': syntax
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/space-before-colon.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = {
if (delimiter.content === ':') {
var previous = parent.content[i - 1];

if (previous.is('space')) {
if (previous && previous.is('space')) {
if (!parser.options.include) {
result = helpers.addUnique(result, {
'ruleId': parser.rule.name,
Expand Down
1 change: 1 addition & 0 deletions lib/rules/variable-name-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module.exports = {
violationMessage = false,
name = variable.first().content;


strippedName = name;

if (parser.options['allow-leading-underscore'] && name[0] === '_') {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@
"dependencies": {
"commander": "^2.8.1",
"eslint": "^2.7.0",
"front-matter": "2.1.0",
"fs-extra": "^0.30.0",
"glob": "^7.0.0",
"globule": "^1.0.0",
"gonzales-pe": "3.4.4",
"gonzales-pe": "3.4.7",
"js-yaml": "^3.5.4",
"lodash.capitalize": "^4.1.0",
"lodash.kebabcase": "^4.0.0",
Expand Down
Loading

0 comments on commit c1aa039

Please sign in to comment.