From ba9c2f1e3a743bb9efdd1010605ff50c90acb7a7 Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Wed, 2 Oct 2024 15:31:14 +0100 Subject: [PATCH 01/15] Rust: Add extractor warnings query. --- rust/ql/lib/codeql/rust/Diagnostics.qll | 5 +++++ .../queries/diagnostics/ExtractionWarnings.ql | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 rust/ql/src/queries/diagnostics/ExtractionWarnings.ql diff --git a/rust/ql/lib/codeql/rust/Diagnostics.qll b/rust/ql/lib/codeql/rust/Diagnostics.qll index 5902bb594141..8c207e708889 100644 --- a/rust/ql/lib/codeql/rust/Diagnostics.qll +++ b/rust/ql/lib/codeql/rust/Diagnostics.qll @@ -52,3 +52,8 @@ class Diagnostic extends @diagnostic { class ExtractionError extends Diagnostic { ExtractionError() { this.getTag() = "parse_error" } } + +/** A diagnostic that is warning severity. */ +class ExtractionWarning extends Diagnostic { + ExtractionWarning() { this.getSeverity() = 30 } +} diff --git a/rust/ql/src/queries/diagnostics/ExtractionWarnings.ql b/rust/ql/src/queries/diagnostics/ExtractionWarnings.ql new file mode 100644 index 000000000000..99773cc6d53a --- /dev/null +++ b/rust/ql/src/queries/diagnostics/ExtractionWarnings.ql @@ -0,0 +1,19 @@ +/** + * @name Extraction warnings + * @description List all extraction warnings for files in the source code directory. + * @kind diagnostic + * @id rust/diagnostics/extraction-warnings + */ + +import codeql.rust.Diagnostics +import codeql.files.FileSystem + +/** 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() From f30a642c8fcc9b8c34493ea170b41fb38c91e93b Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Wed, 2 Oct 2024 15:40:26 +0100 Subject: [PATCH 02/15] Rust: Add a test for the extractor warnings query. --- .../query-tests/diagnostics/ExtractionWarnings.expected | 6 ++++++ .../test/query-tests/diagnostics/ExtractionWarnings.qlref | 1 + 2 files changed, 7 insertions(+) create mode 100644 rust/ql/test/query-tests/diagnostics/ExtractionWarnings.expected create mode 100644 rust/ql/test/query-tests/diagnostics/ExtractionWarnings.qlref diff --git a/rust/ql/test/query-tests/diagnostics/ExtractionWarnings.expected b/rust/ql/test/query-tests/diagnostics/ExtractionWarnings.expected new file mode 100644 index 000000000000..0a68f2bce0ef --- /dev/null +++ b/rust/ql/test/query-tests/diagnostics/ExtractionWarnings.expected @@ -0,0 +1,6 @@ +| does_not_compile.rs:2:6:2:5 | expected SEMICOLON | Extraction warning in does_not_compile.rs with message expected SEMICOLON | 1 | +| does_not_compile.rs:2:9:2:8 | expected SEMICOLON | Extraction warning in does_not_compile.rs with message expected SEMICOLON | 1 | +| does_not_compile.rs:2:13:2:12 | expected SEMICOLON | Extraction warning in does_not_compile.rs with message expected SEMICOLON | 1 | +| does_not_compile.rs:2:21:2:20 | expected SEMICOLON | Extraction warning in does_not_compile.rs with message expected SEMICOLON | 1 | +| does_not_compile.rs:2:26:2:25 | expected SEMICOLON | Extraction warning in does_not_compile.rs with message expected SEMICOLON | 1 | +| does_not_compile.rs:2:32:2:31 | expected field name or number | Extraction warning in does_not_compile.rs with message expected field name or number | 1 | diff --git a/rust/ql/test/query-tests/diagnostics/ExtractionWarnings.qlref b/rust/ql/test/query-tests/diagnostics/ExtractionWarnings.qlref new file mode 100644 index 000000000000..ff6e566d20a7 --- /dev/null +++ b/rust/ql/test/query-tests/diagnostics/ExtractionWarnings.qlref @@ -0,0 +1 @@ +queries/diagnostics/ExtractionWarnings.ql From ad7c96554fbf05eb7b0519672ad2bcb84f95ad83 Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Wed, 2 Oct 2024 18:29:47 +0100 Subject: [PATCH 03/15] Rust: Correct extraction errors query to output only errors. --- rust/ql/lib/codeql/rust/Diagnostics.qll | 4 ++-- rust/ql/src/queries/diagnostics/ExtractionErrors.ql | 2 +- .../test/query-tests/diagnostics/ExtractionErrors.expected | 6 ------ 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/rust/ql/lib/codeql/rust/Diagnostics.qll b/rust/ql/lib/codeql/rust/Diagnostics.qll index 8c207e708889..8f77b64c5123 100644 --- a/rust/ql/lib/codeql/rust/Diagnostics.qll +++ b/rust/ql/lib/codeql/rust/Diagnostics.qll @@ -48,9 +48,9 @@ class Diagnostic extends @diagnostic { string toString() { result = this.getMessage() } } -/** A diagnostic relating to a particular error in extracting a file. */ +/** A diagnostic that is error severity. */ class ExtractionError extends Diagnostic { - ExtractionError() { this.getTag() = "parse_error" } + ExtractionError() { this.getSeverity() = 40 } } /** A diagnostic that is warning severity. */ diff --git a/rust/ql/src/queries/diagnostics/ExtractionErrors.ql b/rust/ql/src/queries/diagnostics/ExtractionErrors.ql index a04c4e618c41..68be66f8ca9b 100644 --- a/rust/ql/src/queries/diagnostics/ExtractionErrors.ql +++ b/rust/ql/src/queries/diagnostics/ExtractionErrors.ql @@ -8,7 +8,7 @@ import codeql.rust.Diagnostics import codeql.files.FileSystem -/** Gets the SARIF severity to associate an error. */ +/** Gets the SARIF severity to associate with an error. */ int getSeverity() { result = 2 } from ExtractionError error, File f diff --git a/rust/ql/test/query-tests/diagnostics/ExtractionErrors.expected b/rust/ql/test/query-tests/diagnostics/ExtractionErrors.expected index b6aaf7b6d373..e69de29bb2d1 100644 --- a/rust/ql/test/query-tests/diagnostics/ExtractionErrors.expected +++ b/rust/ql/test/query-tests/diagnostics/ExtractionErrors.expected @@ -1,6 +0,0 @@ -| does_not_compile.rs:2:6:2:5 | expected SEMICOLON | Extraction failed in does_not_compile.rs with error expected SEMICOLON | 2 | -| does_not_compile.rs:2:9:2:8 | expected SEMICOLON | Extraction failed in does_not_compile.rs with error expected SEMICOLON | 2 | -| does_not_compile.rs:2:13:2:12 | expected SEMICOLON | Extraction failed in does_not_compile.rs with error expected SEMICOLON | 2 | -| does_not_compile.rs:2:21:2:20 | expected SEMICOLON | Extraction failed in does_not_compile.rs with error expected SEMICOLON | 2 | -| does_not_compile.rs:2:26:2:25 | expected SEMICOLON | Extraction failed in does_not_compile.rs with error expected SEMICOLON | 2 | -| does_not_compile.rs:2:32:2:31 | expected field name or number | Extraction failed in does_not_compile.rs with error expected field name or number | 2 | From 12fbd18f3a9c8a08f548942ab732e565c8f3f7c2 Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Wed, 2 Oct 2024 18:32:25 +0100 Subject: [PATCH 04/15] Rust: Have ExtractionConsistency.ql report both. --- rust/ql/consistency-queries/ExtractionConsistency.ql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rust/ql/consistency-queries/ExtractionConsistency.ql b/rust/ql/consistency-queries/ExtractionConsistency.ql index b839f2ad783c..20148f0cea2d 100644 --- a/rust/ql/consistency-queries/ExtractionConsistency.ql +++ b/rust/ql/consistency-queries/ExtractionConsistency.ql @@ -1,3 +1,5 @@ import codeql.rust.Diagnostics query predicate extractionError(ExtractionError ee) { any() } + +query predicate extractionWarning(ExtractionWarning ew) { any() } From a4c06b2bbcb4c1942505e123546225142191aa9f Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Wed, 2 Oct 2024 18:23:25 +0100 Subject: [PATCH 05/15] Rust: Define SuccessfullyExtractedFile and use it to simplify queries. --- rust/ql/lib/codeql/files/FileSystem.qll | 18 ++++++++++++++++++ .../NumberOfFilesExtractedWithErrors.ql | 7 ++++--- .../NumberOfSuccessfullyExtractedFiles.ql | 7 ++----- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/rust/ql/lib/codeql/files/FileSystem.qll b/rust/ql/lib/codeql/files/FileSystem.qll index ee7a2235476e..fd7ad56c74a0 100644 --- a/rust/ql/lib/codeql/files/FileSystem.qll +++ b/rust/ql/lib/codeql/files/FileSystem.qll @@ -5,6 +5,7 @@ private import codeql.util.FileSystem private import codeql.rust.elements.SourceFile private import codeql.rust.elements.AstNode private import codeql.rust.elements.Comment +private import codeql.rust.Diagnostics private module Input implements InputSig { abstract class ContainerBase extends @container { @@ -56,3 +57,20 @@ class File extends Container, Impl::File { ) } } + +/** + * 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 + ) + ) + } +} diff --git a/rust/ql/src/queries/summary/NumberOfFilesExtractedWithErrors.ql b/rust/ql/src/queries/summary/NumberOfFilesExtractedWithErrors.ql index 1af3f0f88ec0..23db30f53e96 100644 --- a/rust/ql/src/queries/summary/NumberOfFilesExtractedWithErrors.ql +++ b/rust/ql/src/queries/summary/NumberOfFilesExtractedWithErrors.ql @@ -2,14 +2,15 @@ * @id rust/summary/number-of-files-extracted-with-errors * @name Total number of Rust files that were extracted with errors * @description The total number of Rust files in the source code directory that - * were extracted, but where at least one extraction error occurred in the process. + * were extracted, but where at least one extraction error (or warning) occurred + * in the process. * @kind metric * @tags summary */ import codeql.files.FileSystem -import codeql.rust.Diagnostics select count(File f | - exists(ExtractionError e | e.getLocation().getFile() = f) and exists(f.getRelativePath()) + exists(f.getRelativePath()) and + not f instanceof SuccessfullyExtractedFile ) diff --git a/rust/ql/src/queries/summary/NumberOfSuccessfullyExtractedFiles.ql b/rust/ql/src/queries/summary/NumberOfSuccessfullyExtractedFiles.ql index eb86577b4b80..c960599ad18f 100644 --- a/rust/ql/src/queries/summary/NumberOfSuccessfullyExtractedFiles.ql +++ b/rust/ql/src/queries/summary/NumberOfSuccessfullyExtractedFiles.ql @@ -2,14 +2,11 @@ * @id rust/summary/number-of-successfully-extracted-files * @name Total number of Rust files that were extracted without error * @description The total number of Rust files in the source code directory that - * were extracted without encountering any extraction errors. + * were extracted without encountering any extraction errors (or warnings). * @kind metric * @tags summary */ -import codeql.rust.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())) From 88abc8f72f8b96d139909bc97d4fb6137fb22334 Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Wed, 2 Oct 2024 17:29:32 +0100 Subject: [PATCH 06/15] Rust: Add to summary stats. --- rust/ql/src/queries/summary/SummaryStats.ql | 17 +++++++++++++++-- .../diagnostics/SummaryStats.expected | 6 +++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/rust/ql/src/queries/summary/SummaryStats.ql b/rust/ql/src/queries/summary/SummaryStats.ql index 447325514cac..a3494ccb769c 100644 --- a/rust/ql/src/queries/summary/SummaryStats.ql +++ b/rust/ql/src/queries/summary/SummaryStats.ql @@ -7,16 +7,29 @@ */ import rust +import codeql.rust.Diagnostics import Stats from string key, string value where - key = "Files extracted" and value = count(File f | exists(f.getRelativePath())).toString() - or key = "Elements extracted" and value = count(Element e | not e instanceof Unextracted).toString() or key = "Elements unextracted" and value = count(Unextracted e).toString() or + key = "Extraction errors" and value = count(ExtractionError e).toString() + or + key = "Extraction warnings" and value = count(ExtractionWarning w).toString() + or + key = "Files extracted - total" and value = count(File f | exists(f.getRelativePath())).toString() + or + key = "Files extracted - with errors" and + value = + count(File f | exists(f.getRelativePath()) and not f instanceof SuccessfullyExtractedFile) + .toString() + or + key = "Files extracted - without errors" and + value = count(SuccessfullyExtractedFile f | exists(f.getRelativePath())).toString() + or key = "Lines of code extracted" and value = getLinesOfCode().toString() or key = "Lines of user code extracted" and value = getLinesOfUserCode().toString() diff --git a/rust/ql/test/query-tests/diagnostics/SummaryStats.expected b/rust/ql/test/query-tests/diagnostics/SummaryStats.expected index ff07c0f589a6..cc467865b00f 100644 --- a/rust/ql/test/query-tests/diagnostics/SummaryStats.expected +++ b/rust/ql/test/query-tests/diagnostics/SummaryStats.expected @@ -1,5 +1,9 @@ | Elements extracted | 210 | | Elements unextracted | 0 | -| Files extracted | 6 | +| Extraction errors | 6 | +| Extraction warnings | 0 | +| Files extracted - total | 6 | +| Files extracted - with errors | 1 | +| Files extracted - without errors | 5 | | Lines of code extracted | 48 | | Lines of user code extracted | 48 | From da84889242e786e7b2bdbd844e7bfdf7cef6fab6 Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Thu, 3 Oct 2024 12:50:40 +0100 Subject: [PATCH 07/15] Rust: Use @diagnostic_error, @diagnostic_warning rather than constants. --- rust/ql/lib/codeql/rust/Diagnostics.qll | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/rust/ql/lib/codeql/rust/Diagnostics.qll b/rust/ql/lib/codeql/rust/Diagnostics.qll index 8f77b64c5123..58de14b8fcf5 100644 --- a/rust/ql/lib/codeql/rust/Diagnostics.qll +++ b/rust/ql/lib/codeql/rust/Diagnostics.qll @@ -49,11 +49,7 @@ class Diagnostic extends @diagnostic { } /** A diagnostic that is error severity. */ -class ExtractionError extends Diagnostic { - ExtractionError() { this.getSeverity() = 40 } -} +class ExtractionError extends Diagnostic, @diagnostic_error { } /** A diagnostic that is warning severity. */ -class ExtractionWarning extends Diagnostic { - ExtractionWarning() { this.getSeverity() = 30 } -} +class ExtractionWarning extends Diagnostic, @diagnostic_warning { } From 32dbdb39133c80ab29386d78cb62e96b8e68d5db Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Thu, 3 Oct 2024 12:50:59 +0100 Subject: [PATCH 08/15] Rust: Update summary stats .expected file. --- rust/ql/test/query-tests/diagnostics/SummaryStats.expected | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rust/ql/test/query-tests/diagnostics/SummaryStats.expected b/rust/ql/test/query-tests/diagnostics/SummaryStats.expected index cc467865b00f..8fe7ee7fb47c 100644 --- a/rust/ql/test/query-tests/diagnostics/SummaryStats.expected +++ b/rust/ql/test/query-tests/diagnostics/SummaryStats.expected @@ -1,7 +1,7 @@ | Elements extracted | 210 | | Elements unextracted | 0 | -| Extraction errors | 6 | -| Extraction warnings | 0 | +| Extraction errors | 0 | +| Extraction warnings | 6 | | Files extracted - total | 6 | | Files extracted - with errors | 1 | | Files extracted - without errors | 5 | From 2e772a80c4bed04c04083e6f8eb2c20e4dc8effb Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Thu, 3 Oct 2024 15:15:32 +0100 Subject: [PATCH 09/15] Rust: Accept minor consistency .expected changes. --- .../utf8/CONSISTENCY/ExtractionConsistency.expected | 1 + .../diagnostics/CONSISTENCY/ExtractionConsistency.expected | 1 + 2 files changed, 2 insertions(+) diff --git a/rust/ql/test/extractor-tests/utf8/CONSISTENCY/ExtractionConsistency.expected b/rust/ql/test/extractor-tests/utf8/CONSISTENCY/ExtractionConsistency.expected index 23b423a489a1..45026be3af2b 100644 --- a/rust/ql/test/extractor-tests/utf8/CONSISTENCY/ExtractionConsistency.expected +++ b/rust/ql/test/extractor-tests/utf8/CONSISTENCY/ExtractionConsistency.expected @@ -1,3 +1,4 @@ +extractionWarning | lib.rs:3:9:3:8 | expected `;` or `{` | | lib.rs:3:9:3:8 | expected an item | | lib.rs:3:21:3:20 | expected BANG | diff --git a/rust/ql/test/query-tests/diagnostics/CONSISTENCY/ExtractionConsistency.expected b/rust/ql/test/query-tests/diagnostics/CONSISTENCY/ExtractionConsistency.expected index 157aafc87852..0d5ffb095614 100644 --- a/rust/ql/test/query-tests/diagnostics/CONSISTENCY/ExtractionConsistency.expected +++ b/rust/ql/test/query-tests/diagnostics/CONSISTENCY/ExtractionConsistency.expected @@ -1,3 +1,4 @@ +extractionWarning | does_not_compile.rs:2:6:2:5 | expected SEMICOLON | | does_not_compile.rs:2:9:2:8 | expected SEMICOLON | | does_not_compile.rs:2:13:2:12 | expected SEMICOLON | From 4c7ec59306a432242f510618611f4fddf3099cc3 Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Thu, 3 Oct 2024 14:16:12 +0100 Subject: [PATCH 10/15] Ruby: Sync identical files. --- ruby/ql/lib/codeql/ruby/Diagnostics.qll | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ruby/ql/lib/codeql/ruby/Diagnostics.qll b/ruby/ql/lib/codeql/ruby/Diagnostics.qll index 5902bb594141..58de14b8fcf5 100644 --- a/ruby/ql/lib/codeql/ruby/Diagnostics.qll +++ b/ruby/ql/lib/codeql/ruby/Diagnostics.qll @@ -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 { } From 1ea94faccf7113ae339190c1151926184fbbfe7d Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Thu, 3 Oct 2024 17:27:52 +0100 Subject: [PATCH 11/15] Ruby: Make similar changes to differentiate extraction errors and warnings, and mostly restore original behaviour. --- ruby/ql/consistency-queries/AstConsistency.ql | 2 ++ ruby/ql/lib/codeql/files/FileSystem.qll | 18 ++++++++++++++++++ .../NumberOfFilesExtractedWithErrors.ql | 7 ++++--- .../NumberOfSuccessfullyExtractedFiles.ql | 8 +++----- .../CONSISTENCY/AstConsistency.expected | 2 +- .../diagnostics/ExtractionErrors.expected | 1 - 6 files changed, 28 insertions(+), 10 deletions(-) diff --git a/ruby/ql/consistency-queries/AstConsistency.ql b/ruby/ql/consistency-queries/AstConsistency.ql index 2a9fea8fea90..d7792a8ae4d0 100644 --- a/ruby/ql/consistency-queries/AstConsistency.ql +++ b/ruby/ql/consistency-queries/AstConsistency.ql @@ -31,3 +31,5 @@ query predicate multipleToString(AstNode n, string s) { } query predicate extractionError(ExtractionError error) { any() } + +query predicate extractionWarning(ExtractionWarning error) { any() } diff --git a/ruby/ql/lib/codeql/files/FileSystem.qll b/ruby/ql/lib/codeql/files/FileSystem.qll index 528dde52fd91..8985cc333447 100644 --- a/ruby/ql/lib/codeql/files/FileSystem.qll +++ b/ruby/ql/lib/codeql/files/FileSystem.qll @@ -2,6 +2,7 @@ private import codeql.Locations private import codeql.util.FileSystem +private import codeql.ruby.Diagnostics private module Input implements InputSig { abstract class ContainerBase extends @container { @@ -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 + ) + ) + } +} diff --git a/ruby/ql/src/queries/summary/NumberOfFilesExtractedWithErrors.ql b/ruby/ql/src/queries/summary/NumberOfFilesExtractedWithErrors.ql index 8623ed911d5a..1cbc28b6cc6b 100644 --- a/ruby/ql/src/queries/summary/NumberOfFilesExtractedWithErrors.ql +++ b/ruby/ql/src/queries/summary/NumberOfFilesExtractedWithErrors.ql @@ -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 ) diff --git a/ruby/ql/src/queries/summary/NumberOfSuccessfullyExtractedFiles.ql b/ruby/ql/src/queries/summary/NumberOfSuccessfullyExtractedFiles.ql index 236374ff2261..afd667cf58c5 100644 --- a/ruby/ql/src/queries/summary/NumberOfSuccessfullyExtractedFiles.ql +++ b/ruby/ql/src/queries/summary/NumberOfSuccessfullyExtractedFiles.ql @@ -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())) diff --git a/ruby/ql/test/query-tests/diagnostics/CONSISTENCY/AstConsistency.expected b/ruby/ql/test/query-tests/diagnostics/CONSISTENCY/AstConsistency.expected index 5dc14116b917..93df75151a77 100644 --- a/ruby/ql/test/query-tests/diagnostics/CONSISTENCY/AstConsistency.expected +++ b/ruby/ql/test/query-tests/diagnostics/CONSISTENCY/AstConsistency.expected @@ -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. | diff --git a/ruby/ql/test/query-tests/diagnostics/ExtractionErrors.expected b/ruby/ql/test/query-tests/diagnostics/ExtractionErrors.expected index dc37ca3642b3..e69de29bb2d1 100644 --- a/ruby/ql/test/query-tests/diagnostics/ExtractionErrors.expected +++ b/ruby/ql/test/query-tests/diagnostics/ExtractionErrors.expected @@ -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 | From 86cc2dc5a1e117b8a9f3e58c639c41d1509593d3 Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Thu, 3 Oct 2024 17:29:25 +0100 Subject: [PATCH 12/15] Ruby: Add rb/diagnostics/extraction-warnings so that we don't miss anything we had before. --- .../queries/diagnostics/ExtractionWarnings.ql | 19 +++++++++++++++++++ .../diagnostics/ExtractionWarnings.expected | 1 + .../diagnostics/ExtractionWarnings.qlref | 1 + 3 files changed, 21 insertions(+) create mode 100644 ruby/ql/src/queries/diagnostics/ExtractionWarnings.ql create mode 100644 ruby/ql/test/query-tests/diagnostics/ExtractionWarnings.expected create mode 100644 ruby/ql/test/query-tests/diagnostics/ExtractionWarnings.qlref diff --git a/ruby/ql/src/queries/diagnostics/ExtractionWarnings.ql b/ruby/ql/src/queries/diagnostics/ExtractionWarnings.ql new file mode 100644 index 000000000000..74f007390567 --- /dev/null +++ b/ruby/ql/src/queries/diagnostics/ExtractionWarnings.ql @@ -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() diff --git a/ruby/ql/test/query-tests/diagnostics/ExtractionWarnings.expected b/ruby/ql/test/query-tests/diagnostics/ExtractionWarnings.expected new file mode 100644 index 000000000000..c47ec9c5d365 --- /dev/null +++ b/ruby/ql/test/query-tests/diagnostics/ExtractionWarnings.expected @@ -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 | diff --git a/ruby/ql/test/query-tests/diagnostics/ExtractionWarnings.qlref b/ruby/ql/test/query-tests/diagnostics/ExtractionWarnings.qlref new file mode 100644 index 000000000000..ff6e566d20a7 --- /dev/null +++ b/ruby/ql/test/query-tests/diagnostics/ExtractionWarnings.qlref @@ -0,0 +1 @@ +queries/diagnostics/ExtractionWarnings.ql From d4414dabff35e74aace2743596d31108ad4cdb5e Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Thu, 3 Oct 2024 17:38:28 +0100 Subject: [PATCH 13/15] Ruby: Add change notes. --- ruby/ql/lib/change-notes/2024-10-03-extraction-warnings.md | 4 ++++ ruby/ql/src/change-notes/2024-10-03-extraction-warnings.md | 4 ++++ 2 files changed, 8 insertions(+) create mode 100644 ruby/ql/lib/change-notes/2024-10-03-extraction-warnings.md create mode 100644 ruby/ql/src/change-notes/2024-10-03-extraction-warnings.md diff --git a/ruby/ql/lib/change-notes/2024-10-03-extraction-warnings.md b/ruby/ql/lib/change-notes/2024-10-03-extraction-warnings.md new file mode 100644 index 000000000000..5d6128354c3b --- /dev/null +++ b/ruby/ql/lib/change-notes/2024-10-03-extraction-warnings.md @@ -0,0 +1,4 @@ +--- +category: minorAnalysis +--- +* The `ExtractionError` class has been split into `ExtractionError` and `ExtractionWarning`, reporting extraction errors and warnings respectively. diff --git a/ruby/ql/src/change-notes/2024-10-03-extraction-warnings.md b/ruby/ql/src/change-notes/2024-10-03-extraction-warnings.md new file mode 100644 index 000000000000..ac97cd1e7ba2 --- /dev/null +++ b/ruby/ql/src/change-notes/2024-10-03-extraction-warnings.md @@ -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. From 8a895740bafc0639ce607753853a8af77534fc1b Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Thu, 10 Oct 2024 14:05:39 +0100 Subject: [PATCH 14/15] Ruby: Move language specific code out of FileSystem.qll (at least for now). --- ruby/ql/lib/codeql/files/FileSystem.qll | 18 ------------------ ruby/ql/lib/codeql/ruby/AST.qll | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/ruby/ql/lib/codeql/files/FileSystem.qll b/ruby/ql/lib/codeql/files/FileSystem.qll index 8985cc333447..528dde52fd91 100644 --- a/ruby/ql/lib/codeql/files/FileSystem.qll +++ b/ruby/ql/lib/codeql/files/FileSystem.qll @@ -2,7 +2,6 @@ private import codeql.Locations private import codeql.util.FileSystem -private import codeql.ruby.Diagnostics private module Input implements InputSig { abstract class ContainerBase extends @container { @@ -35,20 +34,3 @@ 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 - ) - ) - } -} diff --git a/ruby/ql/lib/codeql/ruby/AST.qll b/ruby/ql/lib/codeql/ruby/AST.qll index e8dc28692c07..e98749af4273 100644 --- a/ruby/ql/lib/codeql/ruby/AST.qll +++ b/ruby/ql/lib/codeql/ruby/AST.qll @@ -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 RubyFile { + SuccessfullyExtractedFile() { + not exists(Diagnostic d | + d.getLocation().getFile() = this and + ( + d instanceof ExtractionError + or + d instanceof ExtractionWarning + ) + ) + } +} From 7420d07935d166daaf4f7387bac21339315035cb Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Thu, 10 Oct 2024 15:54:14 +0100 Subject: [PATCH 15/15] Update ruby/ql/lib/codeql/ruby/AST.qll Co-authored-by: Arthur Baars --- ruby/ql/lib/codeql/ruby/AST.qll | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruby/ql/lib/codeql/ruby/AST.qll b/ruby/ql/lib/codeql/ruby/AST.qll index e98749af4273..bd42696a8dbe 100644 --- a/ruby/ql/lib/codeql/ruby/AST.qll +++ b/ruby/ql/lib/codeql/ruby/AST.qll @@ -172,7 +172,7 @@ class RubyFile extends File { * A successfully extracted file, that is, a file that was extracted and * contains no extraction errors or warnings. */ -class SuccessfullyExtractedFile extends RubyFile { +class SuccessfullyExtractedFile extends File { SuccessfullyExtractedFile() { not exists(Diagnostic d | d.getLocation().getFile() = this and