How to remove leading comment whitespace in Perl::Tidy?

653 views Asked by At

I'm just configuring Perl::Tidy to match my preference. I have only one issue left which I can't find a fix.

Sample script:

#!/usr/bin/perl
#   |   |   |   |   |   < "|" indicates first five "tabs" (1 tab 4 spaces).
use strict;     # Enable strict programming mode.
use warnings;   # Enable Perl warnings.
use utf8;       # This is an UTF-8 encoded script.
1;

perltidyrc:

# Perl Best Practices (plus errata) .perltidyrc file

-l=76   # Max line width is 76 cols
-i=4    # Indent level is 4 cols
-ci=4   # Continuation indent is 4 cols
-et=4   # 1 tab represent 4 cols
-st     # Output to STDOUT
-se     # Errors to STDERR
-vt=2   # Maximal vertical tightness
-cti=0  # No extra indentation for closing brackets
-pt=0   # Medium parenthesis tightness
-bt=1   # Medium brace tightness
-sbt=1  # Medium square bracket tightness
-bbt=1  # Medium block brace tightness
-nsfs   # No space before semicolons
-nolq   # Don't outdent long quoted strings
-wbb="% + - * / x != == >= <= =~ < > | & **= += *= &= <<= &&= -= /= |= >>= ||= .= %= ^= x="
        # Break before all operators

# extras/overrides/deviations from PBP

#--maximum-line-length=100               # be slightly more generous
--warning-output                        # Show warnings
--maximum-consecutive-blank-lines=2     # default is 1
--nohanging-side-comments               # troublesome for commented out code

-isbc   # block comments may only be indented if they have some space characters before the #

# for the up-tight folk :)
-pt=2   # High parenthesis tightness
-bt=2   # High brace tightness
-sbt=2  # High square bracket tightness

Result:

#!/usr/bin/perl
#   |   |   |   |   |   < "|" indicates first five "tabs" (1 tab 4 spaces).
use strict;      # Enable strict programming mode.
use warnings;    # Enable Perl warnings.
use utf8;        # This is an UTF-8 encoded script.
1;

As you can see there is a leading space which causes that the "#" doesn't match the forth tab.

How to remove this leading space?

1

There are 1 answers

2
Mithaldu On BEST ANSWER

Perltidy is only able to change perl code, as it knows the meaning of perl code. Comments can contain entirely arbitrary data and as such perltidy cannot touch it. So, this kind of thing you'll have to resolve yourself.