qw() is not indented when the line is wrapped
Status: Beta
Brought to you by:
perltidy
Here is an example:
sub testing
{
my ( $apple ) = @_;
# case 1
croak 'Incorrect params'
if any { !defined $_ } ( $apple, $test );
# case 2
croak 'Incorrect params'
if missing_any_keys( $apple,
qw( apple banana test test2 test3 test4 test5 test6 ) );
# case 3
croak 'Incorrect params'
if any { !exists $apple->{$_} } qw( test2 test3 test4 test5 test6 );
# case 4
croak 'Incorrect params'
if any { !exists $apple->{$_} }
qw( apple test test2 test3 test4 test5 test6 );
return;
}
Notice that in case 2 the qw() are indented due to being in a sub call. However in case 4 we can see that when the line is forced to wrap the qw() is not indented. I would expect case 4 to look similar to case 2 in my example.
Here is my perltidyrc:
--maximum-line-length=80
--variable-maximum-line-length
--indent-columns=4
--iterations=2
--continuation-indentation=4
--backup-and-modify-in-place
--backup-file-extension="/"
--standard-error-output
--closing-token-indentation=0
--all-containers-tightness=1
--paren-tightness=0
--square-bracket-tightness=2
--brace-tightness=1
-sot
-sct
--block-brace-tightness=0
--nospace-for-semicolon
--nooutdent-long-lines
--want-break-before="-> % + - * / x != == >= <= =~ !~ < > | & = **= += *= &= <<= &&= -= /= |= >>= ||= //= .= %= ^= x="
--opening-brace-on-new-line
--nospace-after-keyword="if else elsif unless while for foreach switch case given when"
I hope that you can help!
Hi Harrison,
Thanks for the bug report, I do appreciate it.
The problem here isn't just with a qw quote but has to do with paren-less
function calls, which Perl allows but which are hard to parse.
In case 4 there are no parens around the 'if' or the 'any', and perltidy
doesn't know what 'any' is expecting, so it mistakes the qw list for the
start of a new statement.
Case 1 would also have the same problem if it's list had enough items to
require another line.
Case 3 works because there are parens around the function call.
The best workaround for now is to use occasional parens where possible.
Perltidy does handle paren-less calls with the the builting functions like
sort, map, grep fairly well, but it is difficult to make it completely
general for non-builtin functions.
Regards,
Steve
On Thu, May 14, 2015 at 1:10 PM, Harrison Katz hjkatzneadwerx@users.sf.net
wrote:
Related
Bugs: #15
Steve,
Thanks for the quick update and reply. I see the problem now with the lack of parens call that I'm making. I know that perltidy understands how to deal with calls like grep and map, have you considered adding the library of List::MoreUtils to that list of standard functions that are called in the form <call> { <block> } <list>? List::MoreUtils is recommended by Conway in his book, Perl Best Practices, and the functions included are all very similar to map.</list></block></call>
--Harrison
Would there be a way for me to add these to the list for perltidy to treat special?
Harrison,
I think it would be difficult for you because some of this is hard coded,
but I'll look into the possibility of generalizing it.
Steve
On Sat, May 16, 2015 at 8:06 AM, Harrison Katz hjkatzneadwerx@users.sf.net
wrote:
Related
Bugs: #15