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
|
@ -253,7 +253,11 @@ ignoreProblemsOf p = do
|
|||
shouldIgnoreCode code = do
|
||||
context <- getCurrentContexts
|
||||
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
|
||||
disabling checkSourced item =
|
||||
case item of
|
||||
|
@ -263,6 +267,8 @@ shouldIgnoreCode code = do
|
|||
disabling' (DisableComment n) = code == n
|
||||
disabling' _ = False
|
||||
|
||||
|
||||
|
||||
getCurrentAnnotations includeSource =
|
||||
concatMap get . takeWhile (not . isBoundary) <$> getCurrentContexts
|
||||
where
|
||||
|
@ -3313,16 +3319,21 @@ parseShell env name contents = do
|
|||
prRoot = Just $
|
||||
reattachHereDocs script (hereDocMap userstate)
|
||||
}
|
||||
Left err ->
|
||||
Left err -> do
|
||||
let context = contextStack state
|
||||
return newParseResult {
|
||||
prComments =
|
||||
map toPositionedComment $
|
||||
notesForContext (contextStack state)
|
||||
++ [makeErrorFor err]
|
||||
(filter (not . isIgnored context) $
|
||||
notesForContext context
|
||||
++ [makeErrorFor err])
|
||||
++ parseProblems state,
|
||||
prTokenPositions = Map.empty,
|
||||
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
|
||||
where
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue