Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
镜像
koalaman
ShellCheck
提交
944313c6
S
ShellCheck
项目概览
镜像
/
koalaman
/
ShellCheck
上一次同步 大约 1 年
通知
43
Star
0
Fork
1
代码
文件
提交
分支
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,发现更多精彩内容 >>
提交
944313c6
编写于
3月 08, 2016
作者:
V
Vidar Holen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Directives after the shebang now apply to the entire script.
Also adds support for the shell= directive.
上级
6af1aeb2
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
52 addition
and
15 deletion
+52
-15
ShellCheck/AST.hs
ShellCheck/AST.hs
+5
-1
ShellCheck/Analytics.hs
ShellCheck/Analytics.hs
+33
-11
ShellCheck/Parser.hs
ShellCheck/Parser.hs
+14
-3
未找到文件。
ShellCheck/AST.hs
浏览文件 @
944313c6
...
...
@@ -129,7 +129,11 @@ data Token =
|
T_Include
Id
Token
Token
-- . & source: SimpleCommand T_Script
deriving
(
Show
)
data
Annotation
=
DisableComment
Integer
|
SourceOverride
String
deriving
(
Show
,
Eq
)
data
Annotation
=
DisableComment
Integer
|
SourceOverride
String
|
ShellOverride
String
deriving
(
Show
,
Eq
)
data
ConditionType
=
DoubleBracket
|
SingleBracket
deriving
(
Show
,
Eq
)
-- This is an abomination.
...
...
ShellCheck/Analytics.hs
浏览文件 @
944313c6
...
...
@@ -115,14 +115,32 @@ checkList l t = concatMap (\f -> f t) l
getCode
(
TokenComment
_
(
Comment
_
c
_
))
=
c
prop_determineShell0
=
determineShell
(
T_Script
(
Id
0
)
"#!/bin/sh"
[]
)
==
Sh
prop_determineShell1
=
determineShell
(
T_Script
(
Id
0
)
"#!/usr/bin/env ksh"
[]
)
==
Ksh
prop_determineShell2
=
determineShell
(
T_Script
(
Id
0
)
""
[]
)
==
Bash
prop_determineShell3
=
determineShell
(
T_Script
(
Id
0
)
"#!/bin/sh -e"
[]
)
==
Sh
determineShell
(
T_Script
_
shebang
_
)
=
fromMaybe
Bash
.
shellForExecutable
$
shellFor
shebang
where
shellFor
s
|
"/env "
`
isInfixOf
`
s
=
head
(
drop
1
(
words
s
)
++
[
""
])
shellFor
s
|
' '
`
elem
`
s
=
shellFor
$
takeWhile
(
/=
' '
)
s
shellFor
s
=
reverse
.
takeWhile
(
/=
'/'
)
.
reverse
$
s
prop_determineShell0
=
determineShell
(
fromJust
$
pScript
"#!/bin/sh"
)
==
Sh
prop_determineShell1
=
determineShell
(
fromJust
$
pScript
"#!/usr/bin/env ksh"
)
==
Ksh
prop_determineShell2
=
determineShell
(
fromJust
$
pScript
""
)
==
Bash
prop_determineShell3
=
determineShell
(
fromJust
$
pScript
"#!/bin/sh -e"
)
==
Sh
prop_determineShell4
=
determineShell
(
fromJust
$
pScript
"#!/bin/ksh
\n
#shellcheck shell=sh
\n
foo"
)
==
Sh
prop_determineShell5
=
determineShell
(
fromJust
$
pScript
"#shellcheck shell=sh
\n
foo"
)
==
Sh
determineShell
t
=
fromMaybe
Bash
$
do
shellString
<-
foldl
mplus
Nothing
$
getCandidates
t
shellForExecutable
shellString
where
forAnnotation
t
=
case
t
of
(
ShellOverride
s
)
->
return
s
_
->
fail
""
getCandidates
::
Token
->
[
Maybe
String
]
getCandidates
t
@
(
T_Script
{})
=
[
Just
$
fromShebang
t
]
getCandidates
(
T_Annotation
_
annotations
s
)
=
map
forAnnotation
annotations
++
[
Just
$
fromShebang
s
]
fromShebang
(
T_Script
_
s
t
)
=
shellFor
s
shellFor
s
|
"/env "
`
isInfixOf
`
s
=
head
(
drop
1
(
words
s
)
++
[
""
])
shellFor
s
|
' '
`
elem
`
s
=
shellFor
$
takeWhile
(
/=
' '
)
s
shellFor
s
=
reverse
.
takeWhile
(
/=
'/'
)
.
reverse
$
s
-- Checks that are run on each node in the AST
runNodeAnalysis
f
p
t
=
execWriter
(
doAnalysis
(
f
p
)
t
)
...
...
@@ -310,14 +328,16 @@ defaultSpec root = AnalysisSpec {
checkNode
f
=
producesComments
(
runNodeAnalysis
f
)
producesComments
::
(
Parameters
->
Token
->
[
TokenComment
])
->
String
->
Maybe
Bool
producesComments
f
s
=
do
root
<-
p
rRoot
pResult
root
<-
p
Script
s
return
.
not
.
null
$
runList
(
defaultSpec
root
)
[
f
]
where
pScript
s
=
let
pSpec
=
ParseSpec
{
psFilename
=
"script"
,
psScript
=
s
}
pResult
=
runIdentity
$
parseScript
(
mockedSystemInterface
[]
)
pSpec
in
prRoot
.
runIdentity
$
parseScript
(
mockedSystemInterface
[]
)
pSpec
-- Copied from https://wiki.haskell.org/Edit_distance
dist
::
Eq
a
=>
[
a
]
->
[
a
]
->
Int
...
...
@@ -554,12 +574,14 @@ indexOfSublists sub = f 0
prop_checkShebangParameters1
=
verifyTree
checkShebangParameters
"#!/usr/bin/env bash -x
\n
echo cow"
prop_checkShebangParameters2
=
verifyNotTree
checkShebangParameters
"#! /bin/sh -l "
checkShebangParameters
p
(
T_Annotation
_
_
t
)
=
checkShebangParameters
p
t
checkShebangParameters
_
(
T_Script
id
sb
_
)
=
[
makeComment
ErrorC
id
2096
"On most OS, shebangs can only specify a single parameter."
|
length
(
words
sb
)
>
2
]
prop_checkShebang1
=
verifyNotTree
checkShebang
"#!/usr/bin/env bash -x
\n
echo cow"
prop_checkShebang2
=
verifyNotTree
checkShebang
"#! /bin/sh -l "
prop_checkShebang3
=
verifyTree
checkShebang
"ls -l"
checkShebang
params
(
T_Annotation
_
_
t
)
=
checkShebang
params
t
checkShebang
params
(
T_Script
id
sb
_
)
=
[
makeComment
ErrorC
id
2148
"Tips depend on target shell and yours is unknown. Add a shebang."
|
not
(
shellTypeSpecified
params
)
&&
sb
==
""
]
...
...
ShellCheck/Parser.hs
浏览文件 @
944313c6
...
...
@@ -772,7 +772,7 @@ prop_readAnnotation3 = isOk readAnnotation "# shellcheck disable=SC1234 source=/
readAnnotation
=
called
"shellcheck annotation"
$
do
try
readAnnotationPrefix
many1
linewhitespace
values
<-
many1
(
readDisable
<|>
readSourceOverride
)
values
<-
many1
(
readDisable
<|>
readSourceOverride
<|>
readShellOverride
)
linefeed
many
linewhitespace
return
$
concat
values
...
...
@@ -789,6 +789,14 @@ readAnnotation = called "shellcheck annotation" $ do
filename
<-
many1
$
noneOf
"
\n
"
return
[
SourceOverride
filename
]
readShellOverride
=
forKey
"shell"
$
do
pos
<-
getPosition
shell
<-
many1
$
noneOf
"
\n
"
when
(
isNothing
$
shellForExecutable
shell
)
$
parseNoteAt
pos
ErrorC
1103
"This shell type is unknown. Use e.g. sh or bash."
return
[
ShellOverride
shell
]
forKey
s
p
=
do
try
$
string
s
char
'='
...
...
@@ -2334,6 +2342,7 @@ ifParse p t f =
prop_readShebang1
=
isOk
readShebang
"#!/bin/sh
\n
"
prop_readShebang2
=
isWarning
readShebang
"!# /bin/sh
\n
"
prop_readShebang3
=
isNotOk
readShebang
"#shellcheck shell=/bin/sh
\n
"
readShebang
=
do
try
readCorrect
<|>
try
readSwapped
str
<-
many
$
noneOf
"
\r\n
"
...
...
@@ -2378,9 +2387,11 @@ readScript = do
verifyShell
pos
(
getShell
sb
)
if
isValidShell
(
getShell
sb
)
/=
Just
False
then
do
commands
<-
readCompoundListOrEmpty
annotationId
<-
getNextId
annotations
<-
readAnnotations
commands
<-
withAnnotations
annotations
readCompoundListOrEmpty
verifyEof
return
$
T_Script
id
sb
commands
return
$
T_
Annotation
annotationId
annotations
$
T_
Script
id
sb
commands
else
do
many
anyChar
return
$
T_Script
id
sb
[]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录