From 3a7dc86de116f32f7d0f7797c745d6d26819f668 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Sat, 24 Sep 2016 13:42:20 -0700 Subject: [PATCH] Don't warn about unused vars with readonly -f --- ShellCheck/Analytics.hs | 1 + ShellCheck/AnalyzerLib.hs | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ShellCheck/Analytics.hs b/ShellCheck/Analytics.hs index 8658ab3..f91e91e 100644 --- a/ShellCheck/Analytics.hs +++ b/ShellCheck/Analytics.hs @@ -2136,6 +2136,7 @@ prop_checkUnassignedReferences22= verifyNotTree checkUnassignedReferences "echo prop_checkUnassignedReferences23= verifyTree checkUnassignedReferences "declare -a foo; foo[bar]=42;" prop_checkUnassignedReferences24= verifyNotTree checkUnassignedReferences "declare -A foo; foo[bar]=42;" prop_checkUnassignedReferences25= verifyNotTree checkUnassignedReferences "declare -A foo=(); foo[bar]=42;" +prop_checkUnassignedReferences26= verifyNotTree checkUnassignedReferences "a::b() { foo; }; readonly -f a::b" checkUnassignedReferences params t = warnings where (readMap, writeMap) = execState (mapM tally $ variableFlow params) (Map.empty, Map.empty) diff --git a/ShellCheck/AnalyzerLib.hs b/ShellCheck/AnalyzerLib.hs index e9c0a1e..78aee8c 100644 --- a/ShellCheck/AnalyzerLib.hs +++ b/ShellCheck/AnalyzerLib.hs @@ -361,7 +361,10 @@ getReferencedVariableCommand base@(T_SimpleCommand _ _ (T_NormalWord _ (T_Litera "declare" -> if any (`elem` flags) ["x", "p"] then concatMap getReference rest else [] - "readonly" -> concatMap getReference rest + "readonly" -> + if any (`elem` flags) ["f", "p"] + then [] + else concatMap getReference rest "trap" -> case rest of head:_ -> map (\x -> (head, head, x)) $ getVariablesFromLiteralToken head @@ -395,7 +398,10 @@ getModifiedVariableCommand base@(T_SimpleCommand _ _ (T_NormalWord _ (T_Literal "typeset" -> declaredVars "local" -> concatMap getModifierParamString rest - "readonly" -> concatMap getModifierParamString rest + "readonly" -> + if any (`elem` flags) ["f", "p"] + then [] + else concatMap getModifierParamString rest "set" -> maybeToList $ do params <- getSetParams rest return (base, base, "@", DataString $ SourceFrom params)