eslint icon indicating copy to clipboard operation
eslint copied to clipboard

feat: Support custom severity when reporting unused disable directives

Open bmish opened this issue 2 years ago • 5 comments

Prerequisites checklist

What is the purpose of this pull request? (put an "X" next to an item)

[ ] Documentation update [ ] Bug fix (template) [ ] New rule (template) [ ] Changes an existing rule (template) [ ] Add autofix to a rule [X] Add a CLI option [ ] Add something to the core [ ] Other, please explain:

What changes did you make? (Give an overview)

Implements phase 1 (non-breaking changes) of this RFC:

  • https://github.com/eslint/rfcs/pull/100

That includes:

  • Changes the reportUnusedDisableDirectives option in config files to support severity strings (new behavior) in addition booleans (existing behavior)
  • Adds a new CLI option --report-unused-disable-directives-severity <severity>, in addition to the existing CLI option --report-unused-disable-directives (untouched)

This allows customizing the severity with which unused disabled directives are reported.

TODO:

  • [ ] Wait for RFC to be merged. This is a draft PR until the RFC is merged.
  • [ ] Ensure severity numbers (0, 1, 2) are supported everywhere

Fixes #15466.

Is there anything you'd like reviewers to focus on?

bmish avatar May 23 '23 22:05 bmish

Deploy Preview for docs-eslint ready!

Name Link
Latest commit ddf9aa2e699789df7a9c2e110209f1e1e0d7218e
Latest deploy log https://app.netlify.com/sites/docs-eslint/deploys/6579e18476c1510008d37e0b
Deploy Preview https://deploy-preview-17212--docs-eslint.netlify.app/use/configure/migration-guide
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

netlify[bot] avatar May 23 '23 22:05 netlify[bot]

Hi everyone, it looks like we lost track of this pull request. Please review and see what the next steps are. This pull request will auto-close in 7 days without an update.

github-actions[bot] avatar Jun 08 '23 22:06 github-actions[bot]

Hi everyone, it looks like we lost track of this pull request. Please review and see what the next steps are. This pull request will auto-close in 7 days without an update.

github-actions[bot] avatar Jun 19 '23 22:06 github-actions[bot]

@bmish what's the status on this?

nzakas avatar Jun 20 '23 17:06 nzakas

I need to address some feedback still, but this is ready for review. The RFC https://github.com/eslint/rfcs/pull/100 has been approved and will be merged soon, and this PR is not a breaking change, so we should be able to move forward with it once the review process is completed.

bmish avatar Jun 21 '23 13:06 bmish

Hi everyone, it looks like we lost track of this pull request. Please review and see what the next steps are. This pull request will auto-close in 7 days without an update.

github-actions[bot] avatar Jul 01 '23 22:07 github-actions[bot]

Preparing for v9, so leaving this open.

nzakas avatar Jul 11 '23 15:07 nzakas

@bmish looking for some changes on this. Can you please take a look?

nzakas avatar Nov 30 '23 21:11 nzakas

@nzakas @mdjermanovic finally got this working, feedback addressed, and the tests passing.

The goal is still to release this in a minor version of ESLint v8, pending a thorough review to ensure everything looks good. This change is focused on adding support for severity strings without changing defaults.

After that, I can open another PR to change the default for flat config users to warn, also suitable for a minor version of ESLint v8 since flat config is not yet considered stable.

bmish avatar Dec 03 '23 02:12 bmish

Responded to all comments again. Thanks for the helpful comments.

bmish avatar Dec 03 '23 17:12 bmish

  • For simplicity, I've limited this to severity strings for now. We can add support for severity numbers now or later as needed.

If we're going to support severity numbers, I think it would be best to support them from the start (this PR).

I'm not sure if we'd like to make any further changes in the ESLint class, so its constructor option could keep accepting only strings. We could just translate numbers into strings in cli.js, in the code path that uses the ESLint class (around here).

As for the flat config array, it would make sense to normalize the value of linterOptions.reportUnusedDisableDirectives in calculated configs, either while merging configs or in finalizeConfig. Since rule severities are normalized to numbers, perhaps linterOptions.reportUnusedDisableDirectives should be normalized to a number as well?

mdjermanovic avatar Dec 04 '23 13:12 mdjermanovic

@mdjermanovic I added support for number severities. I haven't yet documented numbers being supported everywhere. Let me know where you think it needs to be documented. I'm a bit unclear if we actually want to encourage and support number severities long-term.

I am currently normalizing severities to strings since the reportUnusedDisableDirectives option originally used strings. Let me know if you think it's easy or necessary to change to using numbers under the hood now.

bmish avatar Dec 04 '23 17:12 bmish