Python: Autoformat all .ql files.

This commit is contained in:
Taus Brock-Nannestad
2020-03-30 11:59:10 +02:00
parent b4fbfa029e
commit 87a9f51c78
491 changed files with 2649 additions and 2747 deletions

View File

@@ -8,8 +8,8 @@
* @metricAggregate avg sum max
* @tags maintainability
*/
import python
from Function f
select f, f.getMetrics().getNumberOfLinesOfCode() as n
order by n desc
select f, f.getMetrics().getNumberOfLinesOfCode() as n order by n desc

View File

@@ -13,6 +13,4 @@
import python
from ClassMetrics cls
select cls, cls.getAfferentCoupling() as n
order by n desc
select cls, cls.getAfferentCoupling() as n order by n desc

View File

@@ -13,6 +13,4 @@
import python
from ClassMetrics cls
select cls, cls.getEfferentCoupling() as n
order by n desc
select cls, cls.getEfferentCoupling() as n order by n desc

View File

@@ -10,9 +10,10 @@
* @tags maintainability
* documentation
*/
import python
from Module m, ModuleMetrics mm
where mm = m.getMetrics() and mm.getNumberOfLines() > 0
select m, 100.0 * ((float)mm.getNumberOfLinesOfComments() / (float)mm.getNumberOfLines()) as ratio
order by ratio desc
select m, 100.0 * (mm.getNumberOfLinesOfComments().(float) / mm.getNumberOfLines().(float)) as ratio
order by ratio desc

View File

@@ -11,9 +11,9 @@
* complexity
* maintainability
*/
import python
from Function func, int complexity
where complexity = func.getMetrics().getCyclomaticComplexity()
select func, complexity
order by complexity desc
select func, complexity order by complexity desc

View File

@@ -2,7 +2,7 @@
* @name External dependencies
* @description Count the number of dependencies that a Python source file has on external packages.
* @kind treemap
* @treemap.warnOn highValues
* @treemap.warnOn highValues
* @metricType externalDependency
* @precision medium
* @id py/external-dependencies
@@ -11,18 +11,18 @@
import python
import semmle.python.dependencies.TechInventory
/*
/*
* These two columns encode four logical columns:
*
*
* 1. Python source file where the dependency originates
* 2. Package Object, ideally referring to a PyPI or similar externally provided package
* 3. Version of that package Object, if known
* 4. Number of dependencies from the source file to the package
*
*
* Ideally this query would therefore return three columns,
* but this would require changing the dashboard database schema
* and dashboard extractor.
*
*
* The first column (the Python source file) is prepended with a '/'
* so that the file path matches the path used for the file in the
* dashboard database, which is implicitly relative to the source
@@ -30,15 +30,15 @@ import semmle.python.dependencies.TechInventory
*/
predicate src_package_count(File sourceFile, ExternalPackage package, int total) {
total = strictcount(AstNode src |
dependency(src, package) and
src.getLocation().getFile() = sourceFile
)
total =
strictcount(AstNode src |
dependency(src, package) and
src.getLocation().getFile() = sourceFile
)
}
from File sourceFile, int total, string entity, ExternalPackage package
where
src_package_count(sourceFile, package, total) and
entity = munge(sourceFile, package)
select entity, total
order by total desc
where
src_package_count(sourceFile, package, total) and
entity = munge(sourceFile, package)
select entity, total order by total desc

View File

@@ -16,11 +16,12 @@ import semmle.python.dependencies.TechInventory
* recover that information once we are in the dashboard database, using the
* ExternalEntity.getASourceLink() method.
*/
from File sourceFile, string entity
where
exists(PackageObject package, AstNode src |
dependency(src, package) and
src.getLocation().getFile() = sourceFile and
entity = munge(sourceFile, package)
)
exists(PackageObject package, AstNode src |
dependency(src, package) and
src.getLocation().getFile() = sourceFile and
entity = munge(sourceFile, package)
)
select entity, sourceFile

View File

@@ -9,6 +9,7 @@
* @tags modularity
* maintainability
*/
import python
from ModuleValue m, int n

View File

