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
feat: add rule test deprecation warnings: fn-style rules/missing schema #15761
feat: add rule test deprecation warnings: fn-style rules/missing schema #15761
Conversation
Hi @bmish!, thanks for the Pull Request The first commit message isn't properly formatted. We ask that you update the message to match this format, as we use it to generate changelogs and automate releases.
To Fix: You can fix this problem by running Read more about contributing to ESLint here |
cc83a0c
to
2a547ca
Compare
I think it isn't necessary to add deprecation warnings to FlatRuleTester if we are planning eslint/rfcs#85 for ESLint v9, as FlatRuleTester won't be used in production before ESLint v9, |
2a547ca
to
763b994
Compare
@mdjermanovic that's fair. Should I just remove the changes to |
Is it necessary to have these checks in RuleTester in the next major version? Per the RFC, they will be implemented in the core. If it throws anyways, it seems we don't need to duplicate checks in RuleTester. |
@mdjermanovic good point, removed from flat rule tester. |
If it helps, we have some deprecation warnings in eslintrc and the tests are here. But there we're using |
I added tests for However, it looks like |
// eslint-disable-next-line no-console -- needed for temporary deprecation warning before this is converted into an assert | ||
console.warn("DEPRECATION WARNING: This test case specifies `options` but the rule is missing `meta.schema` and will stop working in ESLint v9. Please add `meta.schema`: https://eslint.org/docs/developer-guide/working-with-rules#options-schemas This lint rule can assist with the conversion: https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/main/docs/rules/require-meta-schema.md"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assumes that the warning message will be logged right after the test title, but that doesn't have to be the case.
For example, if you run mocha with -R progress
, it would look like this:
[▬▬..........................................................................]DEPRECATION WARNING: This test case specifies `options` but the rule is missing `meta.schema` and will stop working in ESLint v9. Please add `meta.schema`: https://eslint.org/docs/developer-guide/working-with-rules#options-schemas This lint rule can assist with the conversion: https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/main/docs/rules/require-meta-schema.md
[▬▬▬.........................................................................]DEPRECATION WARNING: This test case specifies `options` but the rule is missing `meta.schema` and will stop working in ESLint v9. Please add `meta.schema`: https://eslint.org/docs/developer-guide/working-with-rules#options-schemas This lint rule can assist with the conversion: https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/main/docs/rules/require-meta-schema.md
DEPRECATION WARNING: This test case specifies `options` but the rule is missing `meta.schema` and will stop working in ESLint v9. Please add `meta.schema`:
https://eslint.org/docs/developer-guide/working-with-rules#options-schemas This lint rule can assist with the conversion: https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/main/docs/rules/require-meta-schema.md
[▬▬▬▬........................................................................]DEPRECATION WARNING: This test case specifies `options` but the rule is missing `meta.schema` and will stop working in ESLint v9. Please add `meta.schema`: https://eslint.org/docs/developer-guide/working-with-rules#options-schemas This lint rule can assist with the conversion: https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/main/docs/rules/require-meta-schema.md
[▬▬▬▬▬.......................................................................]DEPRECATION WARNING: This test case specifies `options` but the rule is missing `meta.schema` and will stop working in ESLint v9. Please add `meta.schema`: https://eslint.org/docs/developer-guide/working-with-rules#options-schemas This lint rule can assist with the conversion: https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/main/docs/rules/require-meta-schema.md
DEPRECATION WARNING: This test case specifies `options` but the rule is missing `meta.schema` and will stop working in ESLint v9. Please add `meta.schema`:
https://eslint.org/docs/developer-guide/working-with-rules#options-schemas This lint rule can assist with the conversion: https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/main/docs/rules/require-meta-schema.md
...
The problem is that there's no info about which rule is the cause of the warnings. We could add ruleName
to the message. Also, it might be good to log the warning only once per rule (not for each test case that has options
)?
if (hasOwnProperty(item, "options")) { | ||
assert(Array.isArray(item.options), "options must be an array"); | ||
if (!rule.schema) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we shouldn't log the warning if item.options
is an empty array, as that's basically the same as if no options had been passed.
As for |
@bmish are you still working on this? If not, can I take over this PR? |
@snitin I definitely want to see this work completed. If you want to attempt it, could you open a separate PR to do so? If I can find time to continue on my PR, I'll post here. |
Closing in favor of #16063. |
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
[ ] Add a CLI option
[X] Add something to the core
[ ] Other, please explain:
What changes did you make? (Give an overview)
Prepares for upcoming breaking changes in ESLint v9 to disallow function-style rule and rules with options that are missing a schema.
Adds the deprecation warnings mentioned in the RFC (eslint/rfcs#85).
These deprecation warnings will help alert plugin authors that they need to update their rules. They are only visible when running rule tests and not to end-users who just use the rules.
Is there anything you'd like reviewers to focus on?
Is simply replicating these in flat rule tester right for now? How can I manually test the flat rule tester? I manually tested the normal rule tester.See comments.process.emitWarning()
(see comments)?