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
no-useless-undefined - should not be fixable #760
Comments
I suggest we just ignore |
Why |
There are many functions that behave differently when they receive an explicit undefined. const logResultsAndExit = (...args: unknown[]) => {
if (args.length === 0) {
throw Error('missing args')
}
console.log(...args)
process.exit()
}
// Before fix
logResultsAndExit(undefined) // works
// After fix
logResultsAndExit() // throws at runtime A more likely example, with jest: expect(someValue).toEqual(undefined) The above works ok without the rule. With it, it'll be fixed to I accept that it's usually not a good design, but 1) it's not always in our control - maybe we didn't write the function, we're just using it and 2) that's why there's a lint rule for this. It's ok to discourage accidental reliance on bad design, and even to suggest a fix, but it's not ok to change the runtime behaviour with an auto-fix. |
The The arguments length case need discuss. |
#758 looks like a fine workaround for jest. But it won't be possible to whitelist all legitimate/necessary usages of explicit The simplest way I can put it is - the rule is currently going against this guidance from the eslint docs:
|
As far as I can tell, almost every auto-fix breaks some edge cases. |
I don't think that's true. And if they do, they should be reported as bugs and fixed! This is exactly what the suggest API is for, so I don't really understand the resistance. A styleguide rule should not be able to silently introduce subtle rutime-only bugs into a program. |
Simple, any code changes inside function effect Take some of our rules,
|
|
I agree with this, I think using a whitelist is risky. Since I can't think of a better option, I am also in favor of downgrading to a suggestion. Of course, the whitelist could be kept, in order to not even suggest in the known situations and improve developer experience. |
That's just unrealistic in practice. Yes, it's something to strive for, but if we were to do this 100%, I don't think any rule could have an auto-fix as there are always edge-cases that are impossible to statically detect. |
Fair enough that we can't expect to succeed in never making runtime behaviour changes. But in this case, I think there's a pretty reasonable chance that automatically deleting a parameter will have a real side-effect. Which is related to another reason this shouldn't auto-fix IMO: unlike most autofix rules like So while it's an edge case for the set of all function calls that Anyway, I'll shut up now - it's not that big a deal 🙃 |
I think @mmkal is right... I think it is very likely that someone wrote |
In this specific example, I agree too. |
What do you prefer?
Or better solution? original post in #807 (comment) |
Yes, an option to ignore function parameters. |
As it stands, the rule corrects
console.log(undefined)
toconsole.log()
. These have different runtime behaviour, so it isn't safe to autofix. The fixer should be downgraded to a suggestion.The text was updated successfully, but these errors were encountered: