/ eslint Public
no-unneeded-ternary incorrect documentation for defaultAssignment option #12098
There is consensus among the team that this change meets the criteria for inclusion
archived due to age
This issue has been archived; please open a new issue for any further discussion
ESLint is working incorrectly
Relates to ESLint's documentation
Relates to ESLint's core rules
This is a "documentation bug".
The version of ESLint you are using.
The problem you want to solve.
defaultAssignmentoption of the
no-unneeded-ternaryrule is incorrect.
defaultAssignment = truemeans don't report expressions such as
x ? x : y.
defaultAssignment = falsemeans report expressions such as
x ? x : y.
The rule doesn't actually check if the expression is in an assignment context. That's by design from the start (#3232 and #3260). It simply searches for all ternary expressions where test and consequent are same identifier.
Incorrect parts of the documentation are:
The example is wrong,
var a = f(x ? x : 1);is not a warning because of the default option value.
The comment is wrong.
The option (when
true) allows such expressions everywhere.
Your take on the correct solution to problem.
Fix the documentation.
Perhaps also consider changing the name of the option for two reasons: The
Assignmentpart is confusing.
When the option name doesn't have an explicit prefix,
trueususally means "enforce on", rather than "allow".
Are you willing to submit a pull request to implement this change?
Yes, I would be glad to do it.
The text was updated successfully, but these errors were encountered: