Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace *-whitelist/*-blacklist/*-requirelist rules with *-allowed-list/*-disallowed-list/*-required-list rules #4845

Merged
merged 5 commits into from Jul 6, 2020

Conversation

kevindew
Copy link
Contributor

@kevindew kevindew commented Jun 26, 2020

Which issue, if any, is this issue related to?

Resolves #4844

Is there anything in the PR that needs further explanation?

This PR serves as a potential implementation route to achieve the re-naming change raised in issue #4844, where I expect there is still to be a reasonable amount of discussion on the issue. It has been reworked following @jeddy3 suggestion on an implementation route.

It takes an approach of renaming all *-blacklist, *-requirelist and *-whitelist rules to *-disallowed-list, *-required-list and *-allowed-list which creates a consistent *-list pattern for naming list based rules. There have then been aliases created so that the previously named rules remain operational.

@jeddy3
Copy link
Member

jeddy3 commented Jun 27, 2020

@kevindew Thank you for getting the ball rolling with this.

The approach I took for this was to rename the existing rules first (and associated documentation), so that the git history on the rules could be transferred to the new rules

Excellent. Regardless of the final route we decide on, we'll need to go about it this way.

This PR serves as a potential implementation route to achieve the re-naming change raised in issue #4844, where I expect there is still to be a reasonable amount of discussion on the issue.

I've made some suggestions about the implementation route and renaming over in the issue.

This applies a full rename across the repository to reflect that the
term "blacklist" is controversial in the tech community and that using
the term "disallowed-list" is more explicit in it's purpose.
@kevindew
Copy link
Contributor Author

@kevindew Thank you for getting the ball rolling with this.

The approach I took for this was to rename the existing rules first (and associated documentation), so that the git history on the rules could be transferred to the new rules

Excellent. Regardless of the final route we decide on, we'll need to go about it this way.

This PR serves as a potential implementation route to achieve the re-naming change raised in issue #4844, where I expect there is still to be a reasonable amount of discussion on the issue.

I've made some suggestions about the implementation route and renaming over in the issue.

Thanks, the clarity in your suggestions was super helpful. I've now amended this in line with them, do let me know if I've misinterpreted any.

I wasn't too sure of what testing approach, if any, to take with the aliased rules and put this together where I might benefit from some pointers to precedence if it's not sufficiently consistent with this codebase.

I also wasn't sure if this risks being a BC break given that violations for a whitelist rule will be returned under a new rule name. For example, a unit-whitelist violation will be raised as a unit-allowed-list violation. I expect you'll know better than me if that is considered part of the API.

@kevindew kevindew changed the title Deprecate *-whitelist/*-blacklist rules in favour of *-allowlist/*-denylist Replace *-whitelist/*-blacklist/*-requirelist rules with *-allowed-list/*-disallowed-list/*-required-list rules Jun 28, 2020
Copy link
Member

@jeddy3 jeddy3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kevindew Thanks for putting all the legwork into this one. It's looking great.

I've requested:

  • some very minor nitpicks
  • the regeneration of the example.png screenshot

I wasn't too sure of what testing approach,

Tests look great.

I also wasn't sure if this risks being a BC break given that violations for a whitelist rule will be returned under a new rule name.

I think we're good. The only place outside of a config where the rule names are used is within the checkAgainstRule plugin utility. It would be great if we could add a test ensuring the renamed rule is in the warning when an alias is used.

- [`function-url-scheme-blacklist`](../../../lib/rules/function-url-scheme-blacklist/README.md): Specify a blacklist of disallowed URL schemes.
- [`function-url-scheme-whitelist`](../../../lib/rules/function-url-scheme-whitelist/README.md): Specify a whitelist of allowed URL schemes.
- [`function-whitelist`](../../../lib/rules/function-whitelist/README.md): Specify a whitelist of allowed functions.
- [`function-url-scheme-disallowed-list`](../../../lib/rules/function-url-scheme-disallowed-list/README.md): Specify a list of disallowed URL schemes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's alphabetize this and the next line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, nice spot 👍

@@ -141,6 +143,19 @@ it('Scss integration test', () => {
});
});

it('Rule aliasing integration test', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it('Rule aliasing integration test', () => {
it('rule aliasing integration test', () => {

Let's use a lower case here to be consistent with the majority of other descriptions (the capitalised "Scss..." description above is more an exception than the norm).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, done


const messages = ruleMessages(ruleName, {
expected: (property, atRule) => `Expected property "${property}" for at-rule "${atRule}"`,
});

function rule(primary) {
function rule(list) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making this consistent.

@@ -12,16 +12,16 @@ const ruleMessages = require('../../utils/ruleMessages');
const validateOptions = require('../../utils/validateOptions');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file shifts from whitelist to disallowed list, and vice-versa for its twin. However, the logic also shifts in both rules, so things work out in the end.

I think we can roll with it, rather than try to unpick it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This just seems to be GitHub becoming confused when merging the diffs of multiple commits. In the individual commits this rule doesn't shift.For example:

rename lib/rules/{declaration-property-unit-blacklist => declaration-property-unit-disallowed-list}/README.md (91%)
rename lib/rules/{declaration-property-unit-blacklist => declaration-property-unit-disallowed-list}/__tests__/index.js (100%)
rename lib/rules/{declaration-property-unit-blacklist => declaration-property-unit-disallowed-list}/index.js (85%)

and

rename lib/rules/{declaration-property-unit-whitelist => declaration-property-unit-allowed-list}/README.md (92%)
rename lib/rules/{declaration-property-unit-whitelist => declaration-property-unit-allowed-list}/__tests__/index.js (100%)
rename lib/rules/{declaration-property-unit-whitelist => declaration-property-unit-allowed-list}/index.js (85%)

@@ -1,6 +1,6 @@
# selector-pseudo-element-blacklist
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A blacklist to allowed list shift, but the examples shifted too. As with the rule shift above, I think we're good to roll with this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same GitHub session, looks good in commit history.

@@ -1,7 +1,7 @@
{
"rules": {
"color-no-invalid-hex": true,
"declaration-property-unit-blacklist": { "margin": ["px"] },
"declaration-property-unit-disallowed-list": { "margin": ["px"] },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"declaration-property-unit-disallowed-list": { "margin": ["px"] },
"unit-disallowed-list": ["px"],

Let's:

  1. change this to the shorter unit-disallowed-list
  2. run cd scripts && ./visual.sh
  3. screenshot the "Normal" terminal output
  4. optimise the resultant .png
  5. replace https://github.com/stylelint/stylelint/blob/master/example.png with it

It's shown in the README and project homepage.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, I've added this in 8e8aa2c

This applies a full rename across the repository to reflect that the
term "whitelist" is controversial in the tech community and that using
the term "allowed-list" is more explicit in it's purpose.
This is to make this rule consistent in naming with the other list based
rule names (*-allowed-list and *-disallowed-list).
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.
This replaces the declaration-property-unit-disallowed-list rule with
the shorter unit-disallowed-unit one to create a simpler example image.
@kevindew
Copy link
Contributor Author

I think we're good. The only place outside of a config where the rule names are used is within the checkAgainstRule plugin utility. It would be great if we could add a test ensuring the renamed rule is in the warning when an alias is used.

I've added that in 96acce6 with:

it('warns against a renamed rule when an aliased rule is used', () => {
const root = postcss.parse('a { top: 10px; }');
const warnings = [];
checkAgainstRule(
{
ruleName: 'unit-whitelist',
ruleSettings: ['em'],
root,
},
(warning) => warnings.push(warning),
);
expect(warnings).toHaveLength(1);
expect(warnings[0].rule).toBe('unit-allowed-list');
expect(warnings[0].line).toBe(1);
expect(warnings[0].column).toBe(10);
});

Let me know if you'd like any amends to it (I don't have much of an understanding of the code this part is testing)

Copy link
Member

@jeddy3 jeddy3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent, thank you! It all looks good to me now.

Copy link
Member

@mattxwang mattxwang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran your fork locally and looked through the code, everything looks good to me! This is a large change, thank you for all the work! LGTM!

Would like to loop in a more experienced member on the @stylelint/core team, since this is a pretty big change.

Also, have we made the PR to the stylelint.io website to add redirects for the renamed rules and/or a quick writeup explaining what we did? We'll need to do that before releasing, right?

(and update configs: https://github.com/stylelint/stylelint-config-standard
https://github.com/stylelint/stylelint-config-recommended )

@kevindew
Copy link
Contributor Author

kevindew commented Jul 3, 2020

Great stuff, yup this needs at least a changelog entry for this repo. Would that be where the write-up goes or somewhere else?

I’ve not opened any other PRs in other repos but I’ll look into sorting that out now this is on the way in.

@mattxwang
Copy link
Member

Great stuff, yup this needs at least a changelog entry for this repo. Would that be where the write-up goes or somewhere else?

At least in the CHANGELOG.md for sure, though I'd also imagine that something on the website or more user-facing would also be needed? I'm still pretty new around here, so I'd defer to @jeddy3.

I’ve not opened any other PRs in other repos but I’ll look into sorting that out now this is on the way in.

Sounds good! I can help you with some of the low-hanging but tedious fruit like the config updating!

@jeddy3
Copy link
Member

jeddy3 commented Jul 3, 2020

Also, have we made the PR to the stylelint.io website to add redirects for the renamed rules?

Not yet. It's the only thing remaining to do.

I can help you with some of the low-hanging but tedious fruit like the config updating!

@malsf21 Excellent. If you've time, would you mind rustling up a pull request for the redirects? I've created an issue for it: stylelint/stylelint.io#158

Great stuff, yup this needs at least a changelog entry for this repo.

We'll add a changelog entry just after merging. We'll tweet the release too.

@jeddy3
Copy link
Member

jeddy3 commented Jul 6, 2020

Changelog:

  • Added: *-allowed-list, *-disallowed-list and *-required-list new names for *-whitelist, *-blacklist and *-requirelist rules, respectively; the rules are aliased as their old names (#4845).

m-allanson added a commit that referenced this pull request Jul 8, 2020
# By Richard Hallows (4) and others
# Via GitHub
* master:
  Create codeql analysis workflow (#4850)
  Update CHANGELOG.md
  Add support for descriptions in stylelint command comments (#4848)
  Update CHANGELOG.md
  Add *-allowed-list/*-disallowed-list/*-required-list names for *-whitelist/*-blacklist/*-requirelist rules (#4845)
  Update CHANGELOG.md
  Add syntax object acceptance to customSyntax option (#4839)
  Bump typescript from 3.9.5 to 3.9.6 (#4853)
  Add ignoreComments[] to comment-empty-line-before (#4841)
  Bump autoprefixer from 9.8.0 to 9.8.2 (#4838)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Add new names and alias *-*list rules
3 participants