diff --git a/CHANGELOG.md b/CHANGELOG.md index fbc2ab7..6089c76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,11 @@ - SC2259/SC2260: Warn when redirections override pipes - 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 ### Fixed - `-f diff` no longer claims that it found more issues when it didn't diff --git a/src/ShellCheck/Checker.hs b/src/ShellCheck/Checker.hs index 120f7d8..f639ab3 100644 --- a/src/ShellCheck/Checker.hs +++ b/src/ShellCheck/Checker.hs @@ -295,6 +295,13 @@ prop_canDisableShebangWarning = null $ result 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] where result = checkWithSpec [] emptyCheckSpec { diff --git a/src/ShellCheck/Parser.hs b/src/ShellCheck/Parser.hs index 46d7ace..7eb2c32 100644 --- a/src/ShellCheck/Parser.hs +++ b/src/ShellCheck/Parser.hs @@ -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