Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Annlix
ShellCheck
提交
ad1a0da9
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,体验更适合开发者的 AI 搜索 >>
提交
ad1a0da9
编写于
5月 22, 2016
作者:
V
Vidar Holen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Attempted bats
@test
support
上级
47fd16b8
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
37 addition
and
1 deletion
+37
-1
ShellCheck/AST.hs
ShellCheck/AST.hs
+3
-0
ShellCheck/Analytics.hs
ShellCheck/Analytics.hs
+7
-1
ShellCheck/AnalyzerLib.hs
ShellCheck/AnalyzerLib.hs
+14
-0
ShellCheck/Data.hs
ShellCheck/Data.hs
+1
-0
ShellCheck/Parser.hs
ShellCheck/Parser.hs
+12
-0
未找到文件。
ShellCheck/AST.hs
浏览文件 @
ad1a0da9
...
...
@@ -128,6 +128,7 @@ data Token =
|
T_CoProc
Id
(
Maybe
String
)
Token
|
T_CoProcBody
Id
Token
|
T_Include
Id
Token
Token
-- . & source: SimpleCommand T_Script
|
T_BatsTest
Id
Token
Token
deriving
(
Show
)
data
Annotation
=
...
...
@@ -265,6 +266,7 @@ analyze f g i =
delve
(
T_CoProc
id
var
body
)
=
d1
body
$
T_CoProc
id
var
delve
(
T_CoProcBody
id
t
)
=
d1
t
$
T_CoProcBody
id
delve
(
T_Include
id
includer
script
)
=
d2
includer
script
$
T_Include
id
delve
(
T_BatsTest
id
name
t
)
=
d2
name
t
$
T_BatsTest
id
delve
t
=
return
t
getId
t
=
case
t
of
...
...
@@ -363,6 +365,7 @@ getId t = case t of
T_CoProc
id
_
_
->
id
T_CoProcBody
id
_
->
id
T_Include
id
_
_
->
id
T_BatsTest
id
_
_
->
id
blank
::
Monad
m
=>
Token
->
m
()
blank
=
const
$
return
()
...
...
ShellCheck/Analytics.hs
浏览文件 @
ad1a0da9
...
...
@@ -238,7 +238,9 @@ hasFloatingPoint params = shellType params == Ksh
isCondition
[]
=
False
isCondition
[
_
]
=
False
isCondition
(
child
:
parent
:
rest
)
=
getId
child
`
elem
`
map
getId
(
getConditionChildren
parent
)
||
isCondition
(
parent
:
rest
)
case
child
of
T_BatsTest
{}
->
True
-- count anything in a @test as conditional
_
->
getId
child
`
elem
`
map
getId
(
getConditionChildren
parent
)
||
isCondition
(
parent
:
rest
)
where
getConditionChildren
t
=
case
t
of
...
...
@@ -1772,6 +1774,7 @@ prop_subshellAssignmentCheck15 = verifyNotTree subshellAssignmentCheck "#!/bin/k
prop_subshellAssignmentCheck16
=
verifyNotTree
subshellAssignmentCheck
"(set -e); echo $@"
prop_subshellAssignmentCheck17
=
verifyNotTree
subshellAssignmentCheck
"foo=${ { bar=$(baz); } 2>&1; }; echo $foo $bar"
prop_subshellAssignmentCheck18
=
verifyTree
subshellAssignmentCheck
"( exec {n}>&2; ); echo $n"
prop_subshellAssignmentCheck19
=
verifyTree
subshellAssignmentCheck
"@test 'foo' { a=1; }
\n
@test 'bar' { echo $a; }
\n
"
subshellAssignmentCheck
params
t
=
let
flow
=
variableFlow
params
check
=
findSubshelled
flow
[(
"oops"
,
[]
)]
Map
.
empty
...
...
@@ -1854,6 +1857,7 @@ prop_checkSpacefulness29= verifyNotTree checkSpacefulness "n=$(stuff); exec {n}>
prop_checkSpacefulness30
=
verifyTree
checkSpacefulness
"file='foo bar'; echo foo > $file;"
prop_checkSpacefulness31
=
verifyNotTree
checkSpacefulness
"echo
\"
`echo
\\\"
$1
\\\"
`
\"
"
prop_checkSpacefulness32
=
verifyNotTree
checkSpacefulness
"var=$1; [ -v var ]"
prop_checkSpacefulness33
=
verifyNotTree
checkSpacefulness
"@test 'status' {
\n
[ $status -eq 0 ]
\n
}"
checkSpacefulness
params
t
=
doVariableFlowAnalysis
readF
writeF
(
Map
.
fromList
defaults
)
(
variableFlow
params
)
...
...
@@ -2071,6 +2075,8 @@ prop_checkUnused30= verifyTree checkUnusedAssignments "let a=1"
prop_checkUnused31
=
verifyTree
checkUnusedAssignments
"let 'a=1'"
prop_checkUnused32
=
verifyTree
checkUnusedAssignments
"let a=b=c; echo $a"
prop_checkUnused33
=
verifyNotTree
checkUnusedAssignments
"a=foo; [[ foo =~ ^{$a}$ ]]"
prop_checkUnused34
=
verifyNotTree
checkUnusedAssignments
"@test 'foo' {
\n
true
\n
}
\n
"
checkUnusedAssignments
params
t
=
execWriter
(
mapM_
warnFor
unused
)
where
flow
=
variableFlow
params
...
...
ShellCheck/AnalyzerLib.hs
浏览文件 @
ad1a0da9
...
...
@@ -267,6 +267,7 @@ getVariableFlow shell parents t =
assignFirst
(
T_ForIn
{})
=
True
assignFirst
(
T_SelectIn
{})
=
True
assignFirst
(
T_BatsTest
{})
=
True
assignFirst
_
=
False
setRead
t
=
...
...
@@ -284,6 +285,7 @@ leadType shell parents t =
T_Backticked
_
_
->
SubshellScope
"`..` expansion"
T_Backgrounded
_
_
->
SubshellScope
"backgrounding &"
T_Subshell
_
_
->
SubshellScope
"(..) group"
T_BatsTest
{}
->
SubshellScope
"@bats test"
T_CoProcBody
_
_
->
SubshellScope
"coproc"
T_Redirecting
{}
->
if
fromMaybe
False
causesSubshell
...
...
@@ -334,6 +336,12 @@ getModifiedVariables t =
name
<-
getLiteralString
lhs
return
(
t
,
t
,
name
,
DataString
$
SourceFrom
[
rhs
])
T_BatsTest
{}
->
[
(
t
,
t
,
"lines"
,
DataArray
SourceExternal
),
(
t
,
t
,
"status"
,
DataString
SourceInteger
),
(
t
,
t
,
"output"
,
DataString
SourceExternal
)
]
t
@
(
T_FdRedirect
_
(
'{'
:
var
)
op
)
->
-- {foo}>&2 modifies foo
[(
t
,
t
,
takeWhile
(
/=
'}'
)
var
,
DataString
SourceInteger
)
|
not
$
isClosingFileOp
op
]
...
...
@@ -493,6 +501,12 @@ getReferencedVariables parents t =
then
concatMap
(
getIfReference
t
)
[
lhs
,
rhs
]
else
[]
T_BatsTest
{}
->
[
-- pretend @test references vars to avoid warnings
(
t
,
t
,
"lines"
),
(
t
,
t
,
"status"
),
(
t
,
t
,
"output"
)
]
t
@
(
T_FdRedirect
_
(
'{'
:
var
)
op
)
->
-- {foo}>&- references and closes foo
[(
t
,
t
,
takeWhile
(
/=
'}'
)
var
)
|
isClosingFileOp
op
]
x
->
getReferencedVariableCommand
x
...
...
ShellCheck/Data.hs
浏览文件 @
ad1a0da9
...
...
@@ -87,6 +87,7 @@ shellForExecutable name =
case
name
of
"sh"
->
return
Sh
"bash"
->
return
Bash
"bats"
->
return
Bash
"dash"
->
return
Dash
"ksh"
->
return
Ksh
"ksh88"
->
return
Ksh
...
...
ShellCheck/Parser.hs
浏览文件 @
ad1a0da9
...
...
@@ -1934,6 +1934,16 @@ readBraceGroup = called "brace group" $ do
fail
"Missing '}'"
return
$
T_BraceGroup
id
list
prop_readBatsTest
=
isOk
readBatsTest
"@test 'can parse' {
\n
true
\n
}"
readBatsTest
=
called
"bats @test"
$
do
id
<-
getNextId
try
$
string
"@test"
spacing
name
<-
readNormalWord
spacing
test
<-
readBraceGroup
return
$
T_BatsTest
id
name
test
prop_readWhileClause
=
isOk
readWhileClause
"while [[ -e foo ]]; do sleep 1; done"
readWhileClause
=
called
"while loop"
$
do
pos
<-
getPosition
...
...
@@ -2186,6 +2196,7 @@ readCompoundCommand = do
readForClause
,
readSelectClause
,
readCaseClause
,
readBatsTest
,
readFunctionDefinition
]
spacing
...
...
@@ -2534,6 +2545,7 @@ readScript = do
"ash"
,
"dash"
,
"bash"
,
"bats"
,
"ksh"
]
badShells
=
[
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录