mirror of
https://github.com/koalaman/shellcheck
synced 2025-08-21 22:03:45 -07:00
Add check for function redeclaration (SC2216)
Simplify warning
This commit is contained in:
parent
e6e558946c
commit
3b47de3f81
1 changed files with 10 additions and 0 deletions
|
@ -66,6 +66,7 @@ treeChecks = [
|
||||||
,checkUseBeforeDefinition
|
,checkUseBeforeDefinition
|
||||||
,checkAliasUsedInSameParsingUnit
|
,checkAliasUsedInSameParsingUnit
|
||||||
,checkArrayValueUsedAsIndex
|
,checkArrayValueUsedAsIndex
|
||||||
|
,checkFunctionRedeclaration
|
||||||
]
|
]
|
||||||
|
|
||||||
runAnalytics :: AnalysisSpec -> [TokenComment]
|
runAnalytics :: AnalysisSpec -> [TokenComment]
|
||||||
|
@ -4903,5 +4904,14 @@ checkBatsTestDoesNotUseNegation params t =
|
||||||
x:rest -> isLastOf t rest
|
x:rest -> isLastOf t rest
|
||||||
[] -> False
|
[] -> False
|
||||||
|
|
||||||
|
prop_checkFunctionRedeclaration1 = verifyTree checkFunctionRedeclaration "f () { true; }; f () { true; }"
|
||||||
|
prop_checkFunctionRedeclaration2 = verifyNotTree checkFunctionRedeclaration "f () { true; }; g () { true; }"
|
||||||
|
|
||||||
|
checkFunctionRedeclaration params t = execWriter $ mapM (\ts -> warn (snd $ ts !! 1) 2216 "Function has been defined twice") $
|
||||||
|
filter (\c -> length c > 1) $ groupBy isSameFunc $ sort funcs
|
||||||
|
where
|
||||||
|
funcs = analyse findFunctions t
|
||||||
|
isSameFunc x y = fst x == fst y
|
||||||
|
|
||||||
return []
|
return []
|
||||||
runTests = $( [| $(forAllProperties) (quickCheckWithResult (stdArgs { maxSuccess = 1 }) ) |])
|
runTests = $( [| $(forAllProperties) (quickCheckWithResult (stdArgs { maxSuccess = 1 }) ) |])
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue