Skip to content

Commit 0a8869c

Browse files
authored
Merge pull request github#15385 from geoffw0/swiftfiles
Swift: Report any extracted file as successfully extracted
2 parents 6533269 + a39bb8c commit 0a8869c

File tree

9 files changed

+38
-5
lines changed

9 files changed

+38
-5
lines changed

swift/ql/lib/codeql/swift/elements/File.qll

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,23 @@ class File extends Generated::File {
3232
)
3333
)
3434
}
35+
36+
/**
37+
* Gets the relative path of this file from the root folder of the
38+
* analyzed source location. The relative path of the root folder itself
39+
* would be the empty string.
40+
*
41+
* This has no result if the file is outside the source root, that is,
42+
* if the root folder is not a reflexive, transitive parent of this file.
43+
*/
44+
string getRelativePath() {
45+
exists(string absPath, string pref |
46+
absPath = this.getAbsolutePath() and sourceLocationPrefix(pref)
47+
|
48+
absPath = pref and result = ""
49+
or
50+
absPath = pref.regexpReplaceAll("/$", "") + "/" + result and
51+
not result.matches("/%")
52+
)
53+
}
3554
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The diagnostic query `swift/diagnostics/successfully-extracted-files` now considers any Swift file seen during extraction, even one with some errors, to be extracted / scanned. This affects the Code Scanning UI measure of scanned Swift files.
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
2-
* @name Successfully extracted files
3-
* @description Lists all files in the source code directory that were extracted without encountering a problem in the file.
2+
* @name Extracted files
3+
* @description Lists all files in the source code directory that were extracted.
44
* @kind diagnostic
55
* @id swift/diagnostics/successfully-extracted-files
66
* @tags successfully-extracted-files
@@ -9,5 +9,5 @@
99
import swift
1010

1111
from File f
12-
where f.isSuccessfullyExtracted()
12+
where exists(f.getRelativePath())
1313
select f, "File successfully extracted."
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| error.swift:0:0:0:0 | error.swift | File successfully extracted. |
2+
| main.swift:0:0:0:0 | main.swift | File successfully extracted. |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
diagnostics/ExtractedFiles.ql
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
| error.swift:0:0:0:0 | error.swift | query-tests/Diagnostics/error.swift | |
2+
| file://:0:0:0:0 | | | |
3+
| main.swift:0:0:0:0 | main.swift | query-tests/Diagnostics/main.swift | isSuccessfullyExtracted |
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import swift
2+
3+
string describe(File f) { (f.isSuccessfullyExtracted() and result = "isSuccessfullyExtracted") }
4+
5+
from File f
6+
select f, concat(f.getRelativePath(), ", "), concat(describe(f), ", ")

swift/ql/test/query-tests/Diagnostics/SuccessfullyExtractedFiles.expected

Lines changed: 0 additions & 1 deletion
This file was deleted.

swift/ql/test/query-tests/Diagnostics/SuccessfullyExtractedFiles.qlref

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)