Skip to content

Commit

Permalink
Deprecate *-whitelist *-blacklist rules
Browse files Browse the repository at this point in the history
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
kevindew committed Jun 26, 2020
1 parent e93e44c commit 28e1a31
Show file tree
Hide file tree
Showing 80 changed files with 8,081 additions and 1 deletion.
28 changes: 27 additions & 1 deletion docs/user-guide/rules/list.md
Expand Up @@ -102,10 +102,14 @@ Grouped first by the following categories and then by the [_thing_](http://apps.
### Function

- [`function-allowlist`](../../../lib/rules/function-allowlist/README.md): Specify a list of allowed functions.
- [`function-blacklist`](../../../lib/rules/function-blacklist/README.md): Specify a list of disallowed functions. **(deprecated)**
- [`function-denylist`](../../../lib/rules/function-denylist/README.md): Specify a list of disallowed functions.
- [`function-url-no-scheme-relative`](../../../lib/rules/function-url-no-scheme-relative/README.md): Disallow scheme-relative urls.
- [`function-url-scheme-denylist`](../../../lib/rules/function-url-scheme-denylist/README.md): Specify a list of disallowed URL schemes.
- [`function-url-scheme-allowlist`](../../../lib/rules/function-url-scheme-allowlist/README.md): Specify a list of allowed URL schemes.
- [`function-url-scheme-blacklist`](../../../lib/rules/function-url-scheme-blacklist/README.md): Specify a list of disallowed URL schemes. **(deprecated)**
- [`function-url-scheme-denylist`](../../../lib/rules/function-url-scheme-denylist/README.md): Specify a list of disallowed URL schemes.
- [`function-url-scheme-whitelist`](../../../lib/rules/function-url-scheme-whitelist/README.md): Specify a list of allowed URL schemes. **(deprecated)**
- [`function-whitelist`](../../../lib/rules/function-whitelist/README.md): Specify a list of allowed functions. **(deprecated)**

### Keyframes

Expand All @@ -122,7 +126,9 @@ Grouped first by the following categories and then by the [_thing_](http://apps.
### Unit

- [`unit-allowlist`](../../../lib/rules/unit-allowlist/README.md): Specify a list of allowed units.
- [`unit-blacklist`](../../../lib/rules/unit-blacklist/README.md): Specify a list of disallowed units. **(deprecated)**
- [`unit-denylist`](../../../lib/rules/unit-denylist/README.md): Specify a list of disallowed units.
- [`unit-whitelist`](../../../lib/rules/unit-whitelist/README.md): Specify a list of allowed units. **(deprecated)**

### Shorthand property

Expand All @@ -139,17 +145,23 @@ Grouped first by the following categories and then by the [_thing_](http://apps.
### Property

- [`property-allowlist`](../../../lib/rules/property-allowlist/README.md): Specify a list of allowed properties.
- [`property-blacklist`](../../../lib/rules/property-blacklist/README.md): Specify a list of disallowed properties. **(deprecated)**
- [`property-denylist`](../../../lib/rules/property-denylist/README.md): Specify a list of disallowed properties.
- [`property-no-vendor-prefix`](../../../lib/rules/property-no-vendor-prefix/README.md): Disallow vendor prefixes for properties.
- [`property-whitelist`](../../../lib/rules/property-whitelist/README.md): Specify a list of allowed properties. **(deprecated)**

### Declaration

- [`declaration-block-no-redundant-longhand-properties`](../../../lib/rules/declaration-block-no-redundant-longhand-properties/README.md): Disallow longhand properties that can be combined into one shorthand property.
- [`declaration-no-important`](../../../lib/rules/declaration-no-important/README.md): Disallow `!important` within declarations.
- [`declaration-property-unit-allowlist`](../../../lib/rules/declaration-property-unit-allowlist/README.md): Specify a list of allowed property and unit pairs within declarations.
- [`declaration-property-unit-blacklist`](../../../lib/rules/declaration-property-unit-blacklist/README.md): Specify a list of disallowed property and unit pairs within declarations. **(deprecated)**
- [`declaration-property-unit-denylist`](../../../lib/rules/declaration-property-unit-denylist/README.md): Specify a list of disallowed property and unit pairs within declarations.
- [`declaration-property-unit-whitelist`](../../../lib/rules/declaration-property-unit-whitelist/README.md): Specify a list of allowed property and unit pairs within declarations. **(deprecated)**
- [`declaration-property-value-allowlist`](../../../lib/rules/declaration-property-value-allowlist/README.md): Specify a list of allowed property and value pairs within declarations.
- [`declaration-property-value-blacklist`](../../../lib/rules/declaration-property-value-blacklist/README.md): Specify a list of disallowed property and value pairs within declarations. **(deprecated)**
- [`declaration-property-value-denylist`](../../../lib/rules/declaration-property-value-denylist/README.md): Specify a list of disallowed property and value pairs within declarations.
- [`declaration-property-value-whitelist`](../../../lib/rules/declaration-property-value-whitelist/README.md): Specify a list of allowed property and value pairs within declarations. **(deprecated)**

### Declaration block

Expand All @@ -158,10 +170,14 @@ Grouped first by the following categories and then by the [_thing_](http://apps.
### Selector

- [`selector-attribute-operator-allowlist`](../../../lib/rules/selector-attribute-operator-allowlist/README.md): Specify a list of allowed attribute operators.
- [`selector-attribute-operator-blacklist`](../../../lib/rules/selector-attribute-operator-blacklist/README.md): Specify a list of disallowed attribute operators. **(deprecated)**
- [`selector-attribute-operator-denylist`](../../../lib/rules/selector-attribute-operator-denylist/README.md): Specify a list of disallowed attribute operators.
- [`selector-attribute-operator-whitelist`](../../../lib/rules/selector-attribute-operator-whitelist/README.md): Specify a list of allowed attribute operators. **(deprecated)**
- [`selector-class-pattern`](../../../lib/rules/selector-class-pattern/README.md): Specify a pattern for class selectors.
- [`selector-combinator-allowlist`](../../../lib/rules/selector-combinator-allowlist/README.md): Specify a list of allowed combinators.
- [`selector-combinator-blacklist`](../../../lib/rules/selector-combinator-blacklist/README.md): Specify a list of disallowed combinators. **(deprecated)**
- [`selector-combinator-denylist`](../../../lib/rules/selector-combinator-denylist/README.md): Specify a list of disallowed combinators.
- [`selector-combinator-whitelist`](../../../lib/rules/selector-combinator-whitelist/README.md): Specify a list of allowed combinators. **(deprecated)**
- [`selector-id-pattern`](../../../lib/rules/selector-id-pattern/README.md): Specify a pattern for ID selectors.
- [`selector-max-attribute`](../../../lib/rules/selector-max-attribute/README.md): Limit the number of attribute selectors in a selector.
- [`selector-max-class`](../../../lib/rules/selector-max-class/README.md): Limit the number of classes in a selector.
Expand All @@ -177,17 +193,24 @@ Grouped first by the following categories and then by the [_thing_](http://apps.
- [`selector-no-qualifying-type`](../../../lib/rules/selector-no-qualifying-type/README.md): Disallow qualifying a selector by type.
- [`selector-no-vendor-prefix`](../../../lib/rules/selector-no-vendor-prefix/README.md): Disallow vendor prefixes for selectors.
- [`selector-pseudo-class-allowlist`](../../../lib/rules/selector-pseudo-class-allowlist/README.md): Specify a list of allowed pseudo-class selectors.
- [`selector-pseudo-class-blacklist`](../../../lib/rules/selector-pseudo-class-blacklist/README.md): Specify a list of disallowed pseudo-class selectors. **(deprecated)**
- [`selector-pseudo-class-denylist`](../../../lib/rules/selector-pseudo-class-denylist/README.md): Specify a list of disallowed pseudo-class selectors.
- [`selector-pseudo-class-whitelist`](../../../lib/rules/selector-pseudo-class-whitelist/README.md): Specify a list of allowed pseudo-class selectors. **(deprecated)**
- [`selector-pseudo-element-allowlist`](../../../lib/rules/selector-pseudo-element-allowlist/README.md): Specify a list of allowed pseudo-element selectors.
- [`selector-pseudo-element-blacklist`](../../../lib/rules/selector-pseudo-element-blacklist/README.md): Specify a list of disallowed pseudo-element selectors. **(deprecated)**
- [`selector-pseudo-element-colon-notation`](../../../lib/rules/selector-pseudo-element-colon-notation/README.md): Specify single or double colon notation for applicable pseudo-elements (Autofixable).
- [`selector-pseudo-element-denylist`](../../../lib/rules/selector-pseudo-element-denylist/README.md): Specify a list of disallowed pseudo-element selectors.
- [`selector-pseudo-element-whitelist`](../../../lib/rules/selector-pseudo-element-whitelist/README.md): Specify a list of allowed pseudo-element selectors. **(deprecated)**

### Media feature

- [`media-feature-name-allowlist`](../../../lib/rules/media-feature-name-allowlist/README.md): Specify a list of allowed media feature names.
- [`media-feature-name-blacklist`](../../../lib/rules/media-feature-name-blacklist/README.md): Specify a list of disallowed media feature names. **(deprecated)**
- [`media-feature-name-denylist`](../../../lib/rules/media-feature-name-denylist/README.md): Specify a list of disallowed media feature names.
- [`media-feature-name-no-vendor-prefix`](../../../lib/rules/media-feature-name-no-vendor-prefix/README.md): Disallow vendor prefixes for media feature names.
- [`media-feature-name-value-allowlist`](../../../lib/rules/media-feature-name-value-allowlist/README.md): Specify a list of allowed media feature name and value pairs.
- [`media-feature-name-value-whitelist`](../../../lib/rules/media-feature-name-value-whitelist/README.md): Specify a list of allowed media feature name and value pairs. **(deprecated)**
- [`media-feature-name-whitelist`](../../../lib/rules/media-feature-name-whitelist/README.md): Specify a list of allowed media feature names. **(deprecated)**

### Custom media

Expand All @@ -196,12 +219,15 @@ Grouped first by the following categories and then by the [_thing_](http://apps.
### At-rule

- [`at-rule-allowlist`](../../../lib/rules/at-rule-allowlist/README.md): Specify a list of allowed at-rules.
- [`at-rule-blacklist`](../../../lib/rules/at-rule-blacklist/README.md): Specify a list of disallowed at-rules. **(deprecated)**
- [`at-rule-denylist`](../../../lib/rules/at-rule-denylist/README.md): Specify a list of disallowed at-rules.
- [`at-rule-no-vendor-prefix`](../../../lib/rules/at-rule-no-vendor-prefix/README.md): Disallow vendor prefixes for at-rules.
- [`at-rule-property-requirelist`](../../../lib/rules/at-rule-property-requirelist/README.md): Specify a requirelist of properties for an at-rule.
- [`at-rule-whitelist`](../../../lib/rules/at-rule-whitelist/README.md): Specify a list of allowed at-rules. **(deprecated)**

### Comment

- [`comment-word-blacklist`](../../../lib/rules/comment-word-blacklist/README.md): Specify a list of disallowed words within comments. **(deprecated)**
- [`comment-word-denylist`](../../../lib/rules/comment-word-denylist/README.md): Specify a list of disallowed words within comments.

### General / Sheet
Expand Down
52 changes: 52 additions & 0 deletions lib/rules/at-rule-blacklist/README.md
@@ -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";
```
197 changes: 197 additions & 0 deletions lib/rules/at-rule-blacklist/__tests__/index.js
@@ -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',
},
],
});
20 changes: 20 additions & 0 deletions lib/rules/at-rule-blacklist/index.js
@@ -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;

0 comments on commit 28e1a31

Please sign in to comment.