@@ -9,9 +9,11 @@
* @tags maintainability
* documentation
*/
import python
from Module m, ModuleMetrics mm
where mm = m.getMetrics() and mm.getNumberOfLines() > 0
select m, 100.0 * ((float)mm.getNumberOfLinesOfDocStrings() / (float)mm.getNumberOfLines()) as ratio
order by ratio desc
where mm = m.getMetrics() and mm.getNumberOfLines() > 0
select m,
100.0 * (mm.getNumberOfLinesOfDocStrings().(float) / mm.getNumberOfLines().(float)) as ratio
order by ratio desc

View File

@@ -4,7 +4,9 @@
* @id py/commit-display-strings
* @metricType commit
*/
import python
import external.VCS
from Commit c
select c.getRevisionName(), c.getMessage() + "(" + c.getDate().toString() + ")"

View File

@@ -4,8 +4,10 @@
* @id py/commit-source-links
* @metricType commit
*/
import python
import external.VCS
from Commit c, File f
where f.fromSource() and f = c.getAnAffectedFile()
select c.getRevisionName(), f

View File

@@ -13,5 +13,4 @@ import python
from Module m, int n
where n = count(Class c | c.getEnclosingModule() = m)
select m, n
order by n desc
select m, n order by n desc

View File

@@ -13,5 +13,4 @@ import python
from Module m, int n
where n = count(Function f | f.getEnclosingModule() = m and f.getName() != "lambda")
select m, n
order by n desc
select m, n order by n desc

View File

@@ -7,9 +7,9 @@
* @metricType file
* @metricAggregate avg sum max
*/
import python
from Module m, int n
where n = m.getMetrics().getNumberOfLines()
select m, n
order by n desc
select m, n order by n desc

View File

@@ -10,9 +10,9 @@
* @tags maintainability
* @id py/lines-of-code-in-files
*/
import python
from Module m, int n
where n = m.getMetrics().getNumberOfLinesOfCode()
select m, n
order by n desc
select m, n order by n desc

View File

@@ -9,9 +9,10 @@
* @precision very-high
* @id py/lines-of-comments-in-files
*/
import python
from Module m, int n
where n = m.getMetrics().getNumberOfLinesOfComments() + m.getMetrics().getNumberOfLinesOfDocStrings()
select m, n
order by n desc
where
n = m.getMetrics().getNumberOfLinesOfComments() + m.getMetrics().getNumberOfLinesOfDocStrings()
select m, n order by n desc

View File

@@ -10,17 +10,17 @@
* @tags testability
* @id py/duplicated-lines-in-files
*/
import python
import external.CodeDuplication
from File f, int n
where n = count(int line |
exists(DuplicateBlock d | d.sourceFile() = f |
line in [d.sourceStartLine()..d.sourceEndLine()] and
not whitelistedLineForDuplication(f, line)
)
)
select f, n
order by n desc
where
n =
count(int line |
exists(DuplicateBlock d | d.sourceFile() = f |
line in [d.sourceStartLine() .. d.sourceEndLine()] and
not whitelistedLineForDuplication(f, line)
)
)
select f, n order by n desc

View File

@@ -10,17 +10,17 @@
* @tags testability
* @id py/similar-lines-in-files
*/
import python
import external.CodeDuplication
from File f, int n
where n = count(int line |
exists(SimilarBlock d | d.sourceFile() = f |
line in [d.sourceStartLine()..d.sourceEndLine()] and
not whitelistedLineForDuplication(f, line)
)
)
select f, n
order by n desc
where
n =
count(int line |
exists(SimilarBlock d | d.sourceFile() = f |
line in [d.sourceStartLine() .. d.sourceEndLine()] and
not whitelistedLineForDuplication(f, line)
)
)
select f, n order by n desc

View File

@@ -6,13 +6,12 @@
* @metricType file
* @metricAggregate avg sum max
* @precision medium
* @precision very-high
* @id py/tests-in-files
*/
import python
import semmle.python.filters.Tests
from Module m, int n
where n = strictcount(Test test | test.getEnclosingModule() = m)
select m.getFile(), n
order by n desc
select m.getFile(), n order by n desc

View File

@@ -3,14 +3,12 @@
* @description The total number of calls in a function.
* @kind treemap
* @id py/number-of-calls-per-function
* @treemap.warnOn highValues
* @treemap.warnOn highValues
* @metricType callable
* @metricAggregate avg max
*/
import python
from FunctionMetrics func
select func, func.getNumberOfCalls() as n
order by n desc
select func, func.getNumberOfCalls() as n order by n desc

View File

