Add check for function redeclaration (SC2216)

Simplify warning
This commit is contained in:
Artyom Belousov 2022-01-01 21:59:52 +03:00 committed by Artyom Belousov
commit 3b47de3f81

View file

@ -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 }) ) |])