Skip to content

Commit

Permalink
Merge pull request #15385 from geoffw0/swiftfiles
Browse files Browse the repository at this point in the history
Swift: Report any extracted file as successfully extracted
  • Loading branch information
geoffw0 authored Jan 22, 2024
2 parents 6533269 + a39bb8c commit 0a8869c
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 5 deletions.
19 changes: 19 additions & 0 deletions swift/ql/lib/codeql/swift/elements/File.qll
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,23 @@ class File extends Generated::File {
)
)
}

/**
* Gets the relative path of this file from the root folder of the
* analyzed source location. The relative path of the root folder itself
* would be the empty string.
*
* This has no result if the file is outside the source root, that is,
* if the root folder is not a reflexive, transitive parent of this file.
*/
string getRelativePath() {
exists(string absPath, string pref |
absPath = this.getAbsolutePath() and sourceLocationPrefix(pref)
|
absPath = pref and result = ""
or
absPath = pref.regexpReplaceAll("/$", "") + "/" + result and
not result.matches("/%")
)
}
}
4 changes: 4 additions & 0 deletions swift/ql/src/change-notes/2024-01-19-extracted-files.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
category: minorAnalysis
---
* 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 number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @name Successfully extracted files
* @description Lists all files in the source code directory that were extracted without encountering a problem in the file.
* @name Extracted files
* @description Lists all files in the source code directory that were extracted.
* @kind diagnostic
* @id swift/diagnostics/successfully-extracted-files
* @tags successfully-extracted-files
Expand All @@ -9,5 +9,5 @@
import swift

from File f
where f.isSuccessfullyExtracted()
where exists(f.getRelativePath())
select f, "File successfully extracted."
2 changes: 2 additions & 0 deletions swift/ql/test/query-tests/Diagnostics/ExtractedFiles.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
| error.swift:0:0:0:0 | error.swift | File successfully extracted. |
| main.swift:0:0:0:0 | main.swift | File successfully extracted. |
1 change: 1 addition & 0 deletions swift/ql/test/query-tests/Diagnostics/ExtractedFiles.qlref
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
diagnostics/ExtractedFiles.ql
3 changes: 3 additions & 0 deletions swift/ql/test/query-tests/Diagnostics/Info.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
| error.swift:0:0:0:0 | error.swift | query-tests/Diagnostics/error.swift | |
| file://:0:0:0:0 | | | |
| main.swift:0:0:0:0 | main.swift | query-tests/Diagnostics/main.swift | isSuccessfullyExtracted |
6 changes: 6 additions & 0 deletions swift/ql/test/query-tests/Diagnostics/Info.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import swift

string describe(File f) { (f.isSuccessfullyExtracted() and result = "isSuccessfullyExtracted") }

from File f
select f, concat(f.getRelativePath(), ", "), concat(describe(f), ", ")

This file was deleted.

This file was deleted.

0 comments on commit 0a8869c

Please sign in to comment.