Python: Autoformat everything using qlformat.

Will need subsequent PRs fixing up test failures (due to deprecated
methods moving around), but other than that everything should be
straight-forward.
This commit is contained in:
Taus Brock-Nannestad
2020-07-07 15:43:52 +02:00
parent 993506d781
commit f07a7bf8cf
602 changed files with 26777 additions and 26790 deletions

View File

@@ -16,4 +16,4 @@ import python
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
order by ratio desc
order by ratio desc

View File

@@ -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)
src_package_count(sourceFile, package, total) and
entity = munge(sourceFile, package)
select entity, total order by total desc

View File

@@ -19,9 +19,9 @@ import semmle.python.dependencies.TechInventory
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

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

View File

@@ -14,5 +14,5 @@ import python
from Module m, int n
where
n = m.getMetrics().getNumberOfLinesOfComments() + m.getMetrics().getNumberOfLinesOfDocStrings()
n = m.getMetrics().getNumberOfLinesOfComments() + m.getMetrics().getNumberOfLinesOfDocStrings()
select m, n order by n desc

View File

@@ -16,11 +16,11 @@ 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 allowlistedLineForDuplication(f, line)
)
)
n =
count(int line |
exists(DuplicateBlock d | d.sourceFile() = f |
line in [d.sourceStartLine() .. d.sourceEndLine()] and
not allowlistedLineForDuplication(f, line)
)
)
select f, n order by n desc

View File

@@ -16,11 +16,11 @@ 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 allowlistedLineForDuplication(f, line)
)
)
n =
count(int line |
exists(SimilarBlock d | d.sourceFile() = f |
line in [d.sourceStartLine() .. d.sourceEndLine()] and
not allowlistedLineForDuplication(f, line)
)
)
select f, n order by n desc

View File

@@ -13,11 +13,11 @@ 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())
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

@@ -13,11 +13,11 @@ 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())
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

@@ -13,11 +13,11 @@ 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())
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

@@ -16,8 +16,8 @@ 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
)
avg(Commit commit, int toAvg |
commit.getAnAffectedFile() = m.getFile() and toAvg = committedFiles(commit) - 1
|
toAvg
)

View File

@@ -12,21 +12,21 @@ 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

View File

@@ -14,11 +14,11 @@ 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)
)
count(Author author |
exists(Commit e |
e = author.getACommit() and
m.getFile() = e.getAnAffectedFile() and
e.daysToNow() <= 180 and
not artificialChange(e)
)
)

View File

@@ -13,8 +13,8 @@ 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())
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

@@ -15,18 +15,19 @@ import python
* including the body (if any), as opposed to the location of its name only.
*/
class RangeFunction extends Function {
/**
* Holds if this element is at the specified location.
* The location spans column `startcolumn` of line `startline` to
* column `endcolumn` of line `endline` in file `filepath`.
* For more information, see
* [Locations](https://help.semmle.com/QL/learn-ql/ql/locations.html).
*/
predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn
) { super.getLocation().hasLocationInfo(filepath, startline, startcolumn, _, _) and
this.getBody().getLastItem().getLocation().hasLocationInfo(filepath, _, _, endline, endcolumn)
}
/**
* Holds if this element is at the specified location.
* The location spans column `startcolumn` of line `startline` to
* column `endcolumn` of line `endline` in file `filepath`.
* For more information, see
* [Locations](https://help.semmle.com/QL/learn-ql/ql/locations.html).
*/
predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn
) {
super.getLocation().hasLocationInfo(filepath, startline, startcolumn, _, _) and
this.getBody().getLastItem().getLocation().hasLocationInfo(filepath, _, _, endline, endcolumn)
}
}
/**
@@ -34,16 +35,17 @@ class RangeFunction extends Function {
* including the body (if any), as opposed to the location of its name only.
*/
class RangeClass extends Class {
/**
* Holds if this element is at the specified location.
* The location spans column `startcolumn` of line `startline` to
* column `endcolumn` of line `endline` in file `filepath`.
* For more information, see
* [Locations](https://help.semmle.com/QL/learn-ql/ql/locations.html).
*/
predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn
) { super.getLocation().hasLocationInfo(filepath, startline, startcolumn, _, _) and
this.getBody().getLastItem().getLocation().hasLocationInfo(filepath, _, _, endline, endcolumn)
}
/**
* Holds if this element is at the specified location.
* The location spans column `startcolumn` of line `startline` to
* column `endcolumn` of line `endline` in file `filepath`.
* For more information, see
* [Locations](https://help.semmle.com/QL/learn-ql/ql/locations.html).
*/
predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn
) {
super.getLocation().hasLocationInfo(filepath, startline, startcolumn, _, _) and
this.getBody().getLastItem().getLocation().hasLocationInfo(filepath, _, _, endline, endcolumn)
}
}