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 more disable error configuration #5143

Merged
merged 8 commits into from Feb 19, 2021
Merged

Add more disable error configuration #5143

merged 8 commits into from Feb 19, 2021

Conversation

nex3
Copy link
Contributor

@nex3 nex3 commented Feb 12, 2021

This makes it possible to add exceptions to disable errors, and to
configure their severity, using the same syntax as is used for lint rules.

This makes it possible to refer to more specific parameter types when
they're known. It also means that it doesn't always just reduce to
"any".
This makes it possible to add exceptions to disable errors, and to
configure their severity, using the same syntax as is used for lint
rules.
@nex3 nex3 requested review from jathak and jeddy3 February 12, 2021 02:02
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.

@nex3 Thank you. It's a significant improvement to the reporting feature.

It's fantastic you could do this in a non-breaking way. It's also great that you were able to carry over the except pattern from the rules.

What's the CLI report* flags behaviour, i.e. does the presence of a flag set the primary option to true regardless of what's in the configuration object?

What are your thoughts on parity between the CLI flags and the configuration object, i.e. being able to specify primary and secondary options on the CLI, as the benchmarking tool does? My gut feeling is that we should move towards a configuration-object-first approach, and only add CLI flags where there's a concrete use case to justify the added complexity.

Lastly, two tests are failing:

 ● warns that the rule is deprecated

    expect(received).toHaveLength(expected)

    Expected length: 1
    Received length: 0
    Received array:  []

      16 |              const result = output.results[0];
      17 | 
    > 18 |              expect(result.deprecations).toHaveLength(1);
         |                                          ^
      19 |              expect(result.deprecations[0].text).toEqual(
      20 |                      `'${ruleName}' has been deprecated. Instead use 'property-allowed-list'.`,
      21 |              );

      at lib/rules/property-whitelist/__tests__/index.js:18:31

Test Suites: 1 failed, 1 total
Tests:       1 failed, 27 passed, 28 total

And the same for the property-blacklist rule. It fails locally for me too. Strangely, the failing tests seem unrelated to this pull request's changes. My only thought is that result is now being mutated somewhere and that both rules starting with "property" has something to do with it. On a quick scan through, I couldn't see where a mutation might happen, though.

These properties were being configured with the value `[]`, which we
newly interpret as "unset" rather than "set to the empty list". This
distinction doesn't matter in general, but it does mean that the rules
won't be flagged as deprecated.
@nex3
Copy link
Contributor Author

nex3 commented Feb 17, 2021

What's the CLI report* flags behaviour, i.e. does the presence of a flag set the primary option to true regardless of what's in the configuration object?

Yes, exactly that. The CLI totally overrides the config file.

What are your thoughts on parity between the CLI flags and the configuration object, i.e. being able to specify primary and secondary options on the CLI, as the benchmarking tool does? My gut feeling is that we should move towards a configuration-object-first approach, and only add CLI flags where there's a concrete use case to justify the added complexity.

I agree with your gut. I don't think it's worth trying to add more JSON-parsing on the command line, especially since adding arguments to a flag that historically hasn't taken any is tricky from a compatibility standpoint.

Lastly, two tests are failing:

 ● warns that the rule is deprecated

    expect(received).toHaveLength(expected)

    Expected length: 1
    Received length: 0
    Received array:  []

      16 |              const result = output.results[0];
      17 | 
    > 18 |              expect(result.deprecations).toHaveLength(1);
         |                                          ^
      19 |              expect(result.deprecations[0].text).toEqual(
      20 |                      `'${ruleName}' has been deprecated. Instead use 'property-allowed-list'.`,
      21 |              );

      at lib/rules/property-whitelist/__tests__/index.js:18:31

Test Suites: 1 failed, 1 total
Tests:       1 failed, 27 passed, 28 total

And the same for the property-blacklist rule. It fails locally for me too. Strangely, the failing tests seem unrelated to this pull request's changes. My only thought is that result is now being mutated somewhere and that both rules starting with "property" has something to do with it. On a quick scan through, I couldn't see where a mutation might happen, though.

Looks like this was because the rules were being configured in those tests with the value [], which the revamped rule setting normalization now interprets as "unset". I fixed the settings so this should now work.

@jeddy3
Copy link
Member

jeddy3 commented Feb 17, 2021

Looks like this was because the rules were being configured in those tests with the value [], which the revamped rule setting normalization now interprets as "unset".

Thank you for digging into this.

[] is a valid configuration for the *list as they set this flag:

rule.primaryOptionArray = true;

For the *-disallowed rules, [] is almost equivalent to unsetting; it won't trigger the deprecating warning, though. However, [] for the *-allowed rules means allow nothing, which is how a user can, for example, disallow all attribute selector operators.

Can the revamped rule setting normalisation take this into account somehow?

We mimicked ESLint's configuration structure, but in hindsight, we should've avoided array-based options as they're problematic.


Lint is failing on the TypeScript checks:

 Error: lib/invalidScopeDisables.js(19,23): error TS2532: Object is possibly 'undefined'.

@nex3
Copy link
Contributor Author

nex3 commented Feb 17, 2021

Fixed and fixed!

@jeddy3
Copy link
Member

jeddy3 commented Feb 17, 2021

Fixed and fixed!

Thank you. Conceptually everything looks great, and I think the pull request is ready for code reviews.

Copy link
Contributor

@jathak jathak left a comment

Choose a reason for hiding this comment

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

LGTM

};

export type DisableOptions = {
except?: Array<string | RegExp>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to add a test where this is a regex? Or is this sufficiently covered by existing tests for optionsMatches?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like other rules that allow RegExps don't explicitly test them, so I think it's probably covered.

@nex3 nex3 requested a review from jeddy3 February 18, 2021 20:57
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.

LGTM, thanks!

I should be able to make time to do a release over the weekend. I believe @jathak has access to the stylelint npm (and can add you if you like) if you want to release before then.

@jeddy3 jeddy3 mentioned this pull request Feb 19, 2021
6 tasks
@nex3 nex3 merged commit a48f2ae into master Feb 19, 2021
@nex3 nex3 deleted the disable-config branch February 19, 2021 22:15
@jeddy3
Copy link
Member

jeddy3 commented Feb 20, 2021

  • Added: exceptions and severity options to report* configuration object properties (#5143).

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.

None yet

3 participants