Skip to content

Commit 8cf691a

Browse files
committed
Swift: Add File.getRelativePath and update swift/diagnostics/successfully-extracted-files.
1 parent 7e1dd38 commit 8cf691a

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
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: 3 additions & 3 deletions
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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
| error.swift:0:0:0:0 | error.swift | File successfully extracted. |
12
| main.swift:0:0:0:0 | main.swift | File successfully extracted. |

0 commit comments

Comments
 (0)