eslint: Change Request: Add "did you mean" for slightly incorrect rule option keys
ESLint version
8.44.0
What problem do you want to solve?
Right now, if a user slightly typos a rule option name, the error message is the same as if they used a completely unknown option. Example: https://github.com/typescript-eslint/typescript-eslint/issues/7217
Error: .eslintrc.js:
Configuration for rule "@typescript-eslint/no-confusing-void-expression" is invalid:
Value {"ignoredArrowShorthand":true} should NOT have additional properties.
(the rule option is ignoreAllowShorthand
- no d
after ignore
)
I know I’ve made this mistake plenty of times before and spent multiple minutes squinting at the screen. It would be nice if ESLint used something like didyoumean2
to detect when there’s a small edit distance to an existing option. It could then give an improved message like, maybe…
Error: .eslintrc.js:
Configuration for rule "@typescript-eslint/no-confusing-void-expression" is invalid:
Value {"ignoredArrowShorthand":true} should NOT have additional properties.
Did you mean "ignoreArrowShorthand"?
What do you think is the correct solution?
Seems like a straightforward win to me? See #17056 for another “did you mean?” change request - though that one’s on options shapes, not string keys.
Participation
- I am willing to submit a pull request for this change.
Additional comments
I applied a similar fix to pnpm: https://github.com/pnpm/pnpm/issues/6492 -> https://github.com/pnpm/pnpm/pull/6496
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 4
- Comments: 23 (20 by maintainers)
Okay, I think we are agreed on this proposal so marking as accepted.
Sounds good to me.
Just to clarify, I think we should always list out all of the properties.
No, in this case we’re already displaying multiple errors.
This is what we’re currently displaying for the config from my previous comment:
Now, I’ll just add a linebreak for diff clarity (we should probably format these messages better regardless of this issue):
The proposal is to display additional info below each error that relates to additional properties (I believe this is what @JoshuaKGoldberg is proposing too, just different data):
If we’re always going to list out all properties then I don’t see any reason to also show properties beginning with the same letter. My goal was to shorten and simplify the output, but outputting everything all the time negates that benefit.
Yes. I think we should list potential properties either way, and that alone will be a significant improvement in these messages. Additionally suggesting which of them is probably the right one would then be a small addition that maybe isn’t worth adding a new dependency.
I was curious if Ajv validation actually provides the data we need for this feature. By
validateRule.errors
for a test configuration"array-callback-return": ["error", { "foo": true }]
, it seems doable:We’ve been actively trying to remove extra dependencies from ESLint, and I’m not sure there’s a big enough value-add here to take on another dependency. I’ll leave this open to get feedback from others on the team.