mirror of
https://github.com/github/codeql.git
synced 2025-12-16 08:43:11 +01:00
Python: Fix all metrics-related compilation failures
In hindsight, having a `.getMetrics()` method that just returns `this` is somewhat weird. It's possible that it predates the existence of the inline cast, however.
This commit is contained in:
@@ -18,6 +18,6 @@ from FunctionValue method
|
||||
where
|
||||
exists(ClassValue c |
|
||||
c.declaredAttribute("__del__") = method and
|
||||
method.getScope().getMetrics().getCyclomaticComplexity() > 3
|
||||
method.getScope().(FunctionMetrics).getCyclomaticComplexity() > 3
|
||||
)
|
||||
select method, "Overly complex '__del__' method."
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
*/
|
||||
|
||||
import python
|
||||
private import LegacyPointsTo
|
||||
|
||||
from Function f
|
||||
select f, f.getMetrics().getNumberOfLinesOfCode() as n order by n desc
|
||||
from FunctionMetrics f
|
||||
select f, f.getNumberOfLinesOfCode() as n order by n desc
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
*/
|
||||
|
||||
import python
|
||||
private import LegacyPointsTo
|
||||
|
||||
from ClassMetrics cls
|
||||
select cls, cls.getAfferentCoupling() as n order by n desc
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
*/
|
||||
|
||||
import python
|
||||
private import LegacyPointsTo
|
||||
|
||||
from ClassMetrics cls
|
||||
select cls, cls.getEfferentCoupling() as n order by n desc
|
||||
|
||||
@@ -12,8 +12,10 @@
|
||||
*/
|
||||
|
||||
import python
|
||||
private import LegacyPointsTo
|
||||
|
||||
from Module m, ModuleMetrics mm
|
||||
where mm = m.getMetrics() and mm.getNumberOfLines() > 0
|
||||
select m, 100.0 * (mm.getNumberOfLinesOfComments().(float) / mm.getNumberOfLines().(float)) as ratio
|
||||
from ModuleMetrics mm
|
||||
where mm.getNumberOfLines() > 0
|
||||
select mm,
|
||||
100.0 * (mm.getNumberOfLinesOfComments().(float) / mm.getNumberOfLines().(float)) as ratio
|
||||
order by ratio desc
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
*/
|
||||
|
||||
import python
|
||||
private import LegacyPointsTo
|
||||
|
||||
from Function func, int complexity
|
||||
where complexity = func.getMetrics().getCyclomaticComplexity()
|
||||
from FunctionMetrics func, int complexity
|
||||
where complexity = func.getCyclomaticComplexity()
|
||||
select func, complexity order by complexity desc
|
||||
|
||||
@@ -11,9 +11,10 @@
|
||||
*/
|
||||
|
||||
import python
|
||||
private import LegacyPointsTo
|
||||
|
||||
from Module m, ModuleMetrics mm
|
||||
where mm = m.getMetrics() and mm.getNumberOfLines() > 0
|
||||
select m,
|
||||
from ModuleMetrics mm
|
||||
where mm.getNumberOfLines() > 0
|
||||
select mm,
|
||||
100.0 * (mm.getNumberOfLinesOfDocStrings().(float) / mm.getNumberOfLines().(float)) as ratio
|
||||
order by ratio desc
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
*/
|
||||
|
||||
import python
|
||||
private import LegacyPointsTo
|
||||
|
||||
from Module m, int n
|
||||
where n = m.getMetrics().getNumberOfLines()
|
||||
from ModuleMetrics m, int n
|
||||
where n = m.getNumberOfLines()
|
||||
select m, n order by n desc
|
||||
|
||||
@@ -11,7 +11,8 @@
|
||||
*/
|
||||
|
||||
import python
|
||||
private import LegacyPointsTo
|
||||
|
||||
from Module m, int n
|
||||
where n = m.getMetrics().getNumberOfLinesOfCode()
|
||||
from ModuleMetrics m, int n
|
||||
where n = m.getNumberOfLinesOfCode()
|
||||
select m, n order by n desc
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
*/
|
||||
|
||||
import python
|
||||
private import LegacyPointsTo
|
||||
|
||||
from Module m, int n
|
||||
where
|
||||
n = m.getMetrics().getNumberOfLinesOfComments() + m.getMetrics().getNumberOfLinesOfDocStrings()
|
||||
from ModuleMetrics m, int n
|
||||
where n = m.getNumberOfLinesOfComments() + m.getNumberOfLinesOfDocStrings()
|
||||
select m, n order by n desc
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
*/
|
||||
|
||||
import python
|
||||
private import LegacyPointsTo
|
||||
|
||||
from FunctionMetrics func
|
||||
select func, func.getNumberOfCalls() as n order by n desc
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
*/
|
||||
|
||||
import python
|
||||
private import LegacyPointsTo
|
||||
|
||||
from FunctionMetrics func
|
||||
select func, func.getStatementNestingDepth() as n order by n desc
|
||||
|
||||
@@ -10,8 +10,9 @@
|
||||
|
||||
import python
|
||||
import external.VCS
|
||||
private import LegacyPointsTo
|
||||
|
||||
from Module m, int n
|
||||
from ModuleMetrics m, int n
|
||||
where
|
||||
n =
|
||||
sum(Commit entry, int churn |
|
||||
@@ -19,5 +20,5 @@ where
|
||||
|
|
||||
churn
|
||||
) and
|
||||
exists(m.getMetrics().getNumberOfLinesOfCode())
|
||||
exists(m.getNumberOfLinesOfCode())
|
||||
select m, n order by n desc
|
||||
|
||||
@@ -10,8 +10,9 @@
|
||||
|
||||
import python
|
||||
import external.VCS
|
||||
private import LegacyPointsTo
|
||||
|
||||
from Module m, int n
|
||||
from ModuleMetrics m, int n
|
||||
where
|
||||
n =
|
||||
sum(Commit entry, int churn |
|
||||
@@ -19,5 +20,5 @@ where
|
||||
|
|
||||
churn
|
||||
) and
|
||||
exists(m.getMetrics().getNumberOfLinesOfCode())
|
||||
exists(m.getNumberOfLinesOfCode())
|
||||
select m, n order by n desc
|
||||
|
||||
@@ -10,8 +10,9 @@
|
||||
|
||||
import python
|
||||
import external.VCS
|
||||
private import LegacyPointsTo
|
||||
|
||||
from Module m, int n
|
||||
from ModuleMetrics m, int n
|
||||
where
|
||||
n =
|
||||
sum(Commit entry, int churn |
|
||||
@@ -19,5 +20,5 @@ where
|
||||
|
|
||||
churn
|
||||
) and
|
||||
exists(m.getMetrics().getNumberOfLinesOfCode())
|
||||
exists(m.getNumberOfLinesOfCode())
|
||||
select m, n order by n desc
|
||||
|
||||
@@ -10,7 +10,8 @@
|
||||
|
||||
import python
|
||||
import external.VCS
|
||||
private import LegacyPointsTo
|
||||
|
||||
from Module m
|
||||
where exists(m.getMetrics().getNumberOfLinesOfCode())
|
||||
from ModuleMetrics m
|
||||
where exists(m.getNumberOfLinesOfCode())
|
||||
select m, count(Author author | author.getAnEditedFile() = m.getFile())
|
||||
|
||||
@@ -10,11 +10,12 @@
|
||||
|
||||
import python
|
||||
import external.VCS
|
||||
private import LegacyPointsTo
|
||||
|
||||
int committedFiles(Commit commit) { result = count(commit.getAnAffectedFile()) }
|
||||
|
||||
from Module m
|
||||
where exists(m.getMetrics().getNumberOfLinesOfCode())
|
||||
from ModuleMetrics m
|
||||
where exists(m.getNumberOfLinesOfCode())
|
||||
select m,
|
||||
avg(Commit commit, int toAvg |
|
||||
commit.getAnAffectedFile() = m.getFile() and toAvg = committedFiles(commit) - 1
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
import python
|
||||
import external.VCS
|
||||
private import LegacyPointsTo
|
||||
|
||||
predicate inRange(Commit first, Commit second) {
|
||||
first.getAnAffectedFile() = second.getAnAffectedFile() and
|
||||
@@ -29,6 +30,6 @@ int recommitsForFile(File f) {
|
||||
)
|
||||
}
|
||||
|
||||
from Module m
|
||||
where exists(m.getMetrics().getNumberOfLinesOfCode())
|
||||
from ModuleMetrics m
|
||||
where exists(m.getNumberOfLinesOfCode())
|
||||
select m, recommitsForFile(m.getFile())
|
||||
|
||||
@@ -10,9 +10,10 @@
|
||||
|
||||
import python
|
||||
import external.VCS
|
||||
private import LegacyPointsTo
|
||||
|
||||
from Module m
|
||||
where exists(m.getMetrics().getNumberOfLinesOfCode())
|
||||
from ModuleMetrics m
|
||||
where exists(m.getNumberOfLinesOfCode())
|
||||
select m,
|
||||
count(Author author |
|
||||
exists(Commit e |
|
||||
|
||||
@@ -10,11 +10,12 @@
|
||||
|
||||
import python
|
||||
import external.VCS
|
||||
private import LegacyPointsTo
|
||||
|
||||
from Module m
|
||||
from ModuleMetrics m
|
||||
where
|
||||
exists(Commit e |
|
||||
e.getAnAffectedFile() = m.getFile() and e.daysToNow() <= 180 and not artificialChange(e)
|
||||
) and
|
||||
exists(m.getMetrics().getNumberOfLinesOfCode())
|
||||
exists(m.getNumberOfLinesOfCode())
|
||||
select m, 1
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
*/
|
||||
|
||||
import python
|
||||
private import LegacyPointsTo
|
||||
|
||||
from ClassMetrics cls
|
||||
select cls, cls.getLackOfCohesionCK() as n order by n desc
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
*/
|
||||
|
||||
import python
|
||||
private import LegacyPointsTo
|
||||
|
||||
from ClassMetrics cls
|
||||
select cls, cls.getLackOfCohesionHM() as n order by n desc
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
*/
|
||||
|
||||
import python
|
||||
private import LegacyPointsTo
|
||||
|
||||
from ModuleMetrics m
|
||||
select m, m.getAfferentCoupling() as n order by n desc
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
*/
|
||||
|
||||
import python
|
||||
private import LegacyPointsTo
|
||||
|
||||
from ModuleMetrics m
|
||||
select m, m.getEfferentCoupling() as n order by n desc
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
*/
|
||||
|
||||
import python
|
||||
private import LegacyPointsTo
|
||||
|
||||
from FunctionMetrics func
|
||||
select func, func.getNumberOfParametersWithoutDefault() as n order by n desc
|
||||
|
||||
@@ -28,12 +28,12 @@ predicate needs_docstring(Scope s) {
|
||||
)
|
||||
}
|
||||
|
||||
predicate function_needs_docstring(Function f) {
|
||||
predicate function_needs_docstring(FunctionMetrics f) {
|
||||
not exists(FunctionValue fo, FunctionValue base | fo.overrides(base) and fo.getScope() = f |
|
||||
not function_needs_docstring(base.getScope())
|
||||
) and
|
||||
f.getName() != "lambda" and
|
||||
(f.getMetrics().getNumberOfLinesOfCode() - count(f.getADecorator())) > 2 and
|
||||
(f.getNumberOfLinesOfCode() - count(f.getADecorator())) > 2 and
|
||||
not exists(PythonPropertyObject p |
|
||||
p.getGetter().getFunction() = f or
|
||||
p.getSetter().getFunction() = f
|
||||
|
||||
@@ -10,5 +10,6 @@
|
||||
*/
|
||||
|
||||
import python
|
||||
private import LegacyPointsTo
|
||||
|
||||
select sum(Module m | | m.getMetrics().getNumberOfLinesOfCode())
|
||||
select sum(ModuleMetrics m | | m.getNumberOfLinesOfCode())
|
||||
|
||||
@@ -14,10 +14,11 @@
|
||||
|
||||
import python
|
||||
import semmle.python.filters.GeneratedCode
|
||||
private import LegacyPointsTo
|
||||
|
||||
select sum(Module m |
|
||||
select sum(ModuleMetrics m |
|
||||
exists(m.getFile().getRelativePath()) and
|
||||
not m.getFile() instanceof GeneratedFile
|
||||
|
|
||||
m.getMetrics().getNumberOfLinesOfCode()
|
||||
m.getNumberOfLinesOfCode()
|
||||
)
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
*/
|
||||
|
||||
import python
|
||||
private import LegacyPointsTo
|
||||
|
||||
from string key, string value
|
||||
where
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import python
|
||||
private import LegacyPointsTo
|
||||
|
||||
from string msg, int cnt, int sort
|
||||
where
|
||||
sort = 0 and
|
||||
msg = "Lines of code in DB" and
|
||||
cnt = sum(Module m | | m.getMetrics().getNumberOfLinesOfCode())
|
||||
cnt = sum(ModuleMetrics m | | m.getNumberOfLinesOfCode())
|
||||
or
|
||||
sort = 1 and
|
||||
msg = "Lines of code in repo" and
|
||||
cnt =
|
||||
sum(Module m | exists(m.getFile().getRelativePath()) | m.getMetrics().getNumberOfLinesOfCode())
|
||||
cnt = sum(ModuleMetrics m | exists(m.getFile().getRelativePath()) | m.getNumberOfLinesOfCode())
|
||||
or
|
||||
sort = 2 and
|
||||
msg = "Files" and
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import python
|
||||
private import LegacyPointsTo
|
||||
|
||||
from Module m, int n
|
||||
where n = m.getMetrics().getNumberOfLinesOfComments()
|
||||
from ModuleMetrics m, int n
|
||||
where n = m.getNumberOfLinesOfComments()
|
||||
select m.toString(), n
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import python
|
||||
private import LegacyPointsTo
|
||||
|
||||
from Function func
|
||||
select func.toString(), func.getMetrics().getCyclomaticComplexity()
|
||||
from FunctionMetrics func
|
||||
select func.toString(), func.getCyclomaticComplexity()
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import python
|
||||
private import LegacyPointsTo
|
||||
|
||||
from Scope s, int n
|
||||
where
|
||||
exists(Function f | f = s | n = f.getMetrics().getNumberOfLines())
|
||||
exists(FunctionMetrics f | f = s | n = f.getNumberOfLines())
|
||||
or
|
||||
exists(Module m | m = s | n = m.getMetrics().getNumberOfLines())
|
||||
exists(ModuleMetrics m | m = s | n = m.getNumberOfLines())
|
||||
select s.toString(), n
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import python
|
||||
private import LegacyPointsTo
|
||||
|
||||
from Module m, ModuleMetrics mm
|
||||
where mm = m.getMetrics() and mm.getNumberOfLines() > 0
|
||||
select m, 100.0 * (mm.getNumberOfLinesOfCode().(float) / mm.getNumberOfLines().(float)) as ratio
|
||||
from ModuleMetrics mm
|
||||
where mm.getNumberOfLines() > 0
|
||||
select mm, 100.0 * (mm.getNumberOfLinesOfCode().(float) / mm.getNumberOfLines().(float)) as ratio
|
||||
order by ratio desc
|
||||
|
||||
Reference in New Issue
Block a user