Skip to content

Identation basicOffset force strict condition #17685

@sukolenvo

Description

@sukolenvo

I have read check documentation: https://checkstyle.sourceforge.io/checks/misc/indentation.html#Indentation
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

/var/tmp $ javac Example1.java
# no errors

/var/tmp $ cat config.xml
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
  "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
  "https://checkstyle.org/dtds/configuration_1_3.dtd">

<module name="Checker">
  <module name="TreeWalker">
    <module name="Indentation">
    </module>
  </module>
</module>


/var/tmp $ cat Example1.java
class Example1 {

    void processValues(MyField field) {
        field.getUsers()
            .stream()
            .map(
                "param1",
                "param2"
            ).collect("param1", "param2");


        field.getUsers()
            .stream()
            .map("param1", "param2")
            .collect(
                "param1",
                "param2"
            ); // ok

        field.getUsers().stream()
            .map("param1", "param2")
            .collect(
                "param1",
                "param2"
        );

        field.getUsers().stream()
            .map("param1", "param2")
            .collect(
                "param1",
                "param2"
            ); // violation is here !!!!
    }

    interface MyField {

        MyField getUsers();

        MyField stream();

        MyField map(String param1, String param2);

        MyField collect(String param1, String param2);
    }
}

/var/tmp $ RUN_LOCALE="-Duser.language=en -Duser.country=US"
/var/tmp $ java $RUN_LOCALE -jar checkstyle-11.0.0-all.jar -c config.xml Example1.java
Starting audit...
[ERROR] Example1.java:32:13: 'method call rparen' has incorrect indentation level 12, expected level should be 8. [Indentation]
Audit done.
Checkstyle ends with 1 errors.

Describe what you expect in detail.

Example1.java contains 4 sample code blocks to perform similar operations. 3 of them successfully pass checkstyle validation and last one fails due to basicOffset expected to be 8, but got 12. Block 4 is very similar to other examples (especially 1 and 2) and I think such code should not raise a violation error.

Possible solution: lineWrappingIndentation has a partner property forceStrictCondition that controls if line wrap indent could be bigger on any value user would like. Similar property for basecOffset (or even same property) could solve the problem.

If behaviour is intentional - I would appreciate if you can share explanation I have missed (because I thought about it and could not find obvious reason for behaviour to differ between 4 code blocks).

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions