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
26 lines (24 loc) · 922 Bytes
/
DuplicateFunction.ql
File metadata and controls
26 lines (24 loc) · 922 Bytes
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
/**
* @name Duplicate function
* @description There is another function that shares a lot of code with this function.
* Extract the common parts to a shared utility function to improve maintainability.
* @kind problem
* @problem.severity recommendation
* @id js/duplicate-function
* @tags testability
* useless-code
* maintainability
* statistical
* non-attributable
* duplicate-code
* @precision medium
*/
import javascript
import CodeDuplication
import semmle.javascript.RestrictedLocations
from Function f, Function g, float percent
where duplicateContainers(f, g, percent) and
f.getNumBodyStmt() > 5 and
not duplicateContainers(f.getEnclosingStmt().getContainer(), g.getEnclosingStmt().getContainer(), _)
select (FirstLineOf)f, percent.floor() + "% of statements in " + f.describe() +
" are duplicated in $@.", (FirstLineOf)g, g.describe()