Skip to content

Trailing comment alignment test fails with tab-based indentation in test input files #19063

@MiniPiku

Description

@MiniPiku

I have read check documentation: https://checkstyle.org/checks/xxxxxx/nameofaffectedcheck.html
I have downloaded the latest checkstyle from: https://checkstyle.org/cmdline.html#Download_and_Run

Description

When adding a tab-based regression test file for IndentationCheck,
the JUnit test IndentationTrailingCommentsVerticalAlignmentTest fails due to trailing comment alignment mismatch.

The regression input file intentionally contains tab characters to verify tab-based indentation handling.

However, IndentationTrailingCommentsVerticalAlignmentTest enforces that all trailing comments (//indent:... exp:...) must align at the same expanded column across the file.

This causes failures for files that intentionally use tabs.

How to Reproduce

Add a regression input file containing tabs in:
src/test/resources/com/puppycrawl/tools/checkstyle/checks/indentation/indentation/

ATTENTION : should be tabs and not spaces(IDE'sare tend to convert tabs to spaces)

Run:
mvn -Dtest=IndentationTrailingCommentsVerticalAlignmentTest test

Input

public class InputIndentationTryCtorParamsTabsWrong {                        //indent:0 exp:0

	private InputIndentationTryCtorParamsTabsWrong client;                   //indent:4 exp:4

	private InputIndentationTryCtorParamsTabsWrong(String string) {          //indent:4 exp:4
	}                                                                        //indent:4 exp:4

	private void test() {                                                    //indent:4 exp:4
		try {                                                                //indent:8 exp:8
			client =                                                         //indent:12 exp:12
            new InputIndentationTryCtorParamsTabsWrong(null);                //indent:8 exp:16
		}                                                                    //indent:8 exp:8
		catch (Exception e) {                                                //indent:8 exp:8
		}                                                                    //indent:8 exp:8
	}                                                                        //indent:4 exp:4
}

(Initialized gaps are tabs and not spaces to trigger a particular error for test)

Failing Output

Trailing comment alignment mismatch in file:
InputIndentationTryCtorParamsTabsWrong.java on line 23
expected: 77
but was : 71

Expected Behavior

Tab-based regression test files should not fail due to global trailing comment alignment enforcement.

Actual Behavior

Trailing comment alignment validation fails even though the file is intentionally tab-indented for indentation testing.

Suggested Direction

Allow a hardcoded list of tab-based test files where vertical alignment enforcement is skipped in IndentationTrailingCommentsVerticalAlignmentTest

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions