Dav*_*avs 10 perl autoformatting perl-tidy
我有以下代码片段:
my $obj = $class->new({
schema => $schema,
reminder => $reminder,
action => $action,
dt => $dt,
});
Run Code Online (Sandbox Code Playgroud)
我的问题是,perltidy尝试将其格式化为某种东西,如下所示:
my $obj = $class->new(
{ schema => $schema,
reminder => $reminder,
action => $action,
dt => $dt,
}
);
Run Code Online (Sandbox Code Playgroud)
我不喜欢花括号放置.我可以以某种方式配置perltidy来格式化它像第一个例子?(跳过块的格式不是一个选项.我想将每个更长的hashref格式化为该格式,因此它更紧凑和可读)
到目前为止我的perltidyrc:
-l=79 # Max line width is 78 cols
-i=4 # Indent level is 4 cols
-ci=4 # Continuation indent is 4 cols
-st # Output to STDOUT
-se # Errors to STDERR
-vt=2 # Maximal vertical tightness
-cti=0 # No extra indentation for closing brackets
-pt=1 # 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
Run Code Online (Sandbox Code Playgroud)
如果我删除'{}'并将参数作为列表传递,它会做正确的事btw.但我必须通过hashref.
或者你能推荐一种理智的格式化代码吗?
这个选项怎么样?
perltidy -lp -vt=2 -vtc=1
Run Code Online (Sandbox Code Playgroud)
产量
my $obj = $class->new( { schema => $schema,
reminder => $reminder,
action => $action,
dt => $dt,
} );
Run Code Online (Sandbox Code Playgroud)
这是http://perltidy.sourceforge.net/perltidy.html#line_break_control
关闭令牌(块括号除外)由-vtc = n或--vertical-tightness-closing = n控制,其中
-vtc = 0总是在关闭令牌之前断开一行(默认),-vtc = 1在关闭令牌之前不会中断,后面跟着分号或其他结束令牌,并且不在列表环境中.-vtc = 2在结束令牌之前永远不会中断.
编辑我怀疑你错过了-lp(排队参数)选项,这也是垂直松紧度所需要的(-vt和-vtc)
以下似乎可以解决上述问题并对我有用:
# perltidy configuration file created Thu Sep 24 15:54:07 2015
# using: -
# I/O control
--standard-error-output # -se
--nostandard-output # -nst
# Basic formatting options
--indent-columns=4 # -i=4 [=default]
--maximum-line-length=140 # -l=140
# Code indentation control
--closing-brace-indentation=0 # -cbi=0 [=default]
--closing-paren-indentation=0 # -cpi=0 [=default]
--closing-square-bracket-indentation=0 # -csbi=0 [=default]
--continuation-indentation=4 # -ci=4
--nooutdent-labels # -nola
--nooutdent-long-quotes # -nolq
# Whitespace control
--block-brace-tightness=1 # -bbt=1
--brace-tightness=1 # -bt=1 [=default]
--paren-tightness=2 # -pt=2
--nospace-for-semicolon # -nsfs
--square-bracket-tightness=1 # -sbt=1 [=default]
--square-bracket-vertical-tightness=0 # -sbvt=0 [=default]
# Comment controls
--ignore-side-comment-lengths # -iscl
--minimum-space-to-comment=2 # -msc=2
--static-side-comment-prefix="#" # -sscp="#"
--static-side-comments # -ssc
# Linebreak controls
--brace-vertical-tightness=0 # -bvt=0 [=default]
--paren-vertical-tightness=0 # -pvt=0 [=default]
--stack-closing-hash-brace # -schb
--stack-closing-paren # -scp
--stack-closing-square-bracket # -scsb
--stack-opening-hash-brace # -sohb
--stack-opening-paren # -sop
--stack-opening-square-bracket # -sosb
--want-break-before="% + - * / x != == >= <= =~ < > | & **= += *= &= <<= &&= -= /= |= + >>= ||= .= %= ^= x=" # -wbb="% + - * / x != == >= <= =~ < > | & **= += *= &= <<= &&= -= /= |= + >>= ||= .= %= ^= x="
# Blank line control
--noblanks-before-comments # -nbbc
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
376 次 |
| 最近记录: |