-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathFLinesOfDuplicatedCode.ql
More file actions
39 lines (35 loc) · 1.16 KB
/
FLinesOfDuplicatedCode.ql
File metadata and controls
39 lines (35 loc) · 1.16 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
/**
* @name Duplicated lines in files
* @description The number of lines in a file (including code, comment and whitespace lines)
* occurring in a block of lines that is duplicated at least once somewhere else.
* @kind treemap
* @treemap.warnOn highValues
* @metricType file
* @metricAggregate avg sum max
* @precision high
* @id js/duplicated-lines-in-files
* @tags testability
* duplicate-code
* non-attributable
*/
import external.CodeDuplication
/**
* Holds if line `l` of file `f` should be excluded from duplicated code detection.
*
* Currently, only lines on which an import declaration occurs are excluded.
*/
predicate whitelistedLineForDuplication(File f, int l) {
exists(ImportDeclaration i | i.getFile() = f and i.getLocation().getStartLine() = l)
}
/**
* Holds if line `l` of file `f` belongs to a block of lines that is duplicated somewhere else.
*/
predicate dupLine(int l, File f) {
exists(DuplicateBlock d | d.sourceFile() = f |
l in [d.sourceStartLine() .. d.sourceEndLine()] and
not whitelistedLineForDuplication(f, l)
)
}
from File f, int n
where n = count(int l | dupLine(l, f))
select f, n order by n desc