-
-
Notifications
You must be signed in to change notification settings - Fork 946
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
438 additions
and
66 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"stylelint": minor | ||
--- | ||
|
||
Added: `--report-unscoped-disables` CLI flag and `reportUnscopedDisables` option to Node.js API and configuration object |
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
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,200 @@ | ||
import standalone from '../standalone.mjs'; | ||
import { stripIndent } from 'common-tags'; | ||
|
||
it('does report unscoped configuration comments even when they are needless', async () => { | ||
const config = { | ||
rules: { 'block-no-empty': true }, | ||
}; | ||
|
||
const css = stripIndent`/* stylelint-disable-next-line */ | ||
a { color: red; }`; | ||
|
||
const { results } = await standalone({ | ||
config, | ||
code: css, | ||
reportUnscopedDisables: [true], | ||
}); | ||
|
||
expect(results[0].warnings).toHaveLength(1); | ||
expect(unscopedWarnings(results[0])).toEqual([ | ||
{ | ||
line: 1, | ||
column: 1, | ||
endLine: 1, | ||
endColumn: 33, | ||
rule: '--report-unscoped-disables', | ||
severity: 'error', | ||
text: 'Configuration comment must be scoped', | ||
}, | ||
]); | ||
}); | ||
|
||
it('unscopedDisables true', async () => { | ||
const config = { | ||
rules: { | ||
'selector-type-case': 'lower', | ||
}, | ||
}; | ||
|
||
const css = stripIndent` | ||
/* stylelint-disable */ | ||
a {} | ||
/* stylelint-enable */ | ||
a {} /* stylelint-disable-line */ | ||
/* stylelint-disable-next-line */ | ||
a {} | ||
`; | ||
|
||
const { results } = await standalone({ | ||
config, | ||
code: css, | ||
reportUnscopedDisables: [true], | ||
}); | ||
|
||
const common = { | ||
rule: '--report-unscoped-disables', | ||
severity: 'error', | ||
text: 'Configuration comment must be scoped', | ||
}; | ||
|
||
expect(results[0].warnings).toHaveLength(3); | ||
expect(unscopedWarnings(results[0])).toEqual([ | ||
{ | ||
line: 1, | ||
column: 1, | ||
endLine: 1, | ||
endColumn: 23, | ||
...common, | ||
}, | ||
{ | ||
line: 5, | ||
column: 6, | ||
endLine: 5, | ||
endColumn: 33, | ||
...common, | ||
}, | ||
{ | ||
line: 7, | ||
column: 1, | ||
endLine: 7, | ||
endColumn: 33, | ||
...common, | ||
}, | ||
]); | ||
}); | ||
|
||
it('unscopedDisables false', async () => { | ||
const config = { | ||
rules: { | ||
'selector-type-case': 'lower', | ||
}, | ||
}; | ||
const css = stripIndent`a {} /* stylelint-disable-line */`; | ||
|
||
const { results } = await standalone({ | ||
config, | ||
code: css, | ||
reportUnscopedDisables: [false], | ||
}); | ||
|
||
expect(results[0].warnings).toHaveLength(0); | ||
}); | ||
|
||
it('unscopedDisables false except empty', async () => { | ||
const config = { | ||
rules: { | ||
'selector-type-case': 'lower', | ||
}, | ||
}; | ||
const css = stripIndent`a {} /* stylelint-disable-line */`; | ||
|
||
const { results } = await standalone({ | ||
config, | ||
code: css, | ||
reportUnscopedDisables: [false, { except: [] }], | ||
}); | ||
|
||
expect(results[0].warnings).toHaveLength(0); | ||
}); | ||
|
||
it('unscopedDisables false except / same line', async () => { | ||
const config = { | ||
rules: { | ||
'block-no-empty': true, | ||
'selector-type-case': 'lower', | ||
}, | ||
}; | ||
const css = stripIndent` | ||
A {} /* stylelint-disable-line */ | ||
A {} /* stylelint-disable-line block-no-empty */ | ||
A {} /* stylelint-disable-line selector-type-case */ | ||
`; | ||
|
||
const { results } = await standalone({ | ||
config, | ||
code: css, | ||
reportUnscopedDisables: [false, { except: ['selector-type-case', 'block-no-empty'] }], | ||
}); | ||
|
||
expect(results[0].warnings).toHaveLength(3); | ||
expect(unscopedWarnings(results[0])).toEqual([ | ||
{ | ||
line: 1, | ||
column: 6, | ||
endLine: 1, | ||
endColumn: 33, | ||
rule: '--report-unscoped-disables', | ||
severity: 'error', | ||
text: 'Configuration comment must be scoped', | ||
}, | ||
]); | ||
}); | ||
|
||
it('unscopedDisables false except / separate lines', async () => { | ||
const config = { | ||
rules: { | ||
'block-no-empty': true, | ||
'selector-type-case': 'lower', | ||
}, | ||
}; | ||
const css = stripIndent` | ||
a {} /* stylelint-disable-line */ | ||
A { color:red } /* stylelint-disable-line */ | ||
a { color:red } /* stylelint-disable-line */ | ||
`; | ||
|
||
const { results } = await standalone({ | ||
config, | ||
code: css, | ||
reportUnscopedDisables: [false, { except: ['selector-type-case', 'block-no-empty'] }], | ||
}); | ||
|
||
expect(results[0].warnings).toHaveLength(2); | ||
expect(unscopedWarnings(results[0])).toEqual([ | ||
{ | ||
line: 1, | ||
column: 6, | ||
endLine: 1, | ||
endColumn: 33, | ||
rule: '--report-unscoped-disables', | ||
severity: 'error', | ||
text: 'Configuration comment must be scoped', | ||
}, | ||
{ | ||
line: 2, | ||
column: 17, | ||
endLine: 2, | ||
endColumn: 44, | ||
rule: '--report-unscoped-disables', | ||
severity: 'error', | ||
text: 'Configuration comment must be scoped', | ||
}, | ||
]); | ||
}); | ||
|
||
function unscopedWarnings(result) { | ||
return result.warnings.filter(({ rule }) => rule === '--report-unscoped-disables'); | ||
} |
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.