Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust: More information about extractor errors and warnings #17647

Merged
merged 16 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ruby/ql/consistency-queries/AstConsistency.ql
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ query predicate multipleToString(AstNode n, string s) {
}

query predicate extractionError(ExtractionError error) { any() }

query predicate extractionWarning(ExtractionWarning error) { any() }
18 changes: 18 additions & 0 deletions ruby/ql/lib/codeql/files/FileSystem.qll
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

private import codeql.Locations
private import codeql.util.FileSystem
private import codeql.ruby.Diagnostics
geoffw0 marked this conversation as resolved.
Show resolved Hide resolved

private module Input implements InputSig {
abstract class ContainerBase extends @container {
Expand Down Expand Up @@ -34,3 +35,20 @@ class File extends Container, Impl::File {
/** Holds if this file was extracted from ordinary source code. */
predicate fromSource() { any() }
}

/**
* 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
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Original file line number Diff line number Diff line change
@@ -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. |
Original file line number Diff line number Diff line change
@@ -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 |