mirror of
https://github.com/github/codeql.git
synced 2025-12-18 01:33:15 +01:00
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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
)
|
||||
)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user