如何将perltidy配置为格式化if if语句如下:
if (
('this is an example' =~ /an.*example/ and 1 * 2 * 3 == 6) or
('hello world' =~ /world/ and 6 = 3 * 2 * 1)
) {
print "hello\n";
}
Run Code Online (Sandbox Code Playgroud)
或者像这样
if (
('this is an example' =~ /an.*example/ and 1 * 2 * 3 == 6)
or ('hello world' =~ /world/ and 6 == 3 * 2 * 1)
) {
print "hello\n";
}
Run Code Online (Sandbox Code Playgroud)
编辑1:perltidyrc
--maximum-line-length=100
--indent-columns=4
--default-tabsize=4
--continuation-indentation=4
--closing-token-indentation=0
--no-indent-closing-brace
--paren-tightness=2
--square-bracket-tightness=2
--block-brace-tightness=0
--trim-qw
--nospace-terminal-semicolon
--nospace-for-semicolon
--indent-spaced-block-comments
--ignore-side-comment-lengths
--cuddled-else
--no-opening-brace-on-new-line
--no-opening-sub-brace-on-new-line
--no-opening-anonymous-sub-brace-on-new-line
--no-brace-left-and-indent
--blanks-before-comments
--blank-lines-before-subs=1
--blanks-before-blocks
--maximum-consecutive-blank-lines=1
Run Code Online (Sandbox Code Playgroud)
编辑2:我们的想法是在第一行之后有一个新行(,最后)一行是在新行上{.如果这是不可能的,任何其他建议更好的格式将不胜感激.
perltidy 的默认风格是尽可能遵循Perl 风格指南。其结果是这样的输出:
if ( ( 'this is an example' =~ /an.*example/ and 1 * 2 * 3 == 6 )
or ( 'hello world' =~ /world/ and 6 == 3 * 2 * 1 ) )
{
print "hello\n";
}
Run Code Online (Sandbox Code Playgroud)
您可以控制花括号是否在新行上。您可以控制括号的松紧程度。但是,您无法控制代码块中括号的新行。
默认样式与您想要的输出尽可能接近。