Checkstyle: enforce empty line after close curly / before return

Viewed 123

Looking for a Checkstyle rule to enforce empty lines in some situations:

Empty Line After Close Curly

if (something)
{
    // not important
}
doSomethingElse();

Empty Line Before Return

final var result = doSomething();
return result;
1 Answers

I ended up adding a simple RegexpMultiline module which should work for now thought it may not catch all cases:

<!-- Enforces blank lines after block-closing curly braces (with exceptions). -->
<module name="RegexpMultiline">
    <property name="format" value="}\n(?![ \t]*(else|case|catch|finally|[})]|\*)|$)"/>
</module>

Related