question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Blank line removed after class declaration

See original GitHub issue

This might be done on purpose, but I’m opening this issue to be able to discuss it. Before:

public class JWTFilter extends GenericFilterBean {

    public static final String AUTHORIZATION_HEADER = "Authorization";

    private TokenProvider tokenProvider;

After:

public class JWTFilter extends GenericFilterBean {
    public static final String AUTHORIZATION_HEADER = "Authorization";

    private TokenProvider tokenProvider;

I think it would be more readable to add/keep the extra line.

In the following example it’s hard to distinguish between the end of the class declaration (and its superclass and interfaces) and the first field:

public class MyLoooooongClass
    extends AbstractAuditingEntity
    implements Serializable, MyInterface<AAAAAAA, BBBBBBBBBBB> {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)

Also if the first “content” of the class is an inner class the blank line is added:

 /**
 * some javadoc
 */
public class MyEntityCriteria implements Serializable, Criteria {

    /**
     * Class for filtering MyEntity
     */
    public static class MyEntityFilter extends Filter<MyEntity> {

        public MyEntityFilter() {}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
mmadsoncommented, Sep 1, 2020

Are there plans to merge #398 ? This particular issue has me on the fence about adopting prettier for our java project.

2reactions
jhabercommented, Dec 12, 2019

@murdos Do you think we should always add a blank line at the beginning of class bodies and interfaces bodies ?

What about the end of a class? It usually contains a method, so after formatting there is no blank line between the ending } of the method and the ending }of the class.

I don’t think adding a newline between the last method and end of class is a common style so I would advocate for prettier not doing it.

In terms of adding a newline at the beginning of a class, I think there are definitely cases where this improves readability. And in the cases where it doesn’t seem necessary, it doesn’t actively harm readability (it’s just a minor annoyance that people will get used to). So I would be in favor of keeping the behavior simple/predictable and unconditionally adding a newline at the beginning of a class declaration

Read more comments on GitHub >

github_iconTop Results From Across the Web

Excess blank lines inside and after a class declaration are not ...
Excess blank lines inside and after a class declaration are not removed ... You can adjust minimum number of blank lines around methods...
Read more >
How can I suppress the addition of a blank new line after the ...
1 Answer 1 ... In settings: Editor|Code Style|Java on the 'Blank Lines' tab you probably have 'After class header' set to 1. Change...
Read more >
Fix coding Standard - There must be no blank line following ...
There must be no blank line following an inline comment Remove that blank line which are not as per coding standard.
Read more >
Google Java Style Guide
Line break after the closing brace, only if that brace terminates a statement or terminates the body of a method, constructor, or named...
Read more >
Rationale - Prettier
…all you need to do is remove the newline after { : ... Before running Prettier: @observer class OrderLine { @observable price: number...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found