checkstyle / checkstyle/checkstyle
IndentationCheck does not work with single line comments in the middle
- Dominant language
- Java
- Stars
- 9.6k
- Forks
- 4.2k
- Avg merge
- 21h 32m
- Merged PRs (30d)
- 233
Description
This is not related to CommentsIndentationCheck as the comments are not stand-alone, but in the middle of a statement.
These comments are in the middle of an if statement for explanations about the separate conditions. IndentationCheck incorrectly marks them as errors when they are formatted correctly with Eclipse.
Config:
```
```
Input after formatted with Eclipse (ignore "//<-- " as explanations of the start of the lines)
```
package test;
public class TestClass {
public static void test() { //<-- 4:4
if ( //<-- 5:8
// comment explaining complex condition //<-- 6:8
(true) && //<-- 7:8
// comment explaining 2nd complex condition //<-- 8:8
(true)) { //<-- 9:8
System.out.println("work"); //<-- 10:12
} //<-- 11:8
} //<-- 12:4
}
```
Errors:
```
TestClass.java:7: 'if' child have incorrect indentation level 8, expected level should be 12.
TestClass.java:9: 'if' child have incorrect indentation level 8, expected level should be 16.
```
It doesn't know the comments are there which affects the indentation on the following line.
I couldn't find a specific setting in Eclipse that changed this behavior. Even the built-in formatter does it.
##
Contributor guide
Research direction
Reproduce the issue through the Indentation module using the supplied configuration and TestClass.java input. Inspect how IndentationCheck handles single-line comments within the if statement, then add a regression test showing that the correctly formatted lines no longer produce the reported errors.
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
- 35/100