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

Break on lambda argument in method chain #707

Merged
merged 4 commits into from
Apr 13, 2022

Conversation

gatesn
Copy link
Contributor

@gatesn gatesn commented Apr 13, 2022

Before this PR

Chained calls involving lambda expressions don't line break, which conflicts with checkstyle (at least the gradle-baseline checkstyle config)

class PalantirLambdaInliningPrefersBreak {
    void foo() {
        return hello.read(txn -> {
                    doSomeWork();
                    doSomeMoreWork();
                })
                .chainedCall(() -> {
                    doSomeWork();
                });
    }
}

After this PR

class PalantirLambdaInliningPrefersBreak {
    void foo() {
        return hello
                .read(txn -> {
                    doSomeWork();
                    doSomeMoreWork();
                })
                .chainedCall(() -> {
                    doSomeWork();
                });
    }
}

Possible downsides?

🤷‍♂️ I've also added a test to show that non-chained lambda calls don't include a line break

@changelog-app
Copy link

changelog-app bot commented Apr 13, 2022

Generate changelog in changelog/@unreleased

Type

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

Description

Break on lambda argument in method chain

Before this PR

Chained calls involving lambda expressions don't line break, which conflicts with checkstyle (at least the gradle-baseline checkstyle config)

class PalantirLambdaInliningPrefersBreak {
    void foo() {
        return hello.read(txn -> {
                    doSomeWork();
                    doSomeMoreWork();
                })
                .chainedCall(() -> {
                    doSomeWork();
                });
    }
}

After this PR

class PalantirLambdaInliningPrefersBreak {
    void foo() {
        return hello
                .read(txn -> {
                    doSomeWork();
                    doSomeMoreWork();
                })
                .chainedCall(() -> {
                    doSomeWork();
                });
    }
}

Possible downsides?

🤷‍♂️ I've also added a test to show that non-chained lambda calls don't include a line break

Check the box to generate changelog(s)

  • Generate changelog entry

@gatesn gatesn requested a review from robert3005 April 13, 2022 08:53
@bulldozer-bot bulldozer-bot bot merged commit 843c398 into develop Apr 13, 2022
@bulldozer-bot bulldozer-bot bot deleted the ngates/break-on-lambda branch April 13, 2022 09:39
@svc-autorelease
Copy link
Collaborator

Released 2.21.0

@iamdanfox
Copy link
Contributor

@gatesn what was the specific checkstyle thing that was objecting here? I've never encountered this error personally

@robert3005
Copy link
Contributor

you can see a test case - it's a chained lambda invocation (with multi statement lambdas) of variable name that's <8 characters

@iamdanfox
Copy link
Contributor

iamdanfox commented Apr 13, 2022

DW nick slacked me. My question was because this PR said it was fixing a checkstyle rule, but didn't specific which checkstyle rule. The screenshot showed Checkstyle: 'block' child has incorrect indentation level 20, expected level should be 12/

carterkozak added a commit that referenced this pull request Apr 28, 2022
This reverts #708 and #707 which made expression lambdas less
readable.
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.

5 participants