checkstyle / checkstyle/checkstyle

EmptyLineSeparatorCheck does not report violations when more than one empty line appears with enum constants.

Open
#18,437 6 comments 0 reactions 0 assignees View on GitHub
approved
Dominant language
Java
Stars
9.6k
Forks
4.2k
Avg merge
21h 32m
Merged PRs (30d)
233

Description

I have read check documentation: https://checkstyle.org/checks/whitespace/emptylineseparator.html#EmptyLineSeparator
I have downloaded the latest checkstyle from: https://checkstyle.org/cmdline.html#Download_and_Run
I have executed the cli and showed it below, as cli describes the problem better than 1,000 words

#### Config:
```








```

#### Test.java:
```
public class Test { // 1
// 2
public enum Check { // 3
// 4
FIRST, // 5
SECOND, // 6
// 7
THIRD, // 8
// 9
// 10
FOURTH, // 11
// 11
// 12
// 13
SPECIAL(100) { // 14
@Override // 15
public String describe() { // 16
return "Special enum constant"; // 17
} // 18
}, // 19
// 20
// 21
// 22
// 23
NORMAL(200) { // 24
@Override // 25
public String describe() { // 26
return "Normal enum constant"; // 27
} // 28
}; // 29
// 30
// 31
// 32
} // 33
} // 34
```

#### Actual Cli:
```
$ java -jar checkstyle-12.3.0-all.jar -c config_check.xml Test.java
Starting audit...
Audit done.
```

#### Expected Cli:
```
$ java -jar checkstyle-12.3.0-all.jar -c config_check.xml Test.java
Starting audit...
[ERROR] F:\GitHub\headhtmltagname\Test.java:8:9: 'ENUM_CONSTANT_DEF' has more than 1 empty lines after. [EmptyLineSeparator]
[ERROR] F:\GitHub\headhtmltagname\Test.java:11:9: 'ENUM_CONSTANT_DEF' has more than 1 empty lines after. [EmptyLineSeparator]
[ERROR] F:\GitHub\headhtmltagname\Test.java:19:9: '}' has more than 1 empty lines after. [EmptyLineSeparator]
[ERROR] F:\GitHub\headhtmltagname\Test.java:22:9: '}' has more than 1 empty lines after. [EmptyLineSeparator]
Audit done.
```

Since the documentation mentions that `the check is valid only for statements that have a body: CLASS_DEF, INTERFACE_DEF, ENUM_DEF, STATIC_INIT, INSTANCE_INIT, METHOD_DEF, and CTOR_DEF`, it must also check enum constants.
https://checkstyle.org/checks/whitespace/emptylineseparator.html#Example5-config

Contributor guide

Open the contributing guide

Research direction

Start by running the CLI command from the issue with config_check.xml and Test.java, then trace the EmptyLineSeparatorCheck handling of enum constants and their bodies. Compare the result with the four expected diagnostics; the work is done when the reported output matches those violations without regressing the documented behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.