Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a reportDisables secondary option (#4897)
* Rename UnusedRange to DisableReportRange and .unusedRule to .rule This allows us to re-use this structure for representing errors relating to disabled that aren't specifically related to the disable being unused. * Add a reportDisables secondary option This allows config authors to specify that certain rules may not be disabled by authors. Closes #4875 * Produce different messages for different disable-level failures * Code review
- Loading branch information
Showing
26 changed files
with
314 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
lib/__tests__/fixtures/config-block-no-empty-report-disables.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"rules": { | ||
"block-no-empty": [true, { "reportDisables": true }] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/* stylelint-disable block-no-empty */ | ||
a {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
'use strict'; | ||
|
||
const standalone = require('../standalone'); | ||
const stripIndent = require('common-tags').stripIndent; | ||
|
||
describe('reportDisables', () => { | ||
it('reports a disabled comment', () => { | ||
const config = { | ||
rules: { 'block-no-empty': [true, { reportDisables: true }] }, | ||
}; | ||
|
||
const css = stripIndent` | ||
/* stylelint-disable block-no-empty */ | ||
a {} | ||
/* stylelint-enable block-no-empty */ | ||
a { | ||
b {} /* stylelint-disable-line block-no-empty */ | ||
} | ||
`; | ||
|
||
return standalone({ config, code: css }).then((linted) => { | ||
const report = linted.reportedDisables; | ||
|
||
expect(report).toHaveLength(1); | ||
expect(report[0].ranges).toEqual([ | ||
{ start: 1, end: 3, rule: 'block-no-empty', unusedRule: 'block-no-empty' }, | ||
{ start: 5, end: 5, rule: 'block-no-empty', unusedRule: 'block-no-empty' }, | ||
]); | ||
|
||
// Although these disables are reported as issues, they're still in effect | ||
// so the underlying lint issues are not reported. | ||
expect(linted.results[0].warnings).toHaveLength(0); | ||
}); | ||
}); | ||
|
||
it('reports an ignored disabled comment', () => { | ||
const config = { | ||
rules: { 'block-no-empty': [true, { reportDisables: true }] }, | ||
}; | ||
|
||
const css = stripIndent` | ||
/* stylelint-disable block-no-empty */ | ||
a {} | ||
/* stylelint-enable block-no-empty */ | ||
a { | ||
b {} /* stylelint-disable-line block-no-empty */ | ||
} | ||
`; | ||
|
||
return standalone({ | ||
config, | ||
code: css, | ||
ignoreDisables: true, | ||
}).then((linted) => { | ||
const report = linted.reportedDisables; | ||
|
||
expect(report).toHaveLength(1); | ||
expect(report[0].ranges).toEqual([ | ||
{ start: 1, end: 3, rule: 'block-no-empty', unusedRule: 'block-no-empty' }, | ||
{ start: 5, end: 5, rule: 'block-no-empty', unusedRule: 'block-no-empty' }, | ||
]); | ||
|
||
expect(linted.results[0].warnings).toHaveLength(2); | ||
}); | ||
}); | ||
|
||
it("doesn't report disables by default", () => { | ||
const config = { | ||
rules: { 'block-no-empty': [true] }, | ||
}; | ||
|
||
const css = stripIndent` | ||
/* stylelint-disable block-no-empty */ | ||
a {} | ||
/* stylelint-enable block-no-empty */ | ||
a { | ||
b {} /* stylelint-disable-line block-no-empty */ | ||
} | ||
`; | ||
|
||
return standalone({ config, code: css }).then((linted) => { | ||
const report = linted.reportedDisables; | ||
|
||
expect(report).toHaveLength(0); | ||
}); | ||
}); | ||
|
||
// This should be handled by the global `reportUnscopedDisables` option (#2292). | ||
it("doesn't report unscoped disables", () => { | ||
const config = { | ||
rules: { 'block-no-empty': [true, { reportDisables: true }] }, | ||
}; | ||
|
||
const css = stripIndent` | ||
a {} /* stylelint-disable-line */ | ||
`; | ||
|
||
return standalone({ config, code: css }).then((linted) => { | ||
const report = linted.reportedDisables; | ||
|
||
expect(report).toHaveLength(1); | ||
expect(report[0].ranges).toHaveLength(0); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.