mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +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
|
where
|
||||||
exists(ClassValue c |
|
exists(ClassValue c |
|
||||||
c.declaredAttribute("__del__") = method and
|
c.declaredAttribute("__del__") = method and
|
||||||
method.getScope().getMetrics().getCyclomaticComplexity() > 3
|
method.getScope().(FunctionMetrics).getCyclomaticComplexity() > 3
|
||||||
)
|
)
|
||||||
select method, "Overly complex '__del__' method."
|
select method, "Overly complex '__del__' method."
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import python
|
import python
|
||||||
|
private import LegacyPointsTo
|
||||||
|
|
||||||
from Function f
|
from FunctionMetrics f
|
||||||
select f, f.getMetrics().getNumberOfLinesOfCode() as n order by n desc
|
select f, f.getNumberOfLinesOfCode() as n order by n desc
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import python
|
import python
|
||||||
|
private import LegacyPointsTo
|
||||||
|
|
||||||
from ClassMetrics cls
|
from ClassMetrics cls
|
||||||
select cls, cls.getAfferentCoupling() as n order by n desc
|
select cls, cls.getAfferentCoupling() as n order by n desc
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import python
|
import python
|
||||||
|
private import LegacyPointsTo
|
||||||
|
|
||||||
from ClassMetrics cls
|
from ClassMetrics cls
|
||||||
select cls, cls.getEfferentCoupling() as n order by n desc
|
select cls, cls.getEfferentCoupling() as n order by n desc
|
||||||
|
|||||||
@@ -12,8 +12,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import python
|
import python
|
||||||
|
private import LegacyPointsTo
|
||||||
|
|
||||||
from Module m, ModuleMetrics mm
|
from ModuleMetrics mm
|
||||||
where mm = m.getMetrics() and mm.getNumberOfLines() > 0
|
where mm.getNumberOfLines() > 0
|
||||||
select m, 100.0 * (mm.getNumberOfLinesOfComments().(float) / mm.getNumberOfLines().(float)) as ratio
|
select mm,
|
||||||
|
100.0 * (mm.getNumberOfLinesOfComments().(float) / mm.getNumberOfLines().(float)) as ratio
|
||||||
order by ratio desc
|
order by ratio desc
|
||||||
|
|||||||
@@ -13,7 +13,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import python
|
import python
|
||||||
|
private import LegacyPointsTo
|
||||||
|
|
||||||
from Function func, int complexity
|
from FunctionMetrics func, int complexity
|
||||||
where complexity = func.getMetrics().getCyclomaticComplexity()
|
where complexity = func.getCyclomaticComplexity()
|
||||||
select func, complexity order by complexity desc
|
select func, complexity order by complexity desc
|
||||||
|
|||||||
@@ -11,9 +11,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import python
|
import python
|
||||||
|
private import LegacyPointsTo
|
||||||
|
|
||||||
from Module m, ModuleMetrics mm
|
from ModuleMetrics mm
|
||||||
where mm = m.getMetrics() and mm.getNumberOfLines() > 0
|
where mm.getNumberOfLines() > 0
|
||||||
select m,
|
select mm,
|
||||||
100.0 * (mm.getNumberOfLinesOfDocStrings().(float) / mm.getNumberOfLines().(float)) as ratio
|
100.0 * (mm.getNumberOfLinesOfDocStrings().(float) / mm.getNumberOfLines().(float)) as ratio
|
||||||
order by ratio desc
|
order by ratio desc
|
||||||
|
|||||||
@@ -9,7 +9,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import python
|
import python
|
||||||
|
private import LegacyPointsTo
|
||||||
|
|
||||||
from Module m, int n
|
from ModuleMetrics m, int n
|
||||||
where n = m.getMetrics().getNumberOfLines()
|
where n = m.getNumberOfLines()
|
||||||
select m, n order by n desc
|
select m, n order by n desc
|
||||||
|
|||||||
@@ -11,7 +11,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import python
|
import python
|
||||||
|
private import LegacyPointsTo
|
||||||
|
|
||||||
from Module m, int n
|
from ModuleMetrics m, int n
|
||||||
where n = m.getMetrics().getNumberOfLinesOfCode()
|
where n = m.getNumberOfLinesOfCode()
|
||||||
select m, n order by n desc
|
select m, n order by n desc
|
||||||
|
|||||||
@@ -10,8 +10,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import python
|
import python
|
||||||
|
private import LegacyPointsTo
|
||||||
|
|
||||||
from Module m, int n
|
from ModuleMetrics m, int n
|
||||||
where
|
where n = m.getNumberOfLinesOfComments() + m.getNumberOfLinesOfDocStrings()
|
||||||
n = m.getMetrics().getNumberOfLinesOfComments() + m.getMetrics().getNumberOfLinesOfDocStrings()
|
|
||||||
select m, n order by n desc
|
select m, n order by n desc
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import python
|
import python
|
||||||
|
private import LegacyPointsTo
|
||||||
|
|
||||||
from FunctionMetrics func
|
from FunctionMetrics func
|
||||||
select func, func.getNumberOfCalls() as n order by n desc
|
select func, func.getNumberOfCalls() as n order by n desc
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import python
|
import python
|
||||||
|
private import LegacyPointsTo
|
||||||
|
|
||||||
from FunctionMetrics func
|
from FunctionMetrics func
|
||||||
select func, func.getStatementNestingDepth() as n order by n desc
|
select func, func.getStatementNestingDepth() as n order by n desc
|
||||||
|
|||||||
@@ -10,8 +10,9 @@
|
|||||||
|
|
||||||
import python
|
import python
|
||||||
import external.VCS
|
import external.VCS
|
||||||
|
private import LegacyPointsTo
|
||||||
|
|
||||||
from Module m, int n
|
from ModuleMetrics m, int n
|
||||||
where
|
where
|
||||||
n =
|
n =
|
||||||
sum(Commit entry, int churn |
|
sum(Commit entry, int churn |
|
||||||
@@ -19,5 +20,5 @@ where
|
|||||||
|
|
|
|
||||||
churn
|
churn
|
||||||
) and
|
) and
|
||||||
exists(m.getMetrics().getNumberOfLinesOfCode())
|
exists(m.getNumberOfLinesOfCode())
|
||||||
select m, n order by n desc
|
select m, n order by n desc
|
||||||
|
|||||||
@@ -10,8 +10,9 @@
|
|||||||
|
|
||||||
import python
|
import python
|
||||||
import external.VCS
|
import external.VCS
|
||||||
|
private import LegacyPointsTo
|
||||||
|
|
||||||
from Module m, int n
|
from ModuleMetrics m, int n
|
||||||
where
|
where
|
||||||
n =
|
n =
|
||||||
sum(Commit entry, int churn |
|
sum(Commit entry, int churn |
|
||||||
@@ -19,5 +20,5 @@ where
|
|||||||
|
|
|
|
||||||
churn
|
churn
|
||||||
) and
|
) and
|
||||||
exists(m.getMetrics().getNumberOfLinesOfCode())
|
exists(m.getNumberOfLinesOfCode())
|
||||||
select m, n order by n desc
|
select m, n order by n desc
|
||||||
|
|||||||
@@ -10,8 +10,9 @@
|
|||||||
|
|
||||||
import python
|
import python
|
||||||
import external.VCS
|
import external.VCS
|
||||||
|
private import LegacyPointsTo
|
||||||
|
|
||||||
from Module m, int n
|
from ModuleMetrics m, int n
|
||||||
where
|
where
|
||||||
n =
|
n =
|
||||||
sum(Commit entry, int churn |
|
sum(Commit entry, int churn |
|
||||||
@@ -19,5 +20,5 @@ where
|
|||||||
|
|
|
|
||||||
churn
|
churn
|
||||||
) and
|
) and
|
||||||
exists(m.getMetrics().getNumberOfLinesOfCode())
|
exists(m.getNumberOfLinesOfCode())
|
||||||
select m, n order by n desc
|
select m, n order by n desc
|
||||||
|
|||||||
@@ -10,7 +10,8 @@
|
|||||||
|
|
||||||
import python
|
import python
|
||||||
import external.VCS
|
import external.VCS
|
||||||
|
private import LegacyPointsTo
|
||||||
|
|
||||||
from Module m
|
from ModuleMetrics m
|
||||||
where exists(m.getMetrics().getNumberOfLinesOfCode())
|
where exists(m.getNumberOfLinesOfCode())
|
||||||
select m, count(Author author | author.getAnEditedFile() = m.getFile())
|
select m, count(Author author | author.getAnEditedFile() = m.getFile())
|
||||||
|
|||||||
@@ -10,11 +10,12 @@
|
|||||||
|
|
||||||
import python
|
import python
|
||||||
import external.VCS
|
import external.VCS
|
||||||
|
private import LegacyPointsTo
|
||||||
|
|
||||||
int committedFiles(Commit commit) { result = count(commit.getAnAffectedFile()) }
|
int committedFiles(Commit commit) { result = count(commit.getAnAffectedFile()) }
|
||||||
|
|
||||||
from Module m
|
from ModuleMetrics m
|
||||||
where exists(m.getMetrics().getNumberOfLinesOfCode())
|
where exists(m.getNumberOfLinesOfCode())
|
||||||
select m,
|
select m,
|
||||||
avg(Commit commit, int toAvg |
|
avg(Commit commit, int toAvg |
|
||||||
commit.getAnAffectedFile() = m.getFile() and toAvg = committedFiles(commit) - 1
|
commit.getAnAffectedFile() = m.getFile() and toAvg = committedFiles(commit) - 1
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
import python
|
import python
|
||||||
import external.VCS
|
import external.VCS
|
||||||
|
private import LegacyPointsTo
|
||||||
|
|
||||||
predicate inRange(Commit first, Commit second) {
|
predicate inRange(Commit first, Commit second) {
|
||||||
first.getAnAffectedFile() = second.getAnAffectedFile() and
|
first.getAnAffectedFile() = second.getAnAffectedFile() and
|
||||||
@@ -29,6 +30,6 @@ int recommitsForFile(File f) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
from Module m
|
from ModuleMetrics m
|
||||||
where exists(m.getMetrics().getNumberOfLinesOfCode())
|
where exists(m.getNumberOfLinesOfCode())
|
||||||
select m, recommitsForFile(m.getFile())
|
select m, recommitsForFile(m.getFile())
|
||||||
|
|||||||
@@ -10,9 +10,10 @@
|
|||||||
|
|
||||||
import python
|
import python
|
||||||
import external.VCS
|
import external.VCS
|
||||||
|
private import LegacyPointsTo
|
||||||
|
|
||||||
from Module m
|
from ModuleMetrics m
|
||||||
where exists(m.getMetrics().getNumberOfLinesOfCode())
|
where exists(m.getNumberOfLinesOfCode())
|
||||||
select m,
|
select m,
|
||||||
count(Author author |
|
count(Author author |
|
||||||
exists(Commit e |
|
exists(Commit e |
|
||||||
|
|||||||
@@ -10,11 +10,12 @@
|
|||||||
|
|
||||||
import python
|
import python
|
||||||
import external.VCS
|
import external.VCS
|
||||||
|
private import LegacyPointsTo
|
||||||
|
|
||||||
from Module m
|
from ModuleMetrics m
|
||||||
where
|
where
|
||||||
exists(Commit e |
|
exists(Commit e |
|
||||||
e.getAnAffectedFile() = m.getFile() and e.daysToNow() <= 180 and not artificialChange(e)
|
e.getAnAffectedFile() = m.getFile() and e.daysToNow() <= 180 and not artificialChange(e)
|
||||||
) and
|
) and
|
||||||
exists(m.getMetrics().getNumberOfLinesOfCode())
|
exists(m.getNumberOfLinesOfCode())
|
||||||
select m, 1
|
select m, 1
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import python
|
import python
|
||||||
|
private import LegacyPointsTo
|
||||||
|
|
||||||
from ClassMetrics cls
|
from ClassMetrics cls
|
||||||
select cls, cls.getLackOfCohesionCK() as n order by n desc
|
select cls, cls.getLackOfCohesionCK() as n order by n desc
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import python
|
import python
|
||||||
|
private import LegacyPointsTo
|
||||||
|
|
||||||
from ClassMetrics cls
|
from ClassMetrics cls
|
||||||
select cls, cls.getLackOfCohesionHM() as n order by n desc
|
select cls, cls.getLackOfCohesionHM() as n order by n desc
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import python
|
import python
|
||||||
|
private import LegacyPointsTo
|
||||||
|
|
||||||
from ModuleMetrics m
|
from ModuleMetrics m
|
||||||
select m, m.getAfferentCoupling() as n order by n desc
|
select m, m.getAfferentCoupling() as n order by n desc
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import python
|
import python
|
||||||
|
private import LegacyPointsTo
|
||||||
|
|
||||||
from ModuleMetrics m
|
from ModuleMetrics m
|
||||||
select m, m.getEfferentCoupling() as n order by n desc
|
select m, m.getEfferentCoupling() as n order by n desc
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import python
|
import python
|
||||||
|
private import LegacyPointsTo
|
||||||
|
|
||||||
from FunctionMetrics func
|
from FunctionMetrics func
|
||||||
select func, func.getNumberOfParametersWithoutDefault() as n order by n desc
|
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 exists(FunctionValue fo, FunctionValue base | fo.overrides(base) and fo.getScope() = f |
|
||||||
not function_needs_docstring(base.getScope())
|
not function_needs_docstring(base.getScope())
|
||||||
) and
|
) and
|
||||||
f.getName() != "lambda" and
|
f.getName() != "lambda" and
|
||||||
(f.getMetrics().getNumberOfLinesOfCode() - count(f.getADecorator())) > 2 and
|
(f.getNumberOfLinesOfCode() - count(f.getADecorator())) > 2 and
|
||||||
not exists(PythonPropertyObject p |
|
not exists(PythonPropertyObject p |
|
||||||
p.getGetter().getFunction() = f or
|
p.getGetter().getFunction() = f or
|
||||||
p.getSetter().getFunction() = f
|
p.getSetter().getFunction() = f
|
||||||
|
|||||||
@@ -10,5 +10,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import python
|
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 python
|
||||||
import semmle.python.filters.GeneratedCode
|
import semmle.python.filters.GeneratedCode
|
||||||
|
private import LegacyPointsTo
|
||||||
|
|
||||||
select sum(Module m |
|
select sum(ModuleMetrics m |
|
||||||
exists(m.getFile().getRelativePath()) and
|
exists(m.getFile().getRelativePath()) and
|
||||||
not m.getFile() instanceof GeneratedFile
|
not m.getFile() instanceof GeneratedFile
|
||||||
|
|
|
|
||||||
m.getMetrics().getNumberOfLinesOfCode()
|
m.getNumberOfLinesOfCode()
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import python
|
import python
|
||||||
|
private import LegacyPointsTo
|
||||||
|
|
||||||
from string key, string value
|
from string key, string value
|
||||||
where
|
where
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
import python
|
import python
|
||||||
|
private import LegacyPointsTo
|
||||||
|
|
||||||
from string msg, int cnt, int sort
|
from string msg, int cnt, int sort
|
||||||
where
|
where
|
||||||
sort = 0 and
|
sort = 0 and
|
||||||
msg = "Lines of code in DB" and
|
msg = "Lines of code in DB" and
|
||||||
cnt = sum(Module m | | m.getMetrics().getNumberOfLinesOfCode())
|
cnt = sum(ModuleMetrics m | | m.getNumberOfLinesOfCode())
|
||||||
or
|
or
|
||||||
sort = 1 and
|
sort = 1 and
|
||||||
msg = "Lines of code in repo" and
|
msg = "Lines of code in repo" and
|
||||||
cnt =
|
cnt = sum(ModuleMetrics m | exists(m.getFile().getRelativePath()) | m.getNumberOfLinesOfCode())
|
||||||
sum(Module m | exists(m.getFile().getRelativePath()) | m.getMetrics().getNumberOfLinesOfCode())
|
|
||||||
or
|
or
|
||||||
sort = 2 and
|
sort = 2 and
|
||||||
msg = "Files" and
|
msg = "Files" and
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import python
|
import python
|
||||||
|
private import LegacyPointsTo
|
||||||
|
|
||||||
from Module m, int n
|
from ModuleMetrics m, int n
|
||||||
where n = m.getMetrics().getNumberOfLinesOfComments()
|
where n = m.getNumberOfLinesOfComments()
|
||||||
select m.toString(), n
|
select m.toString(), n
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import python
|
import python
|
||||||
|
private import LegacyPointsTo
|
||||||
|
|
||||||
from Function func
|
from FunctionMetrics func
|
||||||
select func.toString(), func.getMetrics().getCyclomaticComplexity()
|
select func.toString(), func.getCyclomaticComplexity()
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import python
|
import python
|
||||||
|
private import LegacyPointsTo
|
||||||
|
|
||||||
from Scope s, int n
|
from Scope s, int n
|
||||||
where
|
where
|
||||||
exists(Function f | f = s | n = f.getMetrics().getNumberOfLines())
|
exists(FunctionMetrics f | f = s | n = f.getNumberOfLines())
|
||||||
or
|
or
|
||||||
exists(Module m | m = s | n = m.getMetrics().getNumberOfLines())
|
exists(ModuleMetrics m | m = s | n = m.getNumberOfLines())
|
||||||
select s.toString(), n
|
select s.toString(), n
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import python
|
import python
|
||||||
|
private import LegacyPointsTo
|
||||||
|
|
||||||
from Module m, ModuleMetrics mm
|
from ModuleMetrics mm
|
||||||
where mm = m.getMetrics() and mm.getNumberOfLines() > 0
|
where mm.getNumberOfLines() > 0
|
||||||
select m, 100.0 * (mm.getNumberOfLinesOfCode().(float) / mm.getNumberOfLines().(float)) as ratio
|
select mm, 100.0 * (mm.getNumberOfLinesOfCode().(float) / mm.getNumberOfLines().(float)) as ratio
|
||||||
order by ratio desc
|
order by ratio desc
|
||||||
|
|||||||
Reference in New Issue
Block a user