forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDuplicateFunction.ql
More file actions
39 lines (36 loc) · 1.23 KB
/
DuplicateFunction.ql
File metadata and controls
39 lines (36 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
* @deprecated
* @name Duplicate function
* @description There is another identical implementation of this function. Extract the code to a common file or superclass or delegate to improve sharing.
* @kind problem
* @id cpp/duplicate-function
* @problem.severity recommendation
* @precision medium
* @tags testability
* maintainability
* duplicate-code
* non-attributable
*/
import cpp
import CodeDuplication
predicate relevant(FunctionDeclarationEntry m) {
exists(Location loc |
loc = m.getBlock().getLocation() and
(
loc.getStartLine() + 5 < loc.getEndLine() and not m.getName().matches("get%")
or
loc.getStartLine() + 10 < loc.getEndLine()
)
)
}
from FunctionDeclarationEntry m, FunctionDeclarationEntry other
where
duplicateMethod(m, other) and
relevant(m) and
not m.getFunction().isConstructedFrom(_) and
not other.getFunction().isConstructedFrom(_) and
not fileLevelDuplication(m.getFile(), other.getFile()) and
not classLevelDuplication(m.getFunction().getDeclaringType(),
other.getFunction().getDeclaringType())
select m, "Function " + m.getName() + " is duplicated at $@.", other,
other.getFile().getBaseName() + ":" + other.getLocation().getStartLine().toString()