will_ has asked for the wisdom of the Perl Monks concerning the following question:

At work we've recently tried to agree on a set of perltidy rules. We came up with these:
-i=4 # 4 character indents in blocks -pt=2 # "horizontal tightness" -wls='=>' # ensure there's always space to the left of => -wrs='=>' # and always to the right of => -vtc=0 # always break before a closing token -l=79 # 79 characters wide please -nolc # no "outdenting" for long comments - indent them properly -nolq # no "outdenting" for long quotes/strings -sot # stack opening tokens - same as -sop -sohb -sosb -sct # stack closing tokens
But they seem to result in unexpected changes like this:
- error(300) if $@; # 300 = GSI_BAD_ID + error(300) if $@; # 300 = GSI_BAD_ID
and this:
my $d; $d->{status} = 'queued'; $d->{description} = 'The action was successfully queued'; - $d->{id} = '12345'; # Identifies action request + $d->{id} = '12345'; # Identifies action request

So my questions are:
1) What's the point of these changes?
2) Which options control them?

I read the docs but did not find anything relevant:
http://perltidy.sourceforge.net/perltidy.html#formatting_options
http://perltidy.sourceforge.net/stylekey.html

Replies are listed 'Best First'.
Re: Why does perltidy mess up whitespace before inline comments and equals?
by Eily (Monsignor) on Oct 20, 2014 at 12:00 UTC

    -msc=n, --minimum-space-to-comment=n
    Side comments look best when lined up several spaces to the right of code. Perltidy will try to keep comments at least n spaces to the right. The default is n=4 spaces.
    I don't know how to align assignments though.

      > don't know how to align assignments though.

      Neither me, could be a default w/o config option.

      Cheers Rolf

      (addicted to the Perl Programming Language and ☆☆☆☆ :)

        To clarify, the lining up of assignments is automatic (and most agreeable). The only time it doesn't happen is when it would make the line too long.
Re: Why does perltidy mess up whitespace before inline comments and equals?
by LanX (Saint) on Oct 20, 2014 at 11:25 UTC
    Could you please be more specific about what you consider "unexpected changes" and what your desired output looks like?

    your option -nolc mentions comments, searching the docs for -nolc shows

    -olc, --outdent-long-comments When -olc is set, lines which are full-line (block) comments longe +r than the value maximum-line-length will have their indentation remo +ved. This is the default; use -nolc to prevent outdenting.

    so what is your question?

    Cheers Rolf

    (addicted to the Perl Programming Language and ☆☆☆☆ :)

      Rolf, I would expect those lines not to change at all.
      Eily, thanks -msc pointed me in the right direction.

      After some more experimenting, I've found that this code:
      $d->{status} = 'queued'; # something $d->{description} = 'The action'; # other thing $d->{id} = '12345'; # Identifies action
      gets changed to this:
      $d->{status} = 'queued'; # something $d->{description} = 'The action'; # other thing $d->{id} = '12345'; # Identifies action
      ...which is definitely better in that case.

      But even if only the last line had a comment and I use -msc=1:
      $d->{status} = 'queued'; $d->{description} = 'The action'; $d->{id} = '12345'; # Identifies action
      ...it still pushes the comment way out to the right to align with some non-existent other comments. That's not necessary.
      $d->{status} = 'queued'; $d->{description} = 'The action'; $d->{id} = '12345'; # Identifies action

      Setting -ols/-nolc don't seem to have any effect on this.

      And now I've found what I was looking for:
      -ssc -sscp=#
      This sets "static side comments", and sets the identifier for those to the usual # character

      docs: http://perltidy.sourceforge.net/perltidy.html#static_side_comments

      This lines up the equals but leaves the comments alone. The only time the equals doesn't get lined up is if that would make the line longer than the -l setting, which is fair enough.