Skip to content

Column number in DetailAST should start with 1 #4997

@MEZk

Description

@MEZk

Due to the fact that in the past in many IDEs and code editors the position of the first symbol in the line was 0, we have this hack in DetailAST:

// expect columns to start @ 0
columnNo = tok.getColumn() - 1;

Nowadays, in most popular IDEs (IntelliJ IDEA, Eclipse, sublime, VS Code, gedit) the first symbol has 1st position. The log method of AbstractCheck has a special hack to avoid confusion in the Checkstyle output:

final int col = 1 + CommonUtils.lengthExpandedTabs(
            getLines()[lineNo - 1], colNo, tabWidth);

We always increment column number at list by 1. Tab expansion is another story, and it is OK.
That is why we need to consider that the first character starts on the 1st position too.

The fix will lead too the big regression.

  1. We need to remove -1 from DetailAST
  2. We need to remove +1 from AbstractCheck#log
  3. We should fix all UTs. Special attention to each failing UT, some checks violations may become confusing.
  4. The regression report for all failing checks has to be generated to prove that at least the number of violations will not be decreased. So the number of violations before and after fix should be equal.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions