Skip to content
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

Disable linters #677

Merged
merged 16 commits into from
Nov 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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