-
Notifications
You must be signed in to change notification settings - Fork 1.7k
unnecessary_parenthesis sometimes not reported for doubled parentheses #58952
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
Comments
I would assume that any pair of parentheses that doesn't change the semantics of the code is 'unnecessary' and that that's what this lint should flag. There is some evidence, however, that that might be too strict. I think we need to start by defining what this lint is expected to do, and then fix the implementation to match. |
I think there is a lot of evidence that that is too strict. The general consensus is that it would be asking too much to expect every reader of code to know the precedence table. I'm seeing parallels in our other internal linters for JavaScript and Java, and in previous discussions for Dart. In particular there are surprises, like some of the test cases for this rule. Here's one example: var x = (1==1 ? [] : [])..add(7);
var y = 1==1 ? [] : []..add(7); Do the parentheses in the first statement change the semantics? Does
That expectation is spelled out here: https://dart-lang.github.io/linter/lints/unnecessary_parenthesis.html I believe the "double parentheses" examples above represent a mismatch with this expectation, and are thus bugs. |
The problem I have with that expectation statement is that there's not definition of what's covered by "improve the readability of the code". While I don't necessarily object to some of the requested relaxations, I have no idea, other than my own personal taste, of whether to say yes or no to a given relaxation. (That isn't what this issue is about, but still.)
Yes, because the parentheses don't "change the meaning of the code". And I agree that they don't improve readability either. Given that I don't disagree that these are reasonable to catch, I probably shouldn't have said anything. I was too influenced by the related issue (#3886) and trying to answer the question of how far to relax the rule. |
@bwilkerson I think your [first] comment is a call to completely stall this lint unless someone is willing to take it up as their main job. The comment also doesn't seem to talk about this particular issue but rather something general. But I am not talking about something general or controversial. If one writes
I am defining the clearest and highest-priority rule that this lint has ever had, even if it's just 1 rule. |
To clarify, by "highest priority" I mean that the rule could be applied before any other rules and short-circuit the following logic |
Like I said, "I probably shouldn't have said anything". |
Yeah that's really fair. The devil is in the details, and even with a rule in my hand about operators-with-whitespace, or something similar, if you presented me with 10 different cases, I might not give a consistent answer about whether I think the whitespace is unnecessary. |
Some examples of what it currently misses but should lint:
So I would like to introduce a rule that
${( )}
and(( ))
are never OK, drop the inner ones.It's just that it's a bit tricky to find in the language what exactly constitutes these doubled parentheses. For example:
ArgumentList
with length of 1 is always an extra set of parentheses(which already covers almost all bad cases for this issue).
if
statement, but somehow I can't trigger any false negative with it.I will immediately open a pull request that would address this issue.
The text was updated successfully, but these errors were encountered: