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
Fix: don't generate invalid options in config-rule #8326
Conversation
Previously, the `config-rule` logic for generating rule options had a bug where it could generate invalid options. For example, it could generate these options for the `id-match` rule: ```json [2, { "properties": true }] ``` This is invalid because the first option in `id-match` must be a string, and the second option must be an object. The config generator doesn't handle strings, but it was incorrectly skipping the string option and trying to fill in the config with an object after realizing that it couldn't generate a string. As a result, it placed the object where the string was supposed to go, so an invalid set of options was created. A similar issue can appear when generating configs for the `max-statements` rule. Luckily, the `id-match` and `max-statements` rule are still able to run when passed an invalid config, and the invalid config never results in fewer errors being reported than the default, so the invalid options wouldn't ever get output to a config file. However, this is only the case due to implementation details in the two rules, and a new rule could be introduced in the future that crashes when given an invalid schema, so this is still worth fixing. This commit fixes the issue by stopping early when the option generator reaches an option that it doesn't know how to fill in.
@not-an-aardvark, thanks for your PR! By analyzing the history of the files in this pull request, we identified @IanVS, @mysticatea and @gyandeeps to be potential reviewers. |
LGTM |
810fc72
to
ec94389
Compare
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.
Beautiful. This is exactly what I had in mind, and I'm glad that someone besides myself is getting familiar with the autoconfig logic. :) Thanks for stepping in and taking care of this.
What is the purpose of this pull request? (put an "X" next to item)
[x] Bug fix
Tell us about your environment
What did you do? Please include the actual source code causing the issue.
What did you expect to happen?
I expected all the configs in
ruleConfigs
to be valid.What actually happened? Please include the actual, raw output from ESLint.
Some of the configs were invalid. For example:
What changes did you make? (Give an overview)
Previously, the
config-rule
logic for generating rule options had a bug where it could generate invalid options. For example, it could generate these options for theid-match
rule:This is invalid because the first option in
id-match
must be a string, and the second option must be an object. The config generator doesn't handle strings, but it was incorrectly skipping the string option and trying to fill in the config with an object after realizing that it couldn't generate a string. As a result, it placed the object where the string was supposed to go, so an invalid set of options was created. A similar issue can appear when generating configs for themax-statements
rule.Luckily, the
id-match
andmax-statements
rule are still able to run when passed an invalid config, and the invalid config never results in fewer errors being reported than the default, so the invalid options wouldn't ever get output to a config file. However, this is only the case due to implementation details in the two rules, and a new rule could be introduced in the future that crashes when given an invalid schema, so this is still worth fixing.This commit fixes the issue by stopping early when the option generator reaches an option that it doesn't know how to fill in.
Is there anything you'd like reviewers to focus on?
Nothing in particular