Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Annlix
ShellCheck
提交
a839a665
S
ShellCheck
项目概览
Annlix
/
ShellCheck
与 Fork 源项目一致
Fork自
镜像 / koalaman / ShellCheck
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
ShellCheck
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a839a665
编写于
7月 03, 2017
作者:
V
Vidar Holen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Warn when commands start with dashes (#938)
上级
a10b9245
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
26 addition
and
4 deletion
+26
-4
ShellCheck/ASTLib.hs
ShellCheck/ASTLib.hs
+12
-0
ShellCheck/Analytics.hs
ShellCheck/Analytics.hs
+14
-4
未找到文件。
ShellCheck/ASTLib.hs
浏览文件 @
a839a665
...
...
@@ -125,6 +125,11 @@ isFlag token =
T_Literal
_
(
'-'
:
_
)
:
_
->
True
_
->
False
-- Is this token a flag where the - is unquoted?
isUnquotedFlag
token
=
fromMaybe
False
$
do
str
<-
getLeadingUnquotedString
token
return
$
"-"
`
isPrefixOf
`
str
-- Given a T_DollarBraced, return a simplified version of the string contents.
bracedString
(
T_DollarBraced
_
l
)
=
concat
$
oversimplify
l
bracedString
_
=
error
"Internal shellcheck error, please report! (bracedString on non-variable)"
...
...
@@ -194,6 +199,13 @@ getTrailingUnquotedLiteral t =
T_Literal
{}
->
return
t
_
->
Nothing
-- Get the leading, unquoted, literal string of a token (if any).
getLeadingUnquotedString
::
Token
->
Maybe
String
getLeadingUnquotedString
t
=
case
t
of
T_NormalWord
_
((
T_Literal
_
s
)
:
_
)
->
return
s
_
->
Nothing
-- Maybe get the literal string of this token and any globs in it.
getGlobOrLiteralString
=
getLiteralStringExt
f
where
...
...
ShellCheck/Analytics.hs
浏览文件 @
a839a665
...
...
@@ -162,6 +162,7 @@ nodeChecks = [
,
checkSplittingInArrays
,
checkRedirectionToNumber
,
checkGlobAsCommand
,
checkFlagAsCommand
,
checkEmptyCondition
]
...
...
@@ -275,10 +276,7 @@ checkAssignAteCommand _ (T_SimpleCommand id (T_Assignment _ _ _ _ assignmentTerm
isCommonCommand
_
=
False
firstWordIsArg
list
=
fromMaybe
False
$
do
head
<-
list
!!!
0
return
.
or
$
mapMaybe
(
$
head
)
[
return
.
isGlob
,
isFlag
]
isFlag
word
=
do
first
<-
(
concat
$
oversimplify
word
)
!!!
0
return
$
first
==
'-'
return
$
isGlob
head
||
isUnquotedFlag
head
checkAssignAteCommand
_
_
=
return
()
...
...
@@ -2770,6 +2768,18 @@ checkGlobAsCommand _ t = case t of
warn
(
getId
first
)
2211
"This is a glob used as a command name. Was it supposed to be in ${..}, array, or is it missing quoting?"
_
->
return
()
prop_checkFlagAsCommand1
=
verify
checkFlagAsCommand
"-e file"
prop_checkFlagAsCommand2
=
verify
checkFlagAsCommand
"foo
\n
--bar=baz"
prop_checkFlagAsCommand3
=
verifyNot
checkFlagAsCommand
"'--myexec--' args"
prop_checkFlagAsCommand4
=
verifyNot
checkFlagAsCommand
"var=cmd --arg"
-- Handled by SC2037
checkFlagAsCommand
_
t
=
case
t
of
T_SimpleCommand
_
[]
(
first
:
_
)
->
when
(
isUnquotedFlag
first
)
$
warn
(
getId
first
)
2215
"This flag is used as a command name. Bad line break or missing [ .. ]?"
_
->
return
()
prop_checkEmptyCondition1
=
verify
checkEmptyCondition
"if [ ]; then ..; fi"
prop_checkEmptyCondition2
=
verifyNot
checkEmptyCondition
"[ foo -o bar ]"
checkEmptyCondition
_
t
=
case
t
of
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录