Skip to content

Commit 04c7319

Browse files
authored
Merge pull request github#17647 from geoffw0/warnings
Rust: More information about extractor errors and warnings
2 parents e7da53d + 7420d07 commit 04c7319

26 files changed

+142
-36
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() }
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 `ExtractionError` class has been split into `ExtractionError` and `ExtractionWarning`, reporting extraction errors and warnings respectively.

ruby/ql/lib/codeql/ruby/AST.qll

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ private import ast.internal.Scope
1818
private import ast.internal.Synthesis
1919
private import ast.internal.TreeSitter
2020
private import Customizations
21+
private import Diagnostics
2122

2223
cached
2324
private module Cached {
@@ -166,3 +167,20 @@ class RubyFile extends File {
166167
/** Gets the number of lines of comments in this file. */
167168
int getNumberOfLinesOfComments() { result = count(int line | this.line(line, true)) }
168169
}
170+
171+
/**
172+
* A successfully extracted file, that is, a file that was extracted and
173+
* contains no extraction errors or warnings.
174+
*/
175+
class SuccessfullyExtractedFile extends File {
176+
SuccessfullyExtractedFile() {
177+
not exists(Diagnostic d |
178+
d.getLocation().getFile() = this and
179+
(
180+
d instanceof ExtractionError
181+
or
182+
d instanceof ExtractionWarning
183+
)
184+
)
185+
}
186+
}

ruby/ql/lib/codeql/ruby/Diagnostics.qll

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ class Diagnostic extends @diagnostic {
4848
string toString() { result = this.getMessage() }
4949
}
5050

51-
/** A diagnostic relating to a particular error in extracting a file. */
52-
class ExtractionError extends Diagnostic {
53-
ExtractionError() { this.getTag() = "parse_error" }
54-
}
51+
/** A diagnostic that is error severity. */
52+
class ExtractionError extends Diagnostic, @diagnostic_error { }
53+
54+
/** A diagnostic that is warning severity. */
55+
class ExtractionWarning extends Diagnostic, @diagnostic_warning { }
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 `rb/diagnostics/extraction-errors` diagnostic query has been split into `rb/diagnostics/extraction-errors` and `rb/diagnostics/extraction-warnings`, counting extraction errors and warnings respectively.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @name Extraction warnings
3+
* @description List all extraction warnings for files in the source code directory.
4+
* @kind diagnostic
5+
* @id rb/diagnostics/extraction-warnings
6+
*/
7+
8+
import codeql.ruby.AST
9+
import codeql.ruby.Diagnostics
10+
11+
/** Gets the SARIF severity to associate with a warning. */
12+
int getSeverity() { result = 1 }
13+
14+
from ExtractionWarning warning, File f
15+
where
16+
f = warning.getLocation().getFile() and
17+
exists(f.getRelativePath())
18+
select warning, "Extraction warning in " + f + " with message " + warning.getMessage(),
19+
getSeverity()

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)