forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMostlyDuplicateFunction.ql
More file actions
31 lines (29 loc) · 1.11 KB
/
MostlyDuplicateFunction.ql
File metadata and controls
31 lines (29 loc) · 1.11 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
/**
* @deprecated
* @name Mostly duplicate function
* @description There is another function that shares a lot of the code with this one. Extract the code to a common file/superclass or delegate to improve sharing.
* @kind problem
* @id cpp/mostly-duplicate-function
* @problem.severity recommendation
* @precision medium
* @tags testability
* duplicate-code
* non-attributable
*/
import cpp
import CodeDuplication
from FunctionDeclarationEntry m, int covered, int total, FunctionDeclarationEntry other, int percent
where
duplicateStatements(m, other, covered, total) and
covered != total and
total > 5 and
covered * 100 / total = percent and
percent > 80 and
not m.getFunction().isConstructedFrom(_) and
not other.getFunction().isConstructedFrom(_) and
not duplicateMethod(m, other) and
not classLevelDuplication(m.getFunction().getDeclaringType(),
other.getFunction().getDeclaringType()) and
not fileLevelDuplication(m.getFile(), other.getFile())
select m, percent + "% of the statements in " + m.getName() + " are duplicated in $@.", other,
other.getFunction().getQualifiedName()