Skip to content

Commit

Permalink
feat(lint): adds disable-next-line
Browse files Browse the repository at this point in the history
Add disable-next-line
  • Loading branch information
srowhani authored Apr 25, 2019
2 parents e391436 + 19df7ba commit b508036
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 1 deletion.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ 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.

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:
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:
Expand Down Expand Up @@ -127,6 +127,15 @@ p {
}
```

### Disable a rule for text next line

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

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

```scss
Expand Down
9 changes: 9 additions & 0 deletions docs/toggle-rules-in-src.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ p {
}
```

## Disable a rule for the next line

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

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

```scss
Expand Down
3 changes: 3 additions & 0 deletions lib/ruleToggler.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ module.exports.getToggledRules = function (ast) {
case 'sass-lint:disable-line':
addDisableLine(toggledRules, rules, comment.start.line);
break;
case 'sass-lint:disable-next-line':
addDisableLine(toggledRules, rules, comment.start.line + 1);
break;
default:
return;
}
Expand Down
9 changes: 9 additions & 0 deletions tests/ruleToggler.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ describe('rule toggling', function () {
}
}) === true);
});
it('should be able to disable next line', function () {
var ruleToggles = generateToggledRules('ruleToggler-disable-next-line.scss');
assert(deepEqual(ruleToggles, {
globalEnable: [],
ruleEnable: {
a: [[false, 3, 1], [true, 4, 1]]
}
}) === true);
});
it('should be able to disable a block of code', function () {
var ruleToggles = generateToggledRules('ruleToggler-disable-a-block.scss');
assert(deepEqual(ruleToggles, {
Expand Down
3 changes: 3 additions & 0 deletions tests/sass/ruleToggler-disable-next-line.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
p
// sass-lint:disable-next-line a
border-color: red
4 changes: 4 additions & 0 deletions tests/sass/ruleToggler-disable-next-line.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
p {
// sass-lint:disable-next-line a
border-color: red;
}

0 comments on commit b508036

Please sign in to comment.