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
Change Request: Add "did you mean" for slightly incorrect rule option keys #17364
Comments
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. |
Oops! It looks like we lost track of this issue. What do we want to do here? This issue will auto-close in 7 days without an update. |
Not stale. Waiting for feedback. cc @eslint/eslint-team |
@mdjermanovic looking for your feedback here. |
I'd be okay with this change as this improves DX. We can do either of the following:
|
I think it would be very helpful to show the additional (i.e., the unexpected) property name and the list of expected property names, even if we implement "did you mean". That alone would be a great improvement over the existing message. With that, I think "did you mean" would be a small improvement on top, so I'm not sure if it warrants adding a dependency, though I wouldn't be against adding a small dependency if other team members are in favor. |
I was curious if Ajv validation actually provides the data we need for this feature. By [
{
"keyword": "additionalProperties", // <- indicates a problem with additional properties
"dataPath": "[0]",
"schemaPath": "#/items/0/additionalProperties",
"params": {
"additionalProperty": "foo" // <- unexpected property name
},
"message": "should NOT have additional properties",
"schema": false, // <- to be sure that the problem is caused by an unexpected property name
"parentSchema": {
"type": "object",
"properties": { // <- keys of this object are expected property names
"allowImplicit": {
"type": "boolean",
"default": false
},
"checkForEach": {
"type": "boolean",
"default": false
}
},
"additionalProperties": false
},
"data": {
"foo": true,
"allowImplicit": false,
"checkForEach": false
}
}
] |
@mdjermanovic it sounds like you're in favor of just listing potential properties rather than using a dependency to calculate the possible correct property? |
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. |
That sounds good to me. Maybe we can make it a bit "smart" and suggest any properties that begin with the same letter, and otherwise, just list out all of the properties? |
Sounds good to me.
Just to clarify, I think we should always list out all of the properties. |
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. |
Oops! It looks like we lost track of this issue. What do we want to do here? This issue will auto-close in 7 days without an update. |
@mdjermanovic what do you think of my last comment? |
I think that "did you mean" is generally more useful for a large number of options, while these will usually be small. Also, listing all properties can be useful when the schema uses oneOf/anyOf as it shows what exactly failed matching. For example, consider the schema for For a config like this: {
rules: {
"prefer-destructuring": ["error", {
VariableDeclarator: {
object: true
},
array: false
}]
}
} I think it would be most useful to show an error like this:
My opinion is that the error should always show the config property that failed to match (the additional property). Then, if we are choosing between all properties of the schema object and "did you mean", I think that listing all properties would be generally more useful, though I wouldn't mind showing both all properties and "did you mean". |
So it sounds like what you're proposing is not a "did you mean" but rather just displaying all of the errors we can get from Ajv? |
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): Error: Key "rules": Key "prefer-destructuring":
Value {"VariableDeclarator":{"object":true},"array":false} should NOT have additional properties.
+ Unexpected property "array". Expected properties: "VariableDeclarator", "AssignmentExpression".
Value {"VariableDeclarator":{"object":true},"array":false} should NOT have additional properties.
+ Unexpected property "VariableDeclarator". Expected properties: "array", "object".
Value {"VariableDeclarator":{"object":true},"array":false} should match exactly one schema in oneOf. |
Ah, I see. So we'll have an additional line that we'll generate by looking at the schema and figuring out which properties should be there instead. Is there some complexity there if we have a schema using |
Oops! It looks like we lost track of this issue. What do we want to do here? This issue will auto-close in 7 days without an update. |
Ping @mdjermanovic. |
There's no additional complexity for |
Note that "did you mean" would also have to look at the schema to figure out which properties are expected. I'm only proposing that we simply list all of them instead of picking just one. |
Okay, I think we are agreed on this proposal so marking as accepted. |
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: typescript-eslint/typescript-eslint#7217
(the rule option is
ignoreAllowShorthand
- nod
afterignore
)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...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
Additional comments
I applied a similar fix to pnpm: pnpm/pnpm#6492 -> pnpm/pnpm#6496
The text was updated successfully, but these errors were encountered: