Allow specifying ranges in disable directives
This commit is contained in:
parent
43191fa71d
commit
58783ab3cc
|
@ -1,5 +1,6 @@
|
||||||
## Git
|
## Git
|
||||||
### Added
|
### Added
|
||||||
|
- `disable` directives can now be a range, e.g. `disable=SC3000-SC4000`
|
||||||
- SC2259/SC2260: Warn when redirections override pipes
|
- SC2259/SC2260: Warn when redirections override pipes
|
||||||
- SC2261: Warn about multiple competing redirections
|
- SC2261: Warn about multiple competing redirections
|
||||||
- SC2262/SC2263: Warn about aliases declared and used in the same parsing unit
|
- SC2262/SC2263: Warn about aliases declared and used in the same parsing unit
|
||||||
|
|
|
@ -232,7 +232,8 @@ Valid keys are:
|
||||||
**disable**
|
**disable**
|
||||||
: Disables a comma separated list of error codes for the following command.
|
: Disables a comma separated list of error codes for the following command.
|
||||||
The command can be a simple command like `echo foo`, or a compound command
|
The command can be a simple command like `echo foo`, or a compound command
|
||||||
like a function definition, subshell block or loop.
|
like a function definition, subshell block or loop. A range can be
|
||||||
|
be specified with a dash, e.g. `disable=SC3000-SC4000` to exclude 3xxx.
|
||||||
|
|
||||||
**enable**
|
**enable**
|
||||||
: Enable an optional check by name, as listed with **--list-optional**.
|
: Enable an optional check by name, as listed with **--list-optional**.
|
||||||
|
|
|
@ -145,7 +145,7 @@ data InnerToken t =
|
||||||
deriving (Show, Eq, Functor, Foldable, Traversable)
|
deriving (Show, Eq, Functor, Foldable, Traversable)
|
||||||
|
|
||||||
data Annotation =
|
data Annotation =
|
||||||
DisableComment Integer
|
DisableComment Integer Integer -- [from, to)
|
||||||
| EnableComment String
|
| EnableComment String
|
||||||
| SourceOverride String
|
| SourceOverride String
|
||||||
| ShellOverride String
|
| ShellOverride String
|
||||||
|
|
|
@ -567,5 +567,5 @@ isAnnotationIgnoringCode code t =
|
||||||
T_Annotation _ anns _ -> any hasNum anns
|
T_Annotation _ anns _ -> any hasNum anns
|
||||||
_ -> False
|
_ -> False
|
||||||
where
|
where
|
||||||
hasNum (DisableComment ts) = code == ts
|
hasNum (DisableComment from to) = code >= from && code < to
|
||||||
hasNum _ = False
|
hasNum _ = False
|
||||||
|
|
|
@ -270,7 +270,7 @@ contextItemDisablesCode alsoCheckSourced code = disabling alsoCheckSourced
|
||||||
ContextAnnotation list -> any disabling' list
|
ContextAnnotation list -> any disabling' list
|
||||||
ContextSource _ -> not $ checkSourced
|
ContextSource _ -> not $ checkSourced
|
||||||
_ -> False
|
_ -> False
|
||||||
disabling' (DisableComment n) = code == n
|
disabling' (DisableComment n m) = code >= n && code < m
|
||||||
disabling' _ = False
|
disabling' _ = False
|
||||||
|
|
||||||
|
|
||||||
|
@ -973,6 +973,7 @@ prop_readAnnotation3 = isOk readAnnotation "# shellcheck disable=SC1234 source=/
|
||||||
prop_readAnnotation4 = isWarning readAnnotation "# shellcheck cats=dogs disable=SC1234\n"
|
prop_readAnnotation4 = isWarning readAnnotation "# shellcheck cats=dogs disable=SC1234\n"
|
||||||
prop_readAnnotation5 = isOk readAnnotation "# shellcheck disable=SC2002 # All cats are precious\n"
|
prop_readAnnotation5 = isOk readAnnotation "# shellcheck disable=SC2002 # All cats are precious\n"
|
||||||
prop_readAnnotation6 = isOk readAnnotation "# shellcheck disable=SC1234 # shellcheck foo=bar\n"
|
prop_readAnnotation6 = isOk readAnnotation "# shellcheck disable=SC1234 # shellcheck foo=bar\n"
|
||||||
|
prop_readAnnotation7 = isOk readAnnotation "# shellcheck disable=SC1000,SC2000-SC3000,SC1001\n"
|
||||||
readAnnotation = called "shellcheck directive" $ do
|
readAnnotation = called "shellcheck directive" $ do
|
||||||
try readAnnotationPrefix
|
try readAnnotationPrefix
|
||||||
many1 linewhitespace
|
many1 linewhitespace
|
||||||
|
@ -993,12 +994,16 @@ readAnnotationWithoutPrefix = do
|
||||||
key <- many1 (letter <|> char '-')
|
key <- many1 (letter <|> char '-')
|
||||||
char '=' <|> fail "Expected '=' after directive key"
|
char '=' <|> fail "Expected '=' after directive key"
|
||||||
annotations <- case key of
|
annotations <- case key of
|
||||||
"disable" -> readCode `sepBy` char ','
|
"disable" -> readRange `sepBy` char ','
|
||||||
where
|
where
|
||||||
|
readRange = do
|
||||||
|
from <- readCode
|
||||||
|
to <- choice [ char '-' *> readCode, return $ from+1 ]
|
||||||
|
return $ DisableComment from to
|
||||||
readCode = do
|
readCode = do
|
||||||
optional $ string "SC"
|
optional $ string "SC"
|
||||||
int <- many1 digit
|
int <- many1 digit
|
||||||
return $ DisableComment (read int)
|
return $ read int
|
||||||
|
|
||||||
"enable" -> readName `sepBy` char ','
|
"enable" -> readName `sepBy` char ','
|
||||||
where
|
where
|
||||||
|
|
Loading…
Reference in New Issue