Skip to content

Commit 1ea94fa

Browse files
committed
Ruby: Make similar changes to differentiate extraction errors and warnings, and mostly restore original behaviour.
1 parent 4c7ec59 commit 1ea94fa

File tree

6 files changed

+28
-10
lines changed

6 files changed

+28
-10
lines changed

ruby/ql/consistency-queries/AstConsistency.ql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@ query predicate multipleToString(AstNode n, string s) {
3131
}
3232

3333
query predicate extractionError(ExtractionError error) { any() }
34+
35+
query predicate extractionWarning(ExtractionWarning error) { any() }

ruby/ql/lib/codeql/files/FileSystem.qll

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
private import codeql.Locations
44
private import codeql.util.FileSystem
5+
private import codeql.ruby.Diagnostics
56

67
private module Input implements InputSig {
78
abstract class ContainerBase extends @container {
@@ -34,3 +35,20 @@ class File extends Container, Impl::File {
3435
/** Holds if this file was extracted from ordinary source code. */
3536
predicate fromSource() { any() }
3637
}
38+
39+
/**
40+
* A successfully extracted file, that is, a file that was extracted and
41+
* contains no extraction errors or warnings.
42+
*/
43+
class SuccessfullyExtractedFile extends File {
44+
SuccessfullyExtractedFile() {
45+
not exists(Diagnostic d |
46+
d.getLocation().getFile() = this and
47+
(
48+
d instanceof ExtractionError
49+
or
50+
d instanceof ExtractionWarning
51+
)
52+
)
53+
}
54+
}

ruby/ql/src/queries/summary/NumberOfFilesExtractedWithErrors.ql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
* @id rb/summary/number-of-files-extracted-with-errors
33
* @name Total number of Ruby files that were extracted with errors
44
* @description The total number of Ruby code files that we extracted, but where
5-
* at least one extraction error occurred in the process.
5+
* at least one extraction error (or warning) occurred in the process.
66
* @kind metric
77
* @tags summary
88
*/
99

1010
import codeql.ruby.AST
11-
import codeql.ruby.Diagnostics
11+
import codeql.files.FileSystem
1212

1313
select count(File f |
14-
exists(ExtractionError e | e.getLocation().getFile() = f) and exists(f.getRelativePath())
14+
exists(f.getRelativePath()) and
15+
not f instanceof SuccessfullyExtractedFile
1516
)

ruby/ql/src/queries/summary/NumberOfSuccessfullyExtractedFiles.ql

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22
* @id rb/summary/number-of-successfully-extracted-files
33
* @name Total number of Ruby files that were extracted without error
44
* @description The total number of Ruby code files that we extracted without
5-
* encountering any extraction errors
5+
* encountering any extraction errors (or warnings).
66
* @kind metric
77
* @tags summary
88
*/
99

1010
import codeql.ruby.AST
11-
import codeql.ruby.Diagnostics
11+
import codeql.files.FileSystem
1212

13-
select count(File f |
14-
not exists(ExtractionError e | e.getLocation().getFile() = f) and exists(f.getRelativePath())
15-
)
13+
select count(SuccessfullyExtractedFile f | exists(f.getRelativePath()))
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
extractionError
1+
extractionWarning
22
| src/not_ruby.rb:5:25:5:26 | A parse error occurred. Check the syntax of the file. If the file is invalid, correct the error or exclude the file from analysis. |
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
| src/not_ruby.rb:5:25:5:26 | A parse error occurred. Check the syntax of the file. If the file is invalid, correct the error or exclude the file from analysis. | Extraction failed in src/not_ruby.rb with error A parse error occurred. Check the syntax of the file. If the file is invalid, correct the error or exclude the file from analysis. | 2 |

0 commit comments

Comments
 (0)