-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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-unneeded-ternary incorrect documentation for defaultAssignment option #12098
no-unneeded-ternary incorrect documentation for defaultAssignment option #12098
Comments
I'm not against renaming the option if we do so in a backwards compatible way. |
Perhaps to make this issue be just a task to fix the documentation (if confirmed that it's incorrect) ? I could open another issue to evaluate renaming. |
@mdjermanovic Now that you're a team member, if you can verify this is a bug you can feel free to mark it as accepted! |
I would like to make the doc change. I will verify at the same time |
@samrae7 Thanks, a PR to fix the documentation is welcome! |
Marking as accepted based on this Online Demo The code is copy & paste from the 'incorrect' example in the docs. In this example, the rule doesn't report error for the third statement. To avoid confusion, I removed the part about changing the option's name from the original post. This is now just an issue to fix the docs to match the current behavior. |
This is a "documentation bug".
The version of ESLint you are using.
6.1.0
The problem you want to solve.
Documentation for
defaultAssignment
option of theno-unneeded-ternary
rule is incorrect.defaultAssignment = true
means don't report expressions such asx ? x : y
.defaultAssignment = false
means report expressions such asx ? x : y
.Default is
true
.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:
incorrect
example:The example is wrong,
var a = f(x ? x : 1);
is not a warning because of the default option value.correct
example: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:TheAssignment
part is confusing.When the option name doesn't have an explicit prefix,true
ususally means "enforce on", rather than "allow".MaybeallowSameConsequent
orallowSameIfTrue
.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: