feat: Support custom severity when reporting unused disable directives
Prerequisites checklist
- [x] I have read the contributing guidelines.
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
reportUnusedDisableDirectivesoption 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?
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...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site configuration.
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.
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.
@bmish what's the status on this?
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.
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.
Preparing for v9, so leaving this open.
@bmish looking for some changes on this. Can you please take a look?
@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.
Responded to all comments again. Thanks for the helpful comments.
- 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 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.