Skip to content
GitLab
菜单
项目
群组
代码片段
/
帮助
帮助
支持
社区论坛
快捷键
?
提交反馈
登录/注册
切换导航
菜单
打开侧边栏
KMSCAKKSCFKA AKFACAMADCAS
brew
提交
391e7e22
提交
391e7e22
编辑于
11月 12, 2021
作者:
XuehaiPan
浏览文件
utils/shfmt.sh: add `!=` and `=~` to within test regex
上级
2345a340
变更
1
Hide whitespace changes
Inline
Side-by-side
Library/Homebrew/utils/shfmt.sh
浏览文件 @
391e7e22
...
...
@@ -227,11 +227,11 @@ no_forbidden_styles() {
align_multiline_if_condition
()
{
local
line
local
lastline
=
''
local
base_indent
=
''
# indents before `if`
local
extra_indent
=
''
# 2 extra spaces for `elif`
local
base_indent
=
''
# indents before `if`
local
elif_
extra_indent
=
''
# 2 extra spaces for `elif`
local
multiline_if_then_begin_regex
=
'^( *)(el)?if '
local
multiline_if_then_end_regex
=
'^(.*)\; (then( *#.*)?)$'
local
within_test_regex
=
'^( *)(((! )?-[fdLrwxeszn] )|([^\[]+ == ))'
local
within_test_regex
=
'^( *)(((! )?-[fdLrwxeszn] )|([^\[]+
(
==
|!=|=~)
))'
trim
()
{
[[
"
$1
"
=
~
[
^[:space:]]
(
.
*
[
^[:space:]]
)
?
]]
...
...
@@ -241,7 +241,7 @@ align_multiline_if_condition() {
if
[[
"
$1
"
=
~
${
multiline_if_then_begin_regex
}
]]
then
base_indent
=
"
${
BASH_REMATCH
[1]
}
"
[[
-n
"
${
BASH_REMATCH
[2]
}
"
]]
&&
extra_indent
=
' '
[[
-n
"
${
BASH_REMATCH
[2]
}
"
]]
&&
elif_
extra_indent
=
' '
# 2 extra spaces for `elif`
echo
"
$1
"
shift
fi
...
...
@@ -257,9 +257,14 @@ align_multiline_if_condition() {
fi
if
[[
"
${
line
}
"
=
~
${
within_test_regex
}
]]
then
echo
"
${
base_indent
}${
extra_indent
}
$(
trim
"
${
line
}
"
)
"
# Add 3 extra spaces (6 spaces in total) to multiline test conditions
# before: after:
# if [[ -n ... || if [[ -n ... ||
# -n ... ]] -n ... ]]
# then then
echo
"
${
base_indent
}${
elif_extra_indent
}
$(
trim
"
${
line
}
"
)
"
else
echo
"
${
base_indent
}${
extra_indent
}
$(
trim
"
${
line
}
"
)
"
echo
"
${
base_indent
}${
elif_
extra_indent
}
$(
trim
"
${
line
}
"
)
"
fi
done
...
...
编辑
预览
支持
Markdown
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录