Skip to content

Commit

Permalink
Merge branch 'develop' into feature/disable-linters
Browse files Browse the repository at this point in the history
  • Loading branch information
DanPurdy committed Oct 20, 2016
2 parents 68c8a23 + a66c707 commit c789132
Show file tree
Hide file tree
Showing 34 changed files with 609 additions and 128 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
# Sass Lint Changelog

## v1.9.1

**August 25, 2016**

**Fixes**
* Fixed an issue with nth selectors in the `no-mergeable-selectors` rule [#834](https://github.com/sasstools/sass-lint/issues/834)
* Fixed an issue with atrule arguments containing functions in the `no-mergeable-selectors` rule [#826](https://github.com/sasstools/sass-lint/issues/826)
* Fixed an issue with hex colors being ignored in the `shorthand-values` rule [#836](https://github.com/sasstools/sass-lint/pull/836)

## v1.9.0

**August 18, 2016**

**Fixes**
* Fixed an issue with teh indentation rule when it encountered at-rules with no block immediately preceeding a map [#779](https://github.com/sasstools/sass-lint/issues/779) [#783](https://github.com/sasstools/sass-lint/issues/783)
* Fixed an issue with the indentation rule when it encountered at-rules with no block immediately preceding a map [#779](https://github.com/sasstools/sass-lint/issues/779) [#783](https://github.com/sasstools/sass-lint/issues/783)
* Fixed an issue in `single-lint-per-selector` where inline comments were seen as selectors [#789](https://github.com/sasstools/sass-lint/issues/789)
* Fixed an issue with interpolation in placeholders within the `bem-depth` rule [#782](https://github.com/sasstools/sass-lint/issues/782)
* Removed duplicated code from `no-mergeable-selectors` to helper methods
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);
```

37 changes: 37 additions & 0 deletions docs/rules/no-url-domains.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# No Url Domains

Rule `no-url-domains` will enforce that domains are not used within urls.

## Examples

When enabled, the following are allowed:

```scss
.foo {
background-image: url('/img/bar.png');
}

.foo {
background-image: url('img/bar.png');
}

.foo {
background-image: url('bar.png');
}
```

When enabled, the following are disallowed:

```scss
.foo {
background-image: url('https://foo.com/img/bar.png');
}

.foo {
background-image: url('http://foo.com/img/bar.png');
}

.foo {
background-image: url('//foo.com/img/bar.png');
}
```
44 changes: 42 additions & 2 deletions docs/rules/no-url-protocols.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@

Rule `no-url-protocols` will enforce that protocols and domains are not used within urls.

## Options

* `allow-protocol-relative-urls`: `true`/`false` (defaults to `false`)
> This option is scheduled to be deprecated in favour of the [no-url-domains](https://github.com/sasstools/sass-lint/blob/develop/docs/rules/no-url-domains.md) rule in sass-lint 2.0.
## Examples

When enabled, the following are allowed:
### `allow-protocol-relative-urls`


When `allow-protocol-relative-urls: false`, the following are allowed:

```scss
.foo {
Expand All @@ -20,7 +28,7 @@ When enabled, the following are allowed:
}
```

When enabled, the following are disallowed:
When `allow-protocol-relative-urls: false`, the following are disallowed:

```scss
.foo {
Expand All @@ -35,3 +43,35 @@ When enabled, the following are disallowed:
background-image: url('//foo.com/img/bar.png');
}
```

When `allow-protocol-relative-urls: true`, the following are allowed:

```scss
.foo {
background-image: url('//foo.com/img/bar.png');
}

.foo {
background-image: url('/img/bar.png');
}

.foo {
background-image: url('img/bar.png');
}

.foo {
background-image: url('bar.png');
}
```

When `allow-protocol-relative-urls: true`, the following are disallowed:

```scss
.foo {
background-image: url('https://foo.com/img/bar.png');
}

.foo {
background-image: url('http://foo.com/img/bar.png');
}
```
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'),
ruleToggler = require('./lib/ruleToggler'),
Expand Down Expand Up @@ -294,14 +295,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
1 change: 1 addition & 0 deletions lib/config/sass-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ rules:
no-trailing-zero: 1
no-transition-all: 1
no-universal-selectors: 0
no-url-domains: 1
no-url-protocols: 1
no-vendor-prefixes: 1
no-warn: 1
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);
33 changes: 33 additions & 0 deletions lib/rules/no-url-domains.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict';

var helpers = require('../helpers'),
url = require('url');

module.exports = {
'name': 'no-url-domains',
'defaults': {},
'detect': function (ast, parser) {
var result = [];

ast.traverseByType('uri', function (uri) {
uri.traverse(function (item) {
if (item.is('string')) {
var stripped = helpers.stripQuotes(item.content),
parsedUrl = url.parse(stripped, false, true);

if (parsedUrl.host && parsedUrl.protocol !== 'data:') {
result = helpers.addUnique(result, {
'ruleId': parser.rule.name,
'severity': parser.severity,
'line': item.end.line,
'column': item.end.column,
'message': 'Domains in URLs are disallowed'
});
}
}
});
});

return result;
}
};
Loading

0 comments on commit c789132

Please sign in to comment.