Skip to content
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

Implement BracesRequired error-prone check with suggested fixes #1130

Merged
merged 4 commits into from
Dec 18, 2019

Conversation

carterkozak
Copy link
Contributor

@carterkozak carterkozak commented Dec 18, 2019

Before this PR

No automatic fix for missing braces.

After this PR

==COMMIT_MSG==
Implement BracesRequired error-prone check with suggested fixes

- if (condition) statement;
+ if (condition) {
+   statement;
+ }

==COMMIT_MSG==

Possible downsides?

None, we already validate this using the default checkstyle configuration. The new check allows our automation to fix projects that don't yet comply.

```diff
- if (condition) statement;
+ if (condition) {
+   statement;
+ }
```
@changelog-app
Copy link

changelog-app bot commented Dec 18, 2019

Generate changelog in changelog/@unreleased

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

Implement BracesRequired error-prone check with suggested fixes

- if (condition) statement;
+ if (condition) {
+   statement;
+ }

Check the box to generate changelog(s)

  • Generate changelog entry

@policy-bot policy-bot bot requested a review from ferozco December 18, 2019 18:15
@chrismale
Copy link

Can we support the 'statement' being on the immediate line beneath the if?

@carterkozak
Copy link
Contributor Author

Can we support the 'statement' being on the immediate line beneath the if?

Yep, the auto-formatter takes care of that, we only need to build the right AST here :-)

@chrismale
Copy link

Fantastic.

public Description matchIf(IfTree tree, VisitorState state) {
check(tree.getThenStatement(), state);
check(tree.getElseStatement(), state);
return Description.NO_MATCH;
Copy link
Contributor

Choose a reason for hiding this comment

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

seems a little odd to always return NO_MATCH and rely on a side effect of check to actually do the fix

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, it's a bit odd. It allows us to keep the code cleaner and reusable without creating potentially unnecessary SuggestedFix.Builder objects for every conditional and loop. Several of the upstream checks are structured similarly.

@ferozco
Copy link
Contributor

ferozco commented Dec 18, 2019

👍 programming at scale

@bulldozer-bot bulldozer-bot bot merged commit a0f9d09 into develop Dec 18, 2019
@bulldozer-bot bulldozer-bot bot deleted the ckozak/BracesRequired branch December 18, 2019 18:51
@svc-autorelease
Copy link
Collaborator

Released 2.45.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants