Skip to content

Commit

Permalink
Alias *-whitelist, *-blacklist and *-requirelist rules
Browse files Browse the repository at this point in the history
Previously *-whitelist, *-blacklist and *-requirelist rules were renamed
to a consistent naming pattern of *-allowed-list, *-disallowed-list and
*-required-list respectively. This commit adds aliases so that the old
rules can continue to operate; this allows backwards compatibility to be
maintained.

A consequence of this is that violations for the previously named rules
will show up with the new name. A developer may also get some confusing
results if they happen to have the same rule defined with both names and
different options.
  • Loading branch information
kevindew committed Jun 30, 2020
1 parent 3f7b169 commit 96acce6
Show file tree
Hide file tree
Showing 31 changed files with 213 additions and 0 deletions.
41 changes: 41 additions & 0 deletions lib/__tests__/aliasedRules.test.js
@@ -0,0 +1,41 @@
'use strict';

const rules = require('../rules');

const whitelistAndBlacklistRulePrefixes = [
'at-rule',
'declaration-property-unit',
'declaration-property-value',
'function',
'function-url-scheme',
'media-feature-name',
'property',
'selector-attribute-operator',
'selector-combinator',
'selector-pseudo-class',
'selector-pseudo-element',
'unit',
];

const whitelistRulePrefixes = whitelistAndBlacklistRulePrefixes.concat([
'media-feature-name-value',
]);

whitelistRulePrefixes.forEach((prefix) => {
it(`aliases ${prefix}-whitelist to ${prefix}-allowed-list`, () =>
expect(rules[`${prefix}-whitelist`].ruleName).toEqual(`${prefix}-allowed-list`));
});

const blacklistRulePrefixes = whitelistAndBlacklistRulePrefixes.concat(['comment-word']);

blacklistRulePrefixes.forEach((prefix) => {
it(`aliases ${prefix}-blacklist to ${prefix}-disallowed-list`, () =>
expect(rules[`${prefix}-blacklist`].ruleName).toEqual(`${prefix}-disallowed-list`));
});

const requirelistRulePrefixes = ['at-rule-property'];

requirelistRulePrefixes.forEach((prefix) => {
it(`aliases ${prefix}-requirelist to ${prefix}-required-list`, () =>
expect(rules[`${prefix}-requirelist`].ruleName).toEqual(`${prefix}-required-list`));
});
13 changes: 13 additions & 0 deletions lib/__tests__/integration.test.js
Expand Up @@ -143,6 +143,19 @@ it('Scss integration test', () => {
});
});

it('rule aliasing integration test', () => {
return postcss()
.use(stylelint({ rules: { 'unit-blacklist': ['px'] } }))
.process('a { top: 10px; }', { from: undefined })
.then((result) => {
const error = result.messages[0];

expect(error).toBeTruthy();
expect(error.rule).toBe('unit-disallowed-list');
expect(error.text).toBe('Unexpected unit "px" (unit-disallowed-list)');
});
});

describe('integration test null option', () => {
let results;

Expand Down
2 changes: 2 additions & 0 deletions lib/rules/at-rule-allowed-list/README.md
Expand Up @@ -9,6 +9,8 @@ Specify a list of allowed at-rules.
* At-rules like this */
```

This rule was previously called, and is aliased as, `at-rule-whitelist`.

## Options

`array|string`: `["array", "of", "unprefixed", "at-rules"]|"at-rule"`
Expand Down
2 changes: 2 additions & 0 deletions lib/rules/at-rule-disallowed-list/README.md
Expand Up @@ -9,6 +9,8 @@ Specify a list of disallowed at-rules.
* At-rules like this */
```

This rule was previously called, and is aliased as, `at-rule-blacklist`.

## Options

`array|string`: `["array", "of", "unprefixed", "at-rules"]|"at-rule"`
Expand Down
2 changes: 2 additions & 0 deletions lib/rules/at-rule-property-required-list/README.md
Expand Up @@ -9,6 +9,8 @@ Specify a list of required properties for an at-rule.
* At-rule and required property names */
```

This rule was previously called, and is aliased as, `at-rule-requirelist`.

## Options

`object`: `{ "at-rule-name": ["array", "of", "properties"] }`
Expand Down
2 changes: 2 additions & 0 deletions lib/rules/comment-word-disallowed-list/README.md
Expand Up @@ -9,6 +9,8 @@ Specify a list of disallowed words within comments.
* These three words */
```

This rule was previously called, and is aliased as, `comment-word-blacklist`.

**Caveat:** Comments within _selector and value lists_ are currently ignored.

## Options
Expand Down
2 changes: 2 additions & 0 deletions lib/rules/declaration-property-unit-allowed-list/README.md
Expand Up @@ -9,6 +9,8 @@ a { width: 100px; }
* These properties and these units */
```

This rule was previously called, and is aliased as, `declaration-property-unit-whitelist`.

## Options

`object`: `{ "unprefixed-property-name": ["array", "of", "units"] }`
Expand Down
2 changes: 2 additions & 0 deletions lib/rules/declaration-property-unit-disallowed-list/README.md
Expand Up @@ -9,6 +9,8 @@ a { width: 100px; }
* These properties and these units */
```

This rule was previously called, and is aliased as, `declaration-property-unit-blacklist`.

## Options

`object`: `{ "unprefixed-property-name": ["array", "of", "units"] }`
Expand Down
2 changes: 2 additions & 0 deletions lib/rules/declaration-property-value-allowed-list/README.md
Expand Up @@ -9,6 +9,8 @@ a { text-transform: uppercase; }
* These properties and these values */
```

This rule was previously called, and is aliased as, `declaration-property-value-whitelist`.

## Options

`object`: `{ "unprefixed-property-name": ["array", "of", "values"], "unprefixed-property-name": ["/regex/", "non-regex"] }`
Expand Down
Expand Up @@ -9,6 +9,8 @@ a { text-transform: uppercase; }
* These properties and these values */
```

This rule was previously called, and is aliased as, `declaration-property-value-blacklist`.

## Options

`object`: `{ "unprefixed-property-name": ["array", "of", "values"], "unprefixed-property-name": ["/regex/", "non-regex", /regex/] }`
Expand Down
2 changes: 2 additions & 0 deletions lib/rules/function-allowed-list/README.md
Expand Up @@ -9,6 +9,8 @@ a { transform: scale(1); }
* This function */
```

This rule was previously called, and is aliased as, `function-whitelist`.

## Options

`array|string`: `["array", "of", "unprefixed", /functions/ or "regex"]|"function"|"/regex/"`
Expand Down
2 changes: 2 additions & 0 deletions lib/rules/function-disallowed-list/README.md
Expand Up @@ -9,6 +9,8 @@ a { transform: scale(1); }
* This function */
```

This rule was previously called, and is aliased as, `function-blacklist`.

## Options

`array|string`: `["array", "of", "unprefixed", /functions/ or "regex"]|"function"|"/regex/"`
Expand Down
2 changes: 2 additions & 0 deletions lib/rules/function-url-scheme-allowed-list/README.md
Expand Up @@ -9,6 +9,8 @@ a { background-image: url('http://www.example.com/file.jpg'); }
* This URL scheme */
```

This rule was previously called, and is aliased as, `function-url-scheme-whitelist`.

A [URL scheme](https://url.spec.whatwg.org/#syntax-url-scheme) consists of alphanumeric, `+`, `-`, and `.` characters. It can appear at the start of a URL and is followed by `:`.

This rule ignores:
Expand Down
2 changes: 2 additions & 0 deletions lib/rules/function-url-scheme-disallowed-list/README.md
Expand Up @@ -9,6 +9,8 @@ a { background-image: url('http://www.example.com/file.jpg'); }
* This URL scheme */
```

This rule was previously called, and is aliased as, `function-url-scheme-blacklist`.

A [URL scheme](https://url.spec.whatwg.org/#syntax-url-scheme) consists of alphanumeric, `+`, `-`, and `.` characters. It can appear at the start of a URL and is followed by `:`.

This rule ignores:
Expand Down
85 changes: 85 additions & 0 deletions lib/rules/index.js
Expand Up @@ -8,6 +8,8 @@ const importLazy = require('import-lazy');
const rules = {
'alpha-value-notation': importLazy(() => require('./alpha-value-notation'))(),
'at-rule-allowed-list': importLazy(() => require('./at-rule-allowed-list'))(),
// Renamed to at-rule-disallowed-list
'at-rule-blacklist': importLazy(() => require('./at-rule-disallowed-list'))(),
'at-rule-disallowed-list': importLazy(() => require('./at-rule-disallowed-list'))(),
'at-rule-empty-line-before': importLazy(() => require('./at-rule-empty-line-before'))(),
'at-rule-name-case': importLazy(() => require('./at-rule-name-case'))(),
Expand All @@ -17,9 +19,13 @@ const rules = {
'at-rule-no-unknown': importLazy(() => require('./at-rule-no-unknown'))(),
'at-rule-no-vendor-prefix': importLazy(() => require('./at-rule-no-vendor-prefix'))(),
'at-rule-property-required-list': importLazy(() => require('./at-rule-property-required-list'))(),
// Renamed to at-rule-required-list
'at-rule-property-requirelist': importLazy(() => require('./at-rule-property-required-list'))(),
'at-rule-semicolon-newline-after': importLazy(() =>
require('./at-rule-semicolon-newline-after'),
)(),
// Renamed to at-rule-allowed-list
'at-rule-whitelist': importLazy(() => require('./at-rule-allowed-list'))(),
'block-closing-brace-empty-line-before': importLazy(() =>
require('./block-closing-brace-empty-line-before'),
)(),
Expand Down Expand Up @@ -57,6 +63,8 @@ const rules = {
'comment-empty-line-before': importLazy(() => require('./comment-empty-line-before'))(),
'comment-no-empty': importLazy(() => require('./comment-no-empty'))(),
'comment-whitespace-inside': importLazy(() => require('./comment-whitespace-inside'))(),
// Renamed to comment-word-disallowed-list
'comment-word-blacklist': importLazy(() => require('./comment-word-disallowed-list'))(),
'comment-word-disallowed-list': importLazy(() => require('./comment-word-disallowed-list'))(),
'custom-media-pattern': importLazy(() => require('./custom-media-pattern'))(),
'custom-property-empty-line-before': importLazy(() =>
Expand Down Expand Up @@ -102,22 +110,40 @@ const rules = {
'declaration-property-unit-allowed-list': importLazy(() =>
require('./declaration-property-unit-allowed-list'),
)(),
// Renamed to declaration-property-unit-disallowed-list
'declaration-property-unit-blacklist': importLazy(() =>
require('./declaration-property-unit-disallowed-list'),
)(),
'declaration-property-unit-disallowed-list': importLazy(() =>
require('./declaration-property-unit-disallowed-list'),
)(),
// Renamed to declaration-property-unit-allowed-list
'declaration-property-unit-whitelist': importLazy(() =>
require('./declaration-property-unit-allowed-list'),
)(),
'declaration-property-value-allowed-list': importLazy(() =>
require('./declaration-property-value-allowed-list'),
)(),
// Renamed to declaration-property-value-disallowed-list
'declaration-property-value-blacklist': importLazy(() =>
require('./declaration-property-value-disallowed-list'),
)(),
'declaration-property-value-disallowed-list': importLazy(() =>
require('./declaration-property-value-disallowed-list'),
)(),
// Renamed to declaration-property-value-allowed-list
'declaration-property-value-whitelist': importLazy(() =>
require('./declaration-property-value-allowed-list'),
)(),
'font-family-no-missing-generic-family-keyword': importLazy(() =>
require('./font-family-no-missing-generic-family-keyword'),
)(),
'font-family-name-quotes': importLazy(() => require('./font-family-name-quotes'))(),
'font-family-no-duplicate-names': importLazy(() => require('./font-family-no-duplicate-names'))(),
'font-weight-notation': importLazy(() => require('./font-weight-notation'))(),
'function-allowed-list': importLazy(() => require('./function-allowed-list'))(),
// Renamed to function-disallowed-list
'function-blacklist': importLazy(() => require('./function-disallowed-list'))(),
'function-calc-no-invalid': importLazy(() => require('./function-calc-no-invalid'))(),
'function-calc-no-unspaced-operator': importLazy(() =>
require('./function-calc-no-unspaced-operator'),
Expand Down Expand Up @@ -145,10 +171,20 @@ const rules = {
'function-url-scheme-allowed-list': importLazy(() =>
require('./function-url-scheme-allowed-list'),
)(),
// Renamed to function-url-scheme-disallowed-list
'function-url-scheme-blacklist': importLazy(() =>
require('./function-url-scheme-disallowed-list'),
)(),
'function-url-scheme-disallowed-list': importLazy(() =>
require('./function-url-scheme-disallowed-list'),
)(),
// Renamed to function-url-scheme-allowed-list
'function-url-scheme-whitelist': importLazy(() =>
require('./function-url-scheme-allowed-list'),
)(),
'function-whitespace-after': importLazy(() => require('./function-whitespace-after'))(),
// Renamed to function-allowed-list
'function-whitelist': importLazy(() => require('./function-allowed-list'))(),
'hue-degree-notation': importLazy(() => require('./hue-degree-notation'))(),
'keyframe-declaration-no-important': importLazy(() =>
require('./keyframe-declaration-no-important'),
Expand All @@ -168,6 +204,10 @@ const rules = {
'media-feature-name-allowed-list': importLazy(() =>
require('./media-feature-name-allowed-list'),
)(),
// Renamed to media-feature-name-disallowed-list
'media-feature-name-blacklist': importLazy(() =>
require('./media-feature-name-disallowed-list'),
)(),
'media-feature-name-case': importLazy(() => require('./media-feature-name-case'))(),
'media-feature-name-disallowed-list': importLazy(() =>
require('./media-feature-name-disallowed-list'),
Expand All @@ -179,6 +219,11 @@ const rules = {
'media-feature-name-value-allowed-list': importLazy(() =>
require('./media-feature-name-value-allowed-list'),
)(),
'media-feature-name-value-whitelist': importLazy(() =>
require('./media-feature-name-value-allowed-list'),
)(),
// Renamed to media-feature-name-allowed-list
'media-feature-name-whitelist': importLazy(() => require('./media-feature-name-allowed-list'))(),
'media-feature-parentheses-space-inside': importLazy(() =>
require('./media-feature-parentheses-space-inside'),
)(),
Expand Down Expand Up @@ -218,17 +263,25 @@ const rules = {
'number-max-precision': importLazy(() => require('./number-max-precision'))(),
'number-no-trailing-zeros': importLazy(() => require('./number-no-trailing-zeros'))(),
'property-allowed-list': importLazy(() => require('./property-allowed-list'))(),
// Renamed to property-disallowed-list
'property-blacklist': importLazy(() => require('./property-disallowed-list'))(),
'property-case': importLazy(() => require('./property-case'))(),
'property-disallowed-list': importLazy(() => require('./property-disallowed-list'))(),
'property-no-unknown': importLazy(() => require('./property-no-unknown'))(),
'property-no-vendor-prefix': importLazy(() => require('./property-no-vendor-prefix'))(),
// Renamed to property-allowed-list
'property-whitelist': importLazy(() => require('./property-allowed-list'))(),
'rule-empty-line-before': importLazy(() => require('./rule-empty-line-before'))(),
'selector-attribute-brackets-space-inside': importLazy(() =>
require('./selector-attribute-brackets-space-inside'),
)(),
'selector-attribute-operator-allowed-list': importLazy(() =>
require('./selector-attribute-operator-allowed-list'),
)(),
// Renamed to selector-attribute-operator-disallowed-list
'selector-attribute-operator-blacklist': importLazy(() =>
require('./selector-attribute-operator-disallowed-list'),
)(),
'selector-attribute-operator-disallowed-list': importLazy(() =>
require('./selector-attribute-operator-disallowed-list'),
)(),
Expand All @@ -238,11 +291,19 @@ const rules = {
'selector-attribute-operator-space-before': importLazy(() =>
require('./selector-attribute-operator-space-before'),
)(),
// Renamed to selector-attribute-operator-allowed-list
'selector-attribute-operator-whitelist': importLazy(() =>
require('./selector-attribute-operator-allowed-list'),
)(),
'selector-attribute-quotes': importLazy(() => require('./selector-attribute-quotes'))(),
'selector-class-pattern': importLazy(() => require('./selector-class-pattern'))(),
'selector-combinator-allowed-list': importLazy(() =>
require('./selector-combinator-allowed-list'),
)(),
// Renamed to selector-combinator-disallowed-list
'selector-combinator-blacklist': importLazy(() =>
require('./selector-combinator-disallowed-list'),
)(),
'selector-combinator-disallowed-list': importLazy(() =>
require('./selector-combinator-disallowed-list'),
)(),
Expand All @@ -252,6 +313,10 @@ const rules = {
'selector-combinator-space-before': importLazy(() =>
require('./selector-combinator-space-before'),
)(),
// Renamed to selector-combinator-allowed-list
'selector-combinator-whitelist': importLazy(() =>
require('./selector-combinator-allowed-list'),
)(),
'selector-descendant-combinator-no-non-space': importLazy(() =>
require('./selector-descendant-combinator-no-non-space'),
)(),
Expand Down Expand Up @@ -286,6 +351,10 @@ const rules = {
'selector-pseudo-class-allowed-list': importLazy(() =>
require('./selector-pseudo-class-allowed-list'),
)(),
// Renamed to selector-pseudo-class-disallowed-list
'selector-pseudo-class-blacklist': importLazy(() =>
require('./selector-pseudo-class-disallowed-list'),
)(),
'selector-pseudo-class-case': importLazy(() => require('./selector-pseudo-class-case'))(),
'selector-pseudo-class-disallowed-list': importLazy(() =>
require('./selector-pseudo-class-disallowed-list'),
Expand All @@ -296,9 +365,17 @@ const rules = {
'selector-pseudo-class-parentheses-space-inside': importLazy(() =>
require('./selector-pseudo-class-parentheses-space-inside'),
)(),
// Renamed to selector-pseudo-class-allowed-list
'selector-pseudo-class-whitelist': importLazy(() =>
require('./selector-pseudo-class-allowed-list'),
)(),
'selector-pseudo-element-allowed-list': importLazy(() =>
require('./selector-pseudo-element-allowed-list'),
)(),
// Renamed to selector-pseudo-element-disallowed-list
'selector-pseudo-element-blacklist': importLazy(() =>
require('./selector-pseudo-element-disallowed-list'),
)(),
'selector-pseudo-element-case': importLazy(() => require('./selector-pseudo-element-case'))(),
'selector-pseudo-element-colon-notation': importLazy(() =>
require('./selector-pseudo-element-colon-notation'),
Expand All @@ -309,6 +386,10 @@ const rules = {
'selector-pseudo-element-no-unknown': importLazy(() =>
require('./selector-pseudo-element-no-unknown'),
)(),
// Renamed to selector-pseudo-element-allowed-list
'selector-pseudo-element-whitelist': importLazy(() =>
require('./selector-pseudo-element-allowed-list'),
)(),
'selector-type-case': importLazy(() => require('./selector-type-case'))(),
'selector-type-no-unknown': importLazy(() => require('./selector-type-no-unknown'))(),
'shorthand-property-no-redundant-values': importLazy(() =>
Expand All @@ -319,9 +400,13 @@ const rules = {
'time-min-milliseconds': importLazy(() => require('./time-min-milliseconds'))(),
'unicode-bom': importLazy(() => require('./unicode-bom'))(),
'unit-allowed-list': importLazy(() => require('./unit-allowed-list'))(),
// Renamed to unit-disallowed-list
'unit-blacklist': importLazy(() => require('./unit-disallowed-list'))(),
'unit-case': importLazy(() => require('./unit-case'))(),
'unit-disallowed-list': importLazy(() => require('./unit-disallowed-list'))(),
'unit-no-unknown': importLazy(() => require('./unit-no-unknown'))(),
// Renamed to unit-allowed-list
'unit-whitelist': importLazy(() => require('./unit-allowed-list'))(),
'value-keyword-case': importLazy(() => require('./value-keyword-case'))(),
'value-list-comma-newline-after': importLazy(() => require('./value-list-comma-newline-after'))(),
'value-list-comma-newline-before': importLazy(() =>
Expand Down

0 comments on commit 96acce6

Please sign in to comment.