[sf-perl] perltidy frustration
Michael Friedman
frimicc at gmail.com
Mon Feb 11 10:31:30 PST 2013
I'm trying to get my new office (Polyvore.com -- we're hiring, BTW) to adopt perltidy for their existing, but complicated, code style standards. I've managed to get it relatively close, but I'm running into a wall with two particular cases. Since a number of SFPM members seem to be masters of perltidy, I wondered if anyone might have an idea of what I can try to get these to work. (My .perltidyrc is at the bottom of this email.)
Thanks for any advice!
-- Mike Friedman
First case: How do I get perltidy to line up equal signs with other equal-like things, like ||=, //=, and so on? The lining-up-of-equals doesn't seem to be controllable by any of the flags I could find. The BEFORE code is turned into the AFTER code by perltidy with my options.
BEFORE:
$params->{_default_sort} = '-count';
$params->{_sort_map} = TAG_SORT;
$params->{_limit} ||= Cons::MAX_CLEAN_TAGS;
$sql = _limit_order($sql, $params);
AFTER:
$params->{_default_sort} = '-count';
$params->{_sort_map} = TAG_SORT;
$params->{_limit} ||= Cons::MAX_CLEAN_TAGS;
$sql = _limit_order($sql, $params);
Second case: The BEFORE code is turned into the AFTER code. The statement about 'mod_stack_layer' is arguably more readable before than after, but I can't get perltidy to not merge the lines as it does. For other reasons I'm not allowed to shorten the line length < 120 characters or to make all lists vertical. I know I could put in a format-skipping marker (#<<< do not let perltidy touch this), but this construction occurs often enough to make that painful.
Any ideas on how I can get this to stay broken the old way?
BEFORE:
sub render_stack {
my ($resp, $item, $options) = @_;
my $req = $resp->request();
my $size = $options->{size} || 's';
my $class = $options->{class} || '';
my $renderer = $options->{renderer} || \&render_item;
my $content = &$renderer($resp, $item, { size => $size });
my $id = $options->{id} || Request::dom_unique_id();
return $req->div({
id => $id,
class => "mod_stack $class size_$size",
},
$req->div({ class => 'mod_stack_layer' },
$req->div({ class => 'mod_stack_layer' },
$req->div({ class => 'mod_stack_content' }, $content),
),
),
);
}
AFTER:
sub render_stack {
my ($resp, $item, $options) = @_;
my $req = $resp->request();
my $size = $options->{size} || 's';
my $class = $options->{class} || '';
my $renderer = $options->{renderer} || \&render_item;
my $content = &$renderer($resp, $item, { size => $size });
my $id = $options->{id} || Request::dom_unique_id();
return $req->div({
id => $id,
class => "mod_stack $class size_$size",
},
$req->div(
{ class => 'mod_stack_layer' },
$req->div({ class => 'mod_stack_layer' }, $req->div({ class => 'mod_stack_content' }, $content),),
),
);
}
.perltidyrc:
-l=120 # Max line width of 120 cols
-i=4 # Indent is 4 spaces
-ci=2 # Continuation indent is also 4
#-st # Output to STDOUT
-se # Errors to STDERR
-vt=2 # Max vertical tightness for opening blocks
-cti=0 # No extra indentation for closing brackets
-ce # Use "cuddled" else
-bar # Open brace always on right
-pt=2 # Max parens tightness
-bt=1 # Medium brace tightness
-bvt=0 # Min non-code-block brace tightness
-sbt=2 # Max square bracket tightness
-bbt=1 # Medium block brace tightness
-sot # Stack opening tokens
-sct # Stack closing tokens
-nsfs # No space before semicolons
-nolq # Don't outdent long quoted strings
-nbbc # No blank line before comment line
-msc=1 # Minimum space to trailing comment
-wbb="% + - * / x != == >= <= =~ !~ < > | & = **= += *= &= <<= &&= -= /= |= >>= ||= .= %= ^= x="
# Break before all operators, not just the defaults
More information about the SanFrancisco-pm
mailing list