mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Merge pull request #17647 from geoffw0/warnings
Rust: More information about extractor errors and warnings
This commit is contained in:
@@ -31,3 +31,5 @@ query predicate multipleToString(AstNode n, string s) {
|
||||
}
|
||||
|
||||
query predicate extractionError(ExtractionError error) { any() }
|
||||
|
||||
query predicate extractionWarning(ExtractionWarning error) { any() }
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
---
|
||||
category: minorAnalysis
|
||||
---
|
||||
* The `ExtractionError` class has been split into `ExtractionError` and `ExtractionWarning`, reporting extraction errors and warnings respectively.
|
||||
@@ -18,6 +18,7 @@ private import ast.internal.Scope
|
||||
private import ast.internal.Synthesis
|
||||
private import ast.internal.TreeSitter
|
||||
private import Customizations
|
||||
private import Diagnostics
|
||||
|
||||
cached
|
||||
private module Cached {
|
||||
@@ -166,3 +167,20 @@ class RubyFile extends File {
|
||||
/** Gets the number of lines of comments in this file. */
|
||||
int getNumberOfLinesOfComments() { result = count(int line | this.line(line, true)) }
|
||||
}
|
||||
|
||||
/**
|
||||
* A successfully extracted file, that is, a file that was extracted and
|
||||
* contains no extraction errors or warnings.
|
||||
*/
|
||||
class SuccessfullyExtractedFile extends File {
|
||||
SuccessfullyExtractedFile() {
|
||||
not exists(Diagnostic d |
|
||||
d.getLocation().getFile() = this and
|
||||
(
|
||||
d instanceof ExtractionError
|
||||
or
|
||||
d instanceof ExtractionWarning
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,8 @@ class Diagnostic extends @diagnostic {
|
||||
string toString() { result = this.getMessage() }
|
||||
}
|
||||
|
||||
/** A diagnostic relating to a particular error in extracting a file. */
|
||||
class ExtractionError extends Diagnostic {
|
||||
ExtractionError() { this.getTag() = "parse_error" }
|
||||
}
|
||||
/** A diagnostic that is error severity. */
|
||||
class ExtractionError extends Diagnostic, @diagnostic_error { }
|
||||
|
||||
/** A diagnostic that is warning severity. */
|
||||
class ExtractionWarning extends Diagnostic, @diagnostic_warning { }
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
---
|
||||
category: minorAnalysis
|
||||
---
|
||||
* 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.
|
||||
19
ruby/ql/src/queries/diagnostics/ExtractionWarnings.ql
Normal file
19
ruby/ql/src/queries/diagnostics/ExtractionWarnings.ql
Normal file
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* @name Extraction warnings
|
||||
* @description List all extraction warnings for files in the source code directory.
|
||||
* @kind diagnostic
|
||||
* @id rb/diagnostics/extraction-warnings
|
||||
*/
|
||||
|
||||
import codeql.ruby.AST
|
||||
import codeql.ruby.Diagnostics
|
||||
|
||||
/** Gets the SARIF severity to associate with a warning. */
|
||||
int getSeverity() { result = 1 }
|
||||
|
||||
from ExtractionWarning warning, File f
|
||||
where
|
||||
f = warning.getLocation().getFile() and
|
||||
exists(f.getRelativePath())
|
||||
select warning, "Extraction warning in " + f + " with message " + warning.getMessage(),
|
||||
getSeverity()
|
||||
@@ -2,14 +2,15 @@
|
||||
* @id rb/summary/number-of-files-extracted-with-errors
|
||||
* @name Total number of Ruby files that were extracted with errors
|
||||
* @description The total number of Ruby code files that we extracted, but where
|
||||
* at least one extraction error occurred in the process.
|
||||
* at least one extraction error (or warning) occurred in the process.
|
||||
* @kind metric
|
||||
* @tags summary
|
||||
*/
|
||||
|
||||
import codeql.ruby.AST
|
||||
import codeql.ruby.Diagnostics
|
||||
import codeql.files.FileSystem
|
||||
|
||||
select count(File f |
|
||||
exists(ExtractionError e | e.getLocation().getFile() = f) and exists(f.getRelativePath())
|
||||
exists(f.getRelativePath()) and
|
||||
not f instanceof SuccessfullyExtractedFile
|
||||
)
|
||||
|
||||
@@ -2,14 +2,12 @@
|
||||
* @id rb/summary/number-of-successfully-extracted-files
|
||||
* @name Total number of Ruby files that were extracted without error
|
||||
* @description The total number of Ruby code files that we extracted without
|
||||
* encountering any extraction errors
|
||||
* encountering any extraction errors (or warnings).
|
||||
* @kind metric
|
||||
* @tags summary
|
||||
*/
|
||||
|
||||
import codeql.ruby.AST
|
||||
import codeql.ruby.Diagnostics
|
||||
import codeql.files.FileSystem
|
||||
|
||||
select count(File f |
|
||||
not exists(ExtractionError e | e.getLocation().getFile() = f) and exists(f.getRelativePath())
|
||||
)
|
||||
select count(SuccessfullyExtractedFile f | exists(f.getRelativePath()))
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
extractionError
|
||||
extractionWarning
|
||||
| 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. |
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
| 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,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 warning in src/not_ruby.rb with message A parse error occurred. Check the syntax of the file. If the file is invalid, correct the error or exclude the file from analysis. | 1 |
|
||||
@@ -0,0 +1 @@
|
||||
queries/diagnostics/ExtractionWarnings.ql
|
||||
Reference in New Issue
Block a user