Skip to content

Commit

Permalink
Merge branch 'develop' into feature/declarations-before-nesting
Browse files Browse the repository at this point in the history
  • Loading branch information
onishiweb committed Sep 6, 2016
2 parents 9a7b528 + b7bcb3a commit 9d671c4
Show file tree
Hide file tree
Showing 49 changed files with 1,185 additions and 236 deletions.
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
# 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 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

**Documentation**
* Fixed typos in no-vendor-prefixes rule documentation [#787](https://github.com/sasstools/sass-lint/issues/787)
* Added link to Visual Studio extension [#815](https://github.com/sasstools/sass-lint/pull/815)

**New Rules**
* Added the `no-color-hex` rule to disallow all hexadecimal colour definitions [#754](https://github.com/sasstools/sass-lint/issues/754)

**Updates**
* Gonzales-pe updated to version 3.4.4 which fixes a lot of longstanding issues see the [Changelog](https://github.com/tonyganch/gonzales-pe/blob/dev/CHANGELOG.md)

## v1.8.2

**June 23, 2016**
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,5 @@ Our AST is [Gonzales-PE](https://github.com/tonyganch/gonzales-pe/tree/dev). Eac
* [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)
* [Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=glen-84.sass-lint)
* [Vim](https://github.com/gcorne/vim-sass-lint)
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);
```

33 changes: 33 additions & 0 deletions docs/rules/no-color-hex.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# No Color Hex

Rule `no-color-hex` will disallow the use of hexadecimal colors

## Examples

When enabled the following are disallowed.

```scss
$foo-color: #456;

.bar {
background: linear-gradient(top, #3ff, #ddd);
}

.baz {
color: #fff;
}
```

When enabled the following are allowed:

```scss
$foo-color: red;

.bar {
background: linear-gradient(top, blue, green);
}

.baz {
color: white;
}
```
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'),
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
2 changes: 2 additions & 0 deletions lib/config/sass-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ rules:

# Disallows
no-attribute-selectors: 0
no-color-hex: 0
no-color-keywords: 1
no-color-literals: 1
no-combinators: 0
Expand All @@ -37,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);
Loading

0 comments on commit 9d671c4

Please sign in to comment.