mirror of
https://github.com/koalaman/shellcheck
synced 2025-08-22 06:13:54 -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
|
||||
,checkAliasUsedInSameParsingUnit
|
||||
,checkArrayValueUsedAsIndex
|
||||
,checkFunctionRedeclaration
|
||||
]
|
||||
|
||||
runAnalytics :: AnalysisSpec -> [TokenComment]
|
||||
|
@ -4903,5 +4904,14 @@ checkBatsTestDoesNotUseNegation params t =
|
|||
x:rest -> isLastOf t rest
|
||||
[] -> 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 []
|
||||
runTests = $( [| $(forAllProperties) (quickCheckWithResult (stdArgs { maxSuccess = 1 }) ) |])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue