Java Checkstyle Rule To Restrict Method Empty Lines

前端 未结 4 1533
春和景丽
春和景丽 2021-01-19 10:19

Is there a way to setup checkstyle to prevent leading, multiple or trailing empty lines in method bodies:

e.g.

private void a() {
-
int a = 1;
doStu         


        
4条回答
  •  灰色年华
    2021-01-19 10:50

    To prevent multiple empty lines you can use the EmptyLineSeparator check. Its primary purpose is to ensure that there is an empty line between members in a file, but it also has a allowMultipleEmptyLines property which you can set to "false" to disallow them.

    There is however currently a bug with the check that means it doesn't correctly detect multiple empty lines between methods where there is a comment (including JavaDoc) between the methods. I am working on a fix for this at the moment.

    As for checking for new lines at the beginning or end of a block, I think the RegexpMultiline check would be the only option as mentioned in Pankaj's answer.

提交回复
热议问题