Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deprecate *-whitelist *-blacklist rules
This re-instates all of these rules after they had been renamed to allowlist/denylist. They use the returned ruleFactory from their allowlist/denylist equivalents to save them duplicating code. The tests are kept the same with additional tests added to check they provide deprecation alerts.
- Loading branch information
Showing
80 changed files
with
8,081 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# at-rule-blacklist | ||
|
||
**_Deprecated: Instead use the [`at-rule-denylist`](../at-rule-denylist/README.md) rule._** | ||
|
||
Specify a list of disallowed at-rules. | ||
|
||
<!-- prettier-ignore --> | ||
```css | ||
@keyframes name {} | ||
/** ↑ | ||
* At-rules like this */ | ||
``` | ||
|
||
## Options | ||
|
||
`array|string`: `["array", "of", "unprefixed", "at-rules"]|"at-rule"` | ||
|
||
Given: | ||
|
||
``` | ||
["extend", "keyframes"] | ||
``` | ||
|
||
The following patterns are considered violations: | ||
|
||
<!-- prettier-ignore --> | ||
```css | ||
a { @extend placeholder; } | ||
``` | ||
|
||
<!-- prettier-ignore --> | ||
```css | ||
@keyframes name { | ||
from { top: 10px; } | ||
to { top: 20px; } | ||
} | ||
``` | ||
|
||
<!-- prettier-ignore --> | ||
```css | ||
@-moz-keyframes name { | ||
from { top: 10px; } | ||
to { top: 20px; } | ||
} | ||
``` | ||
|
||
The following patterns are _not_ considered violations: | ||
|
||
<!-- prettier-ignore --> | ||
```css | ||
@import "path/to/file.css"; | ||
``` |
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,197 @@ | ||
'use strict'; | ||
|
||
const standalone = require('../../../standalone'); | ||
const { messages, ruleName } = require('..'); | ||
|
||
it('includes a deprecation warning', () => { | ||
const config = { | ||
rules: { | ||
[ruleName]: ['extend'], | ||
}, | ||
}; | ||
|
||
const code = ''; | ||
|
||
return standalone({ code, config }).then((output) => { | ||
const result = output.results[0]; | ||
|
||
expect(result.deprecations).toHaveLength(1); | ||
expect(result.deprecations[0].text).toEqual( | ||
`'${ruleName}' has been deprecated. Instead use 'at-rule-denylist'.`, | ||
); | ||
expect(result.deprecations[0].reference).toEqual( | ||
`https://stylelint.io/user-guide/rules/${ruleName}/`, | ||
); | ||
}); | ||
}); | ||
|
||
testRule({ | ||
ruleName, | ||
|
||
config: ['extend', 'supports', 'keyframes'], | ||
|
||
accept: [ | ||
{ | ||
code: 'a { color: pink; }', | ||
description: 'Some random code.', | ||
}, | ||
{ | ||
code: '@mixin name ($p) {}', | ||
description: '@rule not from a blacklist.', | ||
}, | ||
], | ||
|
||
reject: [ | ||
{ | ||
code: 'a { @extend %placeholder; }', | ||
message: messages.rejected('extend'), | ||
line: 1, | ||
column: 5, | ||
description: '@rule from a blacklist, is a Sass directive.', | ||
}, | ||
{ | ||
code: ` | ||
a { | ||
@extend | ||
%placeholder; | ||
} | ||
`, | ||
message: messages.rejected('extend'), | ||
line: 3, | ||
column: 9, | ||
description: '@rule from a blacklist; newline after its name.', | ||
}, | ||
{ | ||
code: ` | ||
@keyframes name { | ||
from { top: 10px; } | ||
to { top: 20px; } | ||
} | ||
`, | ||
message: messages.rejected('keyframes'), | ||
line: 2, | ||
description: '@rule from a blacklist; independent rule.', | ||
}, | ||
{ | ||
code: ` | ||
@Keyframes name { | ||
from { top: 10px; } | ||
to { top: 20px; } | ||
} | ||
`, | ||
message: messages.rejected('Keyframes'), | ||
line: 2, | ||
column: 7, | ||
description: '@rule from a blacklist; independent rule; messed case.', | ||
}, | ||
{ | ||
code: ` | ||
@-moz-keyframes name { | ||
from { top: 10px; } | ||
to { top: 20px; } | ||
} | ||
`, | ||
message: messages.rejected('-moz-keyframes'), | ||
line: 2, | ||
column: 7, | ||
description: '@rule from a blacklist; independent rule; has vendor prefix.', | ||
}, | ||
{ | ||
code: ` | ||
@-WEBKET-KEYFRAMES name { | ||
from { top: 10px; } | ||
to { top: 20px; } | ||
} | ||
`, | ||
message: messages.rejected('-WEBKET-KEYFRAMES'), | ||
line: 2, | ||
column: 7, | ||
description: '@rule from a blacklist; independent rule; has vendor prefix.', | ||
}, | ||
], | ||
}); | ||
|
||
testRule({ | ||
ruleName, | ||
|
||
config: ['keyframes'], | ||
|
||
accept: [ | ||
{ | ||
code: 'a { color: pink; }', | ||
description: 'Some random code.', | ||
}, | ||
{ | ||
code: '@mixin name ($p) {}', | ||
description: '@rule not from a blacklist.', | ||
}, | ||
], | ||
|
||
reject: [ | ||
{ | ||
code: ` | ||
@keyframes name { | ||
from { top: 10px; } | ||
to { top: 20px; } | ||
} | ||
`, | ||
message: messages.rejected('keyframes'), | ||
line: 2, | ||
column: 7, | ||
description: '@rule from a blacklist; independent rule.', | ||
}, | ||
{ | ||
code: ` | ||
@Keyframes name { | ||
from { top: 10px; } | ||
to { top: 20px; } | ||
} | ||
`, | ||
message: messages.rejected('Keyframes'), | ||
line: 2, | ||
column: 7, | ||
description: '@rule from a blacklist; independent rule; messed case.', | ||
}, | ||
{ | ||
code: ` | ||
@-moz-keyframes name { | ||
from { top: 10px; } | ||
to { top: 20px; } | ||
} | ||
`, | ||
message: messages.rejected('-moz-keyframes'), | ||
line: 2, | ||
column: 7, | ||
description: '@rule from a blacklist; independent rule; has vendor prefix.', | ||
}, | ||
{ | ||
code: ` | ||
@-WEBKET-KEYFRAMES name { | ||
from { top: 10px; } | ||
to { top: 20px; } | ||
} | ||
`, | ||
message: messages.rejected('-WEBKET-KEYFRAMES'), | ||
line: 2, | ||
column: 7, | ||
description: '@rule from a blacklist; independent rule; has vendor prefix.', | ||
}, | ||
], | ||
}); | ||
|
||
testRule({ | ||
ruleName, | ||
syntax: 'less', | ||
config: ['keyframes'], | ||
|
||
accept: [ | ||
{ | ||
code: ` | ||
.keyframes() { margin: 0; } | ||
span { .keyframes(); } | ||
`, | ||
description: 'ignore Less mixin which are treated as at-rule', | ||
}, | ||
], | ||
}); |
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,20 @@ | ||
// @ts-nocheck | ||
|
||
'use strict'; | ||
|
||
const replacementRule = require('../at-rule-denylist'); | ||
const ruleMessages = require('../../utils/ruleMessages'); | ||
|
||
const ruleName = 'at-rule-blacklist'; | ||
|
||
const messages = ruleMessages(ruleName, { | ||
rejected: (name) => `Unexpected at-rule "${name}"`, | ||
}); | ||
|
||
const rule = replacementRule.ruleFactory(ruleName, messages); | ||
|
||
rule.primaryOptionArray = true; | ||
|
||
rule.ruleName = ruleName; | ||
rule.messages = messages; | ||
module.exports = rule; |
Oops, something went wrong.