Skip to content
This repository was archived by the owner on Nov 20, 2024. It is now read-only.

Detect doubled unnecessary_parenthesis, but allow ternary and equality #3887

Merged
merged 3 commits into from
Jan 24, 2023

Conversation

oprypin
Copy link
Contributor

@oprypin oprypin commented Dec 7, 2022


This implements new rules for unnecessary_parenthesis lint:

  • ${( )} and (( )) are never OK, drop the inner ones

else,

  • (a ? b : c) is always OK
  • (a == b) and (a != b) are OK in assignment-like and return-like statements.

This pull request addresses two seemingly completely separate changes, but I think it should be done all at once. That is because:

  • Currently some cases where doubled parentheses happen to be dropped are cases of ((a == b)) etc. So I'd be introducing more false negatives if I remove the old reason to drop these but not add the new one.

  • Removing doubled parentheses just misses one case of ArgumentList so it's unclear why I am adding all the other numerous cases here. But more rules are necessary only because they will become the only reason for some cases of ((a ? b : c)) to still be dropped.

This implements new rules for `unnecessary_parenthesis` lint:
* `${(  )}` and `((  ))` are never OK, drop the inner ones
else,
* `(a ? b : c)` is always OK
* `(a == b)` and `(a != b)` are OK in assignment-like and return-like statements.
@coveralls
Copy link

coveralls commented Dec 8, 2022

Coverage Status

Coverage increased (+0.02%) to 95.657% when pulling 20835a8 on unnecessary_parenthesis_ternary into 79b8433 on main.

Copy link
Contributor

@bwilkerson bwilkerson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to address these comments until we've decided whether we want to make all of the changes.

@oprypin oprypin requested a review from pq January 18, 2023 12:42
@pq pq merged commit 43ac194 into main Jan 24, 2023
@pq pq deleted the unnecessary_parenthesis_ternary branch January 24, 2023 22:54
copybara-service bot pushed a commit to dart-lang/sdk that referenced this pull request Aug 23, 2023
dart-archive/linter#3887)

* Detect doubled unnecessary_parenthesis, but allow ternary and equality

This implements new rules for `unnecessary_parenthesis` lint:
* `${(  )}` and `((  ))` are never OK, drop the inner ones
else,
* `(a ? b : c)` is always OK
* `(a == b)` and `(a != b)` are OK in assignment-like and return-like statements.

* More cases of doubled parentheses and exemptions for equality
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
4 participants