Skip to content

Commit 3481652

Browse files
authored
Merge pull request github#12442 from aibaars/diagnostics-tests
Ruby: add some integration tests for diagnostic messages
2 parents a816b81 + c98e0fa commit 3481652

File tree

11 files changed

+100
-6
lines changed

11 files changed

+100
-6
lines changed

ruby/extractor/src/diagnostics.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,9 @@ fn longest_backtick_sequence_length(text: &str) -> usize {
214214
}
215215
result
216216
}
217-
/**
218-
* An argument of a diagnostic message format string. A message argument is either a "code" snippet or a link.
219-
*/
217+
218+
/// An argument of a diagnostic message format string.
219+
/// A message argument is either a "code" snippet or a link.
220220
pub enum MessageArg<'a> {
221221
Code(&'a str),
222222
Link(&'a str, &'a str),

ruby/extractor/src/extractor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ impl<'a> Visitor<'a> {
294294
.diagnostics_writer
295295
.new_entry("parse-error", "Parse error");
296296
&mesg
297-
.severity(diagnostics::Severity::Error)
297+
.severity(diagnostics::Severity::Warning)
298298
.location(self.path, start_line, start_column, end_line, end_column)
299299
.message(message, args);
300300
if status_page {
@@ -405,7 +405,7 @@ impl<'a> Visitor<'a> {
405405
loc,
406406
self.diagnostics_writer
407407
.new_entry("parse-error", "Parse error")
408-
.severity(diagnostics::Severity::Error)
408+
.severity(diagnostics::Severity::Warning)
409409
.location(self.path, start_line, start_column, end_line, end_column)
410410
.message(
411411
"Unknown table type: {}",
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
4 %%% 5
2+
3+
if 1; 2
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"helpLinks": [
3+
"https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/customizing-code-scanning"
4+
],
5+
"location": {
6+
"endColumn": 5,
7+
"endLine": 1,
8+
"file": "<test-root-directory>/bad.rb",
9+
"startColumn": 4,
10+
"startLine": 1
11+
},
12+
"markdownMessage": "A parse error occurred. Check the syntax of the file. If the file is invalid, correct the error or [exclude](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/customizing-code-scanning) the file from analysis.",
13+
"plaintextMessage": "A parse error occurred. Check the syntax of the file. If the file is invalid, correct the error or exclude the file from analysis.",
14+
"severity": "Warning",
15+
"source": {
16+
"extractorName": "ruby",
17+
"id": "ruby/parse-error",
18+
"name": "Parse error"
19+
},
20+
"visibility": {
21+
"statusPage": true
22+
}
23+
}
24+
{
25+
"helpLinks": [
26+
"https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/customizing-code-scanning"
27+
],
28+
"location": {
29+
"endColumn": 7,
30+
"endLine": 3,
31+
"file": "<test-root-directory>/bad.rb",
32+
"startColumn": 8,
33+
"startLine": 3
34+
},
35+
"markdownMessage": "A parse error occurred (expected `end` symbol). Check the syntax of the file. If the file is invalid, correct the error or [exclude](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/customizing-code-scanning) the file from analysis.",
36+
"plaintextMessage": "A parse error occurred (expected end symbol). Check the syntax of the file. If the file is invalid, correct the error or exclude the file from analysis.",
37+
"severity": "Warning",
38+
"source": {
39+
"extractorName": "ruby",
40+
"id": "ruby/parse-error",
41+
"name": "Parse error"
42+
},
43+
"visibility": {
44+
"statusPage": true
45+
}
46+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import os
2+
from create_database_utils import *
3+
from diagnostics_test_utils import *
4+
5+
run_codeql_database_create([], lang="ruby", runFunction = runSuccessfully, db = None)
6+
7+
check_diagnostics()
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"helpLinks": [
3+
"https://docs.ruby-lang.org/en/master/syntax/comments_rdoc.html#label-encoding+Directive"
4+
],
5+
"location": {
6+
"file": "<test-root-directory>/encoding.rb"
7+
},
8+
"markdownMessage": "Unknown character encoding `silly` in `#encoding:` [directive](https://docs.ruby-lang.org/en/master/syntax/comments_rdoc.html#label-encoding+Directive).",
9+
"plaintextMessage": "Unknown character encoding silly in #encoding: directive.",
10+
"severity": "Warning",
11+
"source": {
12+
"extractorName": "ruby",
13+
"id": "ruby/unknown-character-encoding",
14+
"name": "Unknown character encoding"
15+
},
16+
"visibility": {
17+
"statusPage": true
18+
}
19+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# encoding: silly
2+
3+
def f
4+
puts "hello"
5+
end
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import os
2+
from create_database_utils import *
3+
from diagnostics_test_utils import *
4+
5+
run_codeql_database_create([], lang="ruby", runFunction = runSuccessfully, db = None)
6+
7+
check_diagnostics()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dependencies:
2+
codeql/ruby-all: '*'
3+
codeql/ruby-queries: '*'
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 severity of parse errors was reduced to warning (previously error).

0 commit comments

Comments
 (0)