mirror of
https://github.com/koalaman/shellcheck
synced 2025-07-08 05:51:09 -07:00
Allow disabling SC1072/SC1073 with annotations (fixes #1931)
This commit is contained in:
parent
d6adbfde78
commit
c2a15ce8e9
3 changed files with 27 additions and 4 deletions
|
@ -3,6 +3,11 @@
|
||||||
- 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
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- SC1072/SC1073 now respond to disable annotations, though ignoring parse errors
|
||||||
|
is still purely cosmetic and does not allow ShellCheck to continue.
|
||||||
|
|
||||||
|
|
||||||
## v0.7.1 - 2020-04-04
|
## v0.7.1 - 2020-04-04
|
||||||
### Fixed
|
### Fixed
|
||||||
- `-f diff` no longer claims that it found more issues when it didn't
|
- `-f diff` no longer claims that it found more issues when it didn't
|
||||||
|
|
|
@ -295,6 +295,13 @@ prop_canDisableShebangWarning = null $ result
|
||||||
csScript = "#shellcheck disable=SC2148\nfoo"
|
csScript = "#shellcheck disable=SC2148\nfoo"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prop_canDisableParseErrors = null $ result
|
||||||
|
where
|
||||||
|
result = checkWithSpec [] emptyCheckSpec {
|
||||||
|
csFilename = "file.sh",
|
||||||
|
csScript = "#shellcheck disable=SC1073,SC1072,SC2148\n()"
|
||||||
|
}
|
||||||
|
|
||||||
prop_shExtensionDoesntMatter = result == [2148]
|
prop_shExtensionDoesntMatter = result == [2148]
|
||||||
where
|
where
|
||||||
result = checkWithSpec [] emptyCheckSpec {
|
result = checkWithSpec [] emptyCheckSpec {
|
||||||
|
|
|
@ -253,7 +253,11 @@ ignoreProblemsOf p = do
|
||||||
shouldIgnoreCode code = do
|
shouldIgnoreCode code = do
|
||||||
context <- getCurrentContexts
|
context <- getCurrentContexts
|
||||||
checkSourced <- Mr.asks checkSourced
|
checkSourced <- Mr.asks checkSourced
|
||||||
return $ any (disabling checkSourced) context
|
return $ any (contextItemDisablesCode checkSourced code) context
|
||||||
|
|
||||||
|
-- Does this item on the context stack disable warnings for 'code'?
|
||||||
|
contextItemDisablesCode :: Bool -> Integer -> Context -> Bool
|
||||||
|
contextItemDisablesCode alsoCheckSourced code = disabling alsoCheckSourced
|
||||||
where
|
where
|
||||||
disabling checkSourced item =
|
disabling checkSourced item =
|
||||||
case item of
|
case item of
|
||||||
|
@ -263,6 +267,8 @@ shouldIgnoreCode code = do
|
||||||
disabling' (DisableComment n) = code == n
|
disabling' (DisableComment n) = code == n
|
||||||
disabling' _ = False
|
disabling' _ = False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
getCurrentAnnotations includeSource =
|
getCurrentAnnotations includeSource =
|
||||||
concatMap get . takeWhile (not . isBoundary) <$> getCurrentContexts
|
concatMap get . takeWhile (not . isBoundary) <$> getCurrentContexts
|
||||||
where
|
where
|
||||||
|
@ -3313,16 +3319,21 @@ parseShell env name contents = do
|
||||||
prRoot = Just $
|
prRoot = Just $
|
||||||
reattachHereDocs script (hereDocMap userstate)
|
reattachHereDocs script (hereDocMap userstate)
|
||||||
}
|
}
|
||||||
Left err ->
|
Left err -> do
|
||||||
|
let context = contextStack state
|
||||||
return newParseResult {
|
return newParseResult {
|
||||||
prComments =
|
prComments =
|
||||||
map toPositionedComment $
|
map toPositionedComment $
|
||||||
notesForContext (contextStack state)
|
(filter (not . isIgnored context) $
|
||||||
++ [makeErrorFor err]
|
notesForContext context
|
||||||
|
++ [makeErrorFor err])
|
||||||
++ parseProblems state,
|
++ parseProblems state,
|
||||||
prTokenPositions = Map.empty,
|
prTokenPositions = Map.empty,
|
||||||
prRoot = Nothing
|
prRoot = Nothing
|
||||||
}
|
}
|
||||||
|
where
|
||||||
|
-- A final pass for ignoring parse errors after failed parsing
|
||||||
|
isIgnored stack note = any (contextItemDisablesCode False (codeForParseNote note)) stack
|
||||||
|
|
||||||
notesForContext list = zipWith ($) [first, second] $ filter isName list
|
notesForContext list = zipWith ($) [first, second] $ filter isName list
|
||||||
where
|
where
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue