How can I prevent PerlTidy from aligning assignments but keep adding single spaces?
This question is similar to How can I prevent PerlTidy from aligning my assignments? but I would like single spaces to be added where directed. Due to this -naws
switch does not work for me. I just do not want multiple spaces to be inserted. Is it possibe with perltidy or some other tool?
Perl tidy changes:
my $a = 1;
my $aa = 2;
my $aaa= 3;
into
my $a = 1;
my $aa = 2;
my $aaa = 3;
with -naws it remains unchanged:
my $a = 1;
my $aa = 2;
my $aaa= 3;
I would like this code to be formatted as:
my $a = 1;
my $aa = 2;
my $aaa = 3;
The following patch worked for me:
There is an undocumented flag
--no-valign
which appears to achieve the best of both worlds without modifying the perltidy source.As you point out,
--no-add-whitespace
is too aggressive and prevents whitespace from being added in other, desirable locations (around operators etc.). With--no-valign
perltidy is still correcting things likemy ($arg)=@_;
tomy ($arg) = @_;
but does not attempt to vertically align operators across lines. The setting does not completely disable the vertical aligner, so you still get some benefits in other places (e.g. side-comments).The only problem I have found with this so far is that the first side-comment of a block of side-comments is not aligned with the subsequent ones:
It is only respecting
--minimum-space-to-comment
. I'm not sure why the subsequent (third and fourth) lines work properly. I don't use side-comments much so it's not a major issue (and you could use--format-skipping
on such blocks).