Skip to content

Commit

Permalink
Merge branch 'develop' into greenkeeper/remove-node-0.10
Browse files Browse the repository at this point in the history
  • Loading branch information
DanPurdy authored Nov 6, 2016
2 parents 32bc088 + 4cd8a98 commit 775ef96
Show file tree
Hide file tree
Showing 28 changed files with 825 additions and 5 deletions.
8 changes: 6 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,12 @@ rules:
- global
valid-jsdoc:
- 2
- prefer:
return: returns
-
requireParamDescription: true
requireReturnDescription: true
requireReturn: false
prefer:
return: "returns"
wrap-iife: 2
yoda:
- 2
Expand Down
79 changes: 78 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ If you want to configure options, set the rule to an array, where the first item
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
rules:
rules:
indentation:
- 2
-
Expand All @@ -93,6 +93,83 @@ rules:

---

## Disabling Linters via Source

Special comments can be used to disable and enable certain rules throughout your source files in a variety of scenarios. These can be useful when dealing with legacy code or with certain necessary code smells. You can read the documentation for this feature [here](https://github.com/sasstools/sass-lint/tree/master/docs/toggle-rules-in-src.md).

Below are examples of how to use this feature:


### Disable a rule for the entire file

```scss
// sass-lint:disable border-zero
p {
border: none; // No lint reported
}
```

### Disable more than 1 rule

```scss
// sass-lint:disable border-zero, quotes
p {
border: none; // No lint reported
content: "hello"; // No lint reported
}
```

### Disable a rule for a single line

```scss
p {
border: none; // sass-lint:disable-line border-zero
}
```

### Disable all lints within a block (and all contained blocks)

```scss
p {
// sass-lint:disable-block border-zero
border: none; // No result reported
}
a {
border: none; // Failing result reported
}
```

### Disable and enable again

```scss
// sass-lint:disable border-zero
p {
border: none; // No result reported
}
// sass-lint:enable border-zero
a {
border: none; // Failing result reported
}
```

### Disable/enable all linters

```scss
// sass-lint:disable-all
p {
border: none; // No result reported
}
// sass-lint:enable-all
a {
border: none; // Failing result reported
}
```

---

## CLI

Sass Lint [`v1.1.0`](https://github.com/sasstools/sass-lint/releases/tag/v1.1.0) introduced the ability to run Sass Lint through a command line interface. See the [CLI Docs](https://github.com/sasstools/sass-lint/tree/master/docs/cli) for full documentation on how to use the CLI.
Expand Down
71 changes: 71 additions & 0 deletions docs/toggle-rules-in-src.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Toggling Rules Inside Source Files

For special cases where a particular lint doesn't make sense in a specific area of a file, special inline comments can be used to enable/disable linters. Some examples are provided below:

## Disable a rule for the entire file

```scss
// sass-lint:disable border-zero
p {
border: none; // No lint reported
}
```

## Disable more than 1 rule

```scss
// sass-lint:disable border-zero, quotes
p {
border: none; // No lint reported
content: "hello"; // No lint reported
}
```

## Disable a rule for a single line

```scss
p {
border: none; // sass-lint:disable-line border-zero
}
```

## Disable all lints within a block (and all contained blocks)

```scss
p {
// sass-lint:disable-block border-zero
border: none; // No result reported
}

a {
border: none; // Failing result reported
}
```

## Disable and enable again

```scss
// sass-lint:disable border-zero
p {
border: none; // No result reported
}
// sass-lint:enable border-zero

a {
border: none; // Failing result reported
}
```

## Disable/enable all linters

```scss
// sass-lint:disable-all
p {
border: none; // No result reported
}
// sass-lint:enable-all

a {
border: none; // Failing result reported
}
```
14 changes: 12 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ var slConfig = require('./lib/config'),
exceptions = require('./lib/exceptions'),
helpers = require('./lib/helpers'),
slRules = require('./lib/rules'),
ruleToggler = require('./lib/ruleToggler'),
glob = require('glob'),
path = require('path'),
fs = require('fs-extra'),
globule = require('globule');

var getToggledRules = ruleToggler.getToggledRules,
isResultEnabled = ruleToggler.isResultEnabled;

var sassLint = function (config) {
config = require('./lib/config')(config);
return;
Expand Down Expand Up @@ -102,7 +106,9 @@ sassLint.lintText = function (file, options, configPath) {
detects,
results = [],
errors = 0,
warnings = 0;
warnings = 0,
ruleToggles = null,
isEnabledFilter = null;

try {
ast = groot(file.text, file.format, file.filename);
Expand All @@ -121,8 +127,12 @@ sassLint.lintText = function (file, options, configPath) {
}

if (ast.content && ast.content.length > 0) {
ruleToggles = getToggledRules(ast);
isEnabledFilter = isResultEnabled(ruleToggles);

rules.forEach(function (rule) {
detects = rule.rule.detect(ast, rule);
detects = rule.rule.detect(ast, rule)
.filter(isEnabledFilter);
results = results.concat(detects);
if (detects.length) {
if (rule.severity === 1) {
Expand Down
Loading

0 comments on commit 775ef96

Please sign in to comment.