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

Formatting of field annotations is inconsistent with GJF #316

Open
xeals opened this issue May 2, 2022 · 2 comments
Open

Formatting of field annotations is inconsistent with GJF #316

xeals opened this issue May 2, 2022 · 2 comments
Labels
formatting-discussions Discussions about how formatting should look like, when there's no clear consensus.

Comments

@xeals
Copy link

xeals commented May 2, 2022

Apologies if this is not an explicit goal, but I'm unable to find anything addressing this or not.

The Google Java Style guidelines have no preference regarding if annotations with parameters are formatted on a single or multiple lines, but Google Java Format makes the decision that if any annotation has parameters, it is formatted across multiple lines:

@Autowired @NotNull private Foo foo;
// is unchanged

@Autowired(required = false) @Nullable private Bar bar;
// becomes
@Autowired(required = false)
@Nullable
private Bar bar;

ktfmt prefers to always format annotations on a single line where they fit:

// neither are changed
@Autowired @NotNull private lateinit var foo: Foo
@Autowired(required = false) @Nullable private lateinit var bar: Bar

In mixed-language projects, this leads to inconsistency issues, particularly around declarations that often use multiple annotations with arguments (JPA, lint/warning suppressions, serialization, etc).

@xeals xeals changed the title Formatting of annotations is inconsistent with GJF Formatting of field annotations is inconsistent with GJF May 2, 2022
@cgrushko
Copy link
Contributor

cgrushko commented May 2, 2022

I think we went for one line annotations because of some idiosyncrasies in our code base. @strulovich did I remember correctly?

(Meaning, doing one per line causes some of our files to become super long)

@strulovich
Copy link
Contributor

I vaguely remember why, but we used to follow the JetBrains convention of annotations with arguments on their own line. It created a bunch of awkward constructs with some short named annotations breaking lines into many lines (Your example for bar seems to be of that style).

I'm open to looking at this again, if there's a PR I can run it on the codebase and see if it comes up awkward or not. Otherwise it may take some time until I make this PR and test it.

@hick209 hick209 added the formatting-discussions Discussions about how formatting should look like, when there's no clear consensus. label Jun 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
formatting-discussions Discussions about how formatting should look like, when there's no clear consensus.
Projects
None yet
Development

No branches or pull requests

4 participants