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

Add support for descriptions in stylelint command comments #4840

Closed
glen-84 opened this issue Jun 24, 2020 · 9 comments · Fixed by #4848
Closed

Add support for descriptions in stylelint command comments #4840

glen-84 opened this issue Jun 24, 2020 · 9 comments · Fixed by #4848
Labels
status: wip is being worked on by someone type: enhancement a new feature that isn't related to rules

Comments

@glen-84
Copy link
Contributor

glen-84 commented Jun 24, 2020

What is the problem you're trying to solve?

Describing/justifying disable directives, so that they aren't used unless necessary, and other developers know why they were used.

What solution would you like to see?

See the equivalent in ESLint:

Example:

a {
    // stylelint-disable-next-line declaration-no-important -- A really good reason here.
    color: red !important;
}
@jeddy3 jeddy3 changed the title Description in directive comments Add support for descriptions in stylelint command comments Jun 26, 2020
@jeddy3 jeddy3 added status: ready to implement is ready to be worked on by someone type: enhancement a new feature that isn't related to rules labels Jun 26, 2020
@jeddy3
Copy link
Member

jeddy3 commented Jun 26, 2020

@glen-84 Thanks for the request and for using the template.

Mimicking the ESLint implementation sounds good to me, i.e. the reason must come after --.

The feature offers an optional, convenient and consistent way for authors to describe the reason for using a disable command. It is a better solution than the old stylelint-disable-reason rule that was deprecated in 8.0.0, as it sits outside of the sphere of rules.

I've labelled the issue as ready to implement. Please consider contributing if you have time.

@glen-84
Copy link
Contributor Author

glen-84 commented Jun 27, 2020

Is it sufficient to add the 3rd line here:

const rules = fullText
    .slice(command.length)
    .split('--')[0].trim() // Allow for description (f.e. /* stylelint-disable a, b -- Description */).
    .split(',')
    .filter(Boolean)
    .map((r) => r.trim());

in getCommandRules?

Assumptions:

  • Commands will not include two successive hyphens.
  • Rule names will not include two successive hyphens.

If so, how many/what tests should be written?

@jeddy3
Copy link
Member

jeddy3 commented Jun 28, 2020

Is it sufficient to add the 3rd line here

I suspect it will be.

Assumptions:

Those assumptions are correct. You should add an explicit warning about double hyphens to the rule docs as part of the pull request.

If so, how many/what tests should be written?

Write as many tests as you need to feel confident that the feature works as expected.

You want to add:

  • unit test assigning disable range here
  • a couple of integration tests here

For example, you'll want to test that */ stylelint-disable foo-bar -- baz-maz */ assigns a disable range for foo-bar, but not baz-maz.

@ota-meshi
Copy link
Member

Note that eslint does not interpret it as a description if there is no whitespace before or after the hyphen.

@glen-84
Copy link
Contributor Author

glen-84 commented Jun 28, 2020

Is it necessary to have that limitation?

I could change it to .split(' -- ')[0].trim() (note the space on either side), which would also mean that rules could then (in theory) include double hyphens.

Edit: Actually this might be the better option.

@ota-meshi
Copy link
Member

I have checked the eslint source code.
If you want the exact same specifications as eslint, use the following regular expression.

.split(/\s-{2,}\s/u)[0].trim()

https://github.com/eslint/eslint/blob/51e42eca3e87d8259815d736ffe81e604f184057/lib/linter/linter.js#L276

If you use this, the following comments are probably also valid:

/* stylelint-disable rule-name
----------
description */

@jeddy3 jeddy3 added status: wip is being worked on by someone and removed status: ready to implement is ready to be worked on by someone labels Jul 6, 2020
@nex3
Copy link
Contributor

nex3 commented Jul 30, 2020

It looks like this isn't working on stylelint.io/demo. Is that just because the demo site uses an out-of-date version of stylelint?

@glen-84
Copy link
Contributor Author

glen-84 commented Jul 30, 2020

@nex3 There hasn't been a release since the feature was merged.

@nex3
Copy link
Contributor

nex3 commented Jul 30, 2020

Ah, gotcha! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: wip is being worked on by someone type: enhancement a new feature that isn't related to rules
Development

Successfully merging a pull request may close this issue.

4 participants