Skip to content

LineLength check documentation incorrectly shows how to work with tabWidth property  #13005

@danielrcollins1

Description

@danielrcollins1

Sad documentation defect

https://checkstyle.org/config_sizes.html#LineLength_Notes

To specify a different number of spaces, the user can set TreeWalker property tabWidth which applies to all Checks, including LineLength; or can set property tabWidth for LineLength alone.

We need to change Treewalker to Checker.

Line to change

<a href="config.html#TreeWalker"><code>TreeWalker</code></a> property


I have read check documentation: https://checkstyle.org/config_xxxxxx.html#NameOfAffectedCheck
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

D:\Dwnl\CheckStyle\BugReports\BadTabWidth>type Config.xml
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
    "-//Puppy Crawl//DTD Check Configuration 1.2//EN"
    "https://checkstyle.org/dtds/configuration_1_2.dtd">

<module name="Checker">
   <module name="LineLength"/>
   <module name="TreeWalker">
      <property name="tabWidth" value="3" />
   </module>
</module>

D:\Dwnl\CheckStyle\BugReports\BadTabWidth>type TestLongLine.java
/*
                1234567890123456789012345678901234567890123456789012345678901234567890
*/

D:\Dwnl\CheckStyle\BugReports\BadTabWidth>java -jar checkstyle-10.9.3-all.jar -c Config.xml TestLongLine.java
Starting audit...
[ERROR] D:\Dwnl\CheckStyle\BugReports\BadTabWidth\TestLongLine.java:2: Line is longer than 80 characters (found 86). [LineLength]
Audit done.
Checkstyle ends with 1 errors.

The documentation for LineLength says that it honors the TreeWalker tabWidth property, but it does not seem to do so in practice (https://checkstyle.org/config_sizes.html#LineLength).
The sample code file in its second line has 2 tab characters, followed by 70 digits. The config file has tabWidth set to 3, so this should be counted as 76 total characters, and within the default limit of 80 for LineLength. But instead this is counted as 86 characters (what you get if tabs are counted as the default 8 spaces wide each; 70 + 8 + 8 = 86), and thus triggers the LineLength error.
I've also tried setting the tabWidth property within the LineLenth module (as documentation says should work), but that has the same result.


Config.xml.txt
TestLongLine.java.txt

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