@@ -12,7 +12,5 @@
import python
from FunctionMetrics func
select func, func.getStatementNestingDepth() as n
order by n desc
select func, func.getStatementNestingDepth() as n order by n desc

View File

@@ -7,11 +7,17 @@
* @metricType file
* @metricAggregate avg sum max
*/
import python
import external.VCS
from Module m, int n
where n = sum(Commit entry, int churn | churn = entry.getRecentChurnForFile(m.getFile()) and not artificialChange(entry) | churn)
and exists(m.getMetrics().getNumberOfLinesOfCode())
select m, n
order by n desc
where
n =
sum(Commit entry, int churn |
churn = entry.getRecentChurnForFile(m.getFile()) and not artificialChange(entry)
|
churn
) and
exists(m.getMetrics().getNumberOfLinesOfCode())
select m, n order by n desc

View File

@@ -7,11 +7,17 @@
* @metricType file
* @metricAggregate avg sum max
*/
import python
import external.VCS
from Module m, int n
where n = sum(Commit entry, int churn | churn = entry.getRecentAdditionsForFile(m.getFile()) and not artificialChange(entry) | churn)
and exists(m.getMetrics().getNumberOfLinesOfCode())
select m, n
order by n desc
where
n =
sum(Commit entry, int churn |
churn = entry.getRecentAdditionsForFile(m.getFile()) and not artificialChange(entry)
|
churn
) and
exists(m.getMetrics().getNumberOfLinesOfCode())
select m, n order by n desc

View File

@@ -7,11 +7,17 @@
* @metricType file
* @metricAggregate avg sum max
*/
import python
import external.VCS
from Module m, int n
where n = sum(Commit entry, int churn | churn = entry.getRecentDeletionsForFile(m.getFile()) and not artificialChange(entry) | churn)
and exists(m.getMetrics().getNumberOfLinesOfCode())
select m, n
order by n desc
where
n =
sum(Commit entry, int churn |
churn = entry.getRecentDeletionsForFile(m.getFile()) and not artificialChange(entry)
|
churn
) and
exists(m.getMetrics().getNumberOfLinesOfCode())
select m, n order by n desc

View File

@@ -7,10 +7,10 @@
* @metricType file
* @metricAggregate avg min max
*/
import python
import external.VCS
from Module m
where exists(m.getMetrics().getNumberOfLinesOfCode())
select m, count(Author author | author.getAnEditedFile() = m.getFile())

View File

@@ -7,14 +7,17 @@
* @metricType file
* @metricAggregate avg min max
*/
import python
import external.VCS
int committedFiles(Commit commit) {
result = count(commit.getAnAffectedFile())
}
int committedFiles(Commit commit) { result = count(commit.getAnAffectedFile()) }
from Module m
where exists(m.getMetrics().getNumberOfLinesOfCode())
select m, avg(Commit commit, int toAvg | (commit.getAnAffectedFile() = m.getFile()) and (toAvg = committedFiles(commit)-1) | toAvg)
select m,
avg(Commit commit, int toAvg |
commit.getAnAffectedFile() = m.getFile() and toAvg = committedFiles(commit) - 1
|
toAvg
)

View File

@@ -7,6 +7,7 @@
* @metricType commit
* @metricAggregate sum
*/
import python
import external.VCS

View File

@@ -5,25 +5,30 @@
* @id py/historical-number-of-re-commits
* @treemap.warnOn highValues
* @metricType file
* @metricAggregate avg min max
* @metricAggregate avg min max
*/
import python
import external.VCS
predicate inRange(Commit first, Commit second) {
first.getAnAffectedFile() = second.getAnAffectedFile() and
first != second and
exists(int n | n = first.getDate().daysTo(second.getDate()) and
n >= 0 and n < 5)
first.getAnAffectedFile() = second.getAnAffectedFile() and
first != second and
exists(int n |
n = first.getDate().daysTo(second.getDate()) and
n >= 0 and
n < 5
)
}
int recommitsForFile(File f) {
result = count(Commit recommit |
f = recommit.getAnAffectedFile() and
exists(Commit prev | inRange(prev, recommit)))
result =
count(Commit recommit |
f = recommit.getAnAffectedFile() and
exists(Commit prev | inRange(prev, recommit))
)
}
from Module m
where exists(m.getMetrics().getNumberOfLinesOfCode())
select m, recommitsForFile(m.getFile())

View File

@@ -7,10 +7,18 @@
* @metricType file
* @metricAggregate avg min max
*/
import python
import external.VCS
from Module m
where exists(m.getMetrics().getNumberOfLinesOfCode())
select m, count(Author author | exists(Commit e | e = author.getACommit() and m.getFile() = e.getAnAffectedFile() and e.daysToNow() <= 180 and not artificialChange(e)))
select m,
count(Author author |
exists(Commit e |
e = author.getACommit() and
m.getFile() = e.getAnAffectedFile() and
e.daysToNow() <= 180 and
not artificialChange(e)
)
)

View File

@@ -5,13 +5,16 @@
* @id py/historical-number-of-recent-changed-files
* @treemap.warnOn highValues
* @metricType file
* @metricAggregate avg min max
* @metricAggregate avg min max
*/
import python
import external.VCS
from Module m
where exists(Commit e | e.getAnAffectedFile() = m.getFile() and e.daysToNow() <= 180 and not artificialChange(e))
and exists(m.getMetrics().getNumberOfLinesOfCode())
where
exists(Commit e |
e.getAnAffectedFile() = m.getFile() and e.daysToNow() <= 180 and not artificialChange(e)
) and
exists(m.getMetrics().getNumberOfLinesOfCode())
select m, 1

View File

@@ -7,10 +7,10 @@
* @metricType commit
* @metricAggregate sum
*/
import python
import external.VCS
from Commit c
where c.daysToNow() <= 180 and not artificialChange(c)
select c.getRevisionName(), 1

View File

@@ -4,6 +4,7 @@
* @id py/function-display-strings
* @metricType callable
*/
import python
from Function f

View File

@@ -4,6 +4,7 @@
* @id py/function-extents
* @metricType callable
*/
import python
import Extents

View File

@@ -4,6 +4,7 @@
* @id py/function-source-links
* @metricType callable
*/
import python
from Function f

View File

@@ -4,6 +4,7 @@
* @id py/lgtm/class-display-strings
* @metricType reftype
*/
import python
from Class c

View File

@@ -4,6 +4,7 @@
* @id py/class-extents
* @metricType reftype
*/
import python
import Extents

View File

@@ -4,6 +4,7 @@
* @id py/class-source-links
* @metricType reftype
*/
import python
from Class c

View File

@@ -3,14 +3,12 @@
* @description Lack of cohesion in the methods of a class, as defined by Chidamber and Kemerer.
* @kind treemap
* @id py/lack-of-cohesion-chidamber-kemerer
* @treemap.warnOn highValues
* @treemap.warnOn highValues
* @metricType reftype
* @metricAggregate avg max
*/
import python
from ClassMetrics cls
select cls, cls.getLackOfCohesionCK() as n
order by n desc
select cls, cls.getLackOfCohesionCK() as n order by n desc

View File

@@ -3,14 +3,12 @@
* @description Lack of cohesion of a class, as defined by Hitz and Montazeri.
* @kind treemap
* @id py/lack-of-cohesion-hitz-montazeri
* @treemap.warnOn highValues
* @treemap.warnOn highValues
* @metricType reftype
* @metricAggregate avg max
*/
import python
from ClassMetrics cls
select cls, cls.getLackOfCohesionHM() as n
order by n desc
select cls, cls.getLackOfCohesionHM() as n order by n desc

View File

@@ -13,6 +13,4 @@
import python
from ModuleMetrics m
select m, m.getAfferentCoupling() as n
order by n desc
select m, m.getAfferentCoupling() as n order by n desc

View File

@@ -13,6 +13,4 @@
import python
from ModuleMetrics m
select m, m.getEfferentCoupling() as n
order by n desc
select m, m.getEfferentCoupling() as n order by n desc

View File

@@ -12,7 +12,5 @@
import python
from FunctionMetrics func
select func, func.getNumberOfParametersWithoutDefault() as n
order by n desc
select func, func.getNumberOfParametersWithoutDefault() as n order by n desc

View File

@@ -7,9 +7,9 @@
* @metricType file
* @metricAggregate avg sum max
*/
import python
from Module m, int n
where n = count(Stmt s | s.getEnclosingModule() = m)
select m, n
order by n desc
select m, n order by n desc

View File

@@ -9,6 +9,7 @@
* @metricAggregate avg max
* @tags modularity
*/
import python
from ModuleValue m, int n