#1221 OneDeclarationPerLine really checks for one declaration each statement



The OneDeclarationPerLine rule really checks for maximum one declaration per statement, not one per line. But Java allows for multiple declarations to each be on individual lines in a single statement -- and the rule currently disallows that.

I would agree that multiple declarations in one line can be hard to read. But I disagree that

String a = "first string";
String b = "second string";
String c = "third string";

is harder to read than

String a = "first string",
       b = "second string",
       c = "third string";

In fact, the second one is less cluttered. But it's a matter of style.

Relaxing the rule to permit one declaration on each line of a multi-line statement would at least make the name of the rule match its behavior.

Otherwise, please provide a parameter to allow the multi-line, single-statement form.



  • Andreas Dangel

    Andreas Dangel - 2014-07-10

    I agree with you, the multi-line statement should not be flagged by this rule.
    I've added a rule-property "strictMode" which is by default false. Setting it to true will restore the old behavior, but the new behavior will accept combined variable declarations as long as they are on separate lines.

    This will be included in the next PMD release.

  • Andreas Dangel

    Andreas Dangel - 2014-07-10
    • status: open --> closed
    • assigned_to: Andreas Dangel
    • Milestone: New Tickets --> PMD-Next

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks