Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default class Test {
commands = [];
client: Example

constructor() {
this.client = {};
}
}
15 changes: 15 additions & 0 deletions apps/oxlint/src/output_formatter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,21 @@ mod test {
}
}

// Regression test for https://github.com/oxc-project/oxc/issues/19588
// Parser errors with colons in their message (e.g. 'Expected `;` but found `:`')
// were being truncated to just the character after the first colon.
#[test]
fn test_output_formatter_diagnostic_formats_with_parser_error() {
let formats: Vec<&str> =
vec!["checkstyle", "default", "github", "gitlab", "json", "junit", "stylish", "unix"];

for fmt in &formats {
let args_vec = [format!("--format={fmt}"), "parser-error.js".to_string()];
let args_ref: Vec<&str> = args_vec.iter().map(std::string::String::as_str).collect();
Tester::new().with_cwd(TEST_CWD.into()).test_and_snapshot(&args_ref);
}
}

// Test that each of the formatters can output the disable directive violations.
#[test]
fn test_output_formatter_diagnostic_formats_with_disable_directive() {
Expand Down
15 changes: 15 additions & 0 deletions apps/oxlint/src/output_formatter/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,19 @@ mod test {
assert!(result.is_some());
assert_eq!(result.unwrap(), "file://test.ts:1:1: error message [Warning]\n");
}

/// Regression test: messages containing colons (e.g. parser errors like
/// 'Expected `;` but found `:`') must not be truncated.
#[test]
fn reporter_error_message_with_colon() {
let mut reporter = UnixReporter::default();
let error = OxcDiagnostic::error("Expected `;` but found `:`")
.with_label(Span::new(0, 1))
.with_source_code(NamedSource::new("file://test.js", ":"));

let result = reporter.render_error(error);

assert!(result.is_some());
assert_eq!(result.unwrap(), "file://test.js:1:1: Expected `;` but found `:` [Error]\n");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
source: apps/oxlint/src/tester.rs
---
##########
arguments: --format=checkstyle parser-error.js
working directory: fixtures/output_formatter_diagnostic
----------
<?xml version="1.0" encoding="utf-8"?><checkstyle version="4.3"><file name="parser-error.js"><error line="3" column="9" severity="error" message="Expected `;` but found `:`" source="" /></file></checkstyle>
----------
CLI result: LintFoundErrors
----------
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
source: apps/oxlint/src/tester.rs
---
##########
arguments: --format=default parser-error.js
working directory: fixtures/output_formatter_diagnostic
----------

x Expected `;` but found `:`
,-[parser-error.js:3:9]
2 | commands = [];
3 | client: Example
: |
: `-- `;` expected
4 |
`----

Found 0 warnings and 1 error.
Finished in <variable>ms on 1 file with 2 rules using 1 threads.
----------
CLI result: LintFoundErrors
----------
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
source: apps/oxlint/src/tester.rs
---
##########
arguments: --format=github parser-error.js
working directory: fixtures/output_formatter_diagnostic
----------
::error file=parser-error.js,line=3,endLine=3,col=9,endColumn=10,title=oxlint::Expected `;` but found `:`
----------
CLI result: LintFoundErrors
----------
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
source: apps/oxlint/src/tester.rs
---
##########
arguments: --format=gitlab parser-error.js
working directory: fixtures/output_formatter_diagnostic
----------
[
{
"description": "Expected `;` but found `:`",
"check_name": "",
"fingerprint": "5f141d44128bf58e",
"severity": "critical",
"location": {
"path": "apps/oxlint/parser-error.js",
"lines": {
"begin": 3,
"end": 3
}
}
}
]----------
CLI result: LintFoundErrors
----------
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
source: apps/oxlint/src/tester.rs
---
##########
arguments: --format=json parser-error.js
working directory: fixtures/output_formatter_diagnostic
----------
{ "diagnostics": [{"message": "Expected `;` but found `:`","severity": "error","causes": [],"filename": "parser-error.js","labels": [{"label": "`;` expected","span": {"offset": 53,"length": 1,"line": 3,"column": 9}}],"related": []}],
"number_of_files": 1,
"number_of_rules": 2,
"threads_count": 1,
"start_time": <variable>
}
----------
CLI result: LintFoundErrors
----------
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
source: apps/oxlint/src/tester.rs
---
##########
arguments: --format=junit parser-error.js
working directory: fixtures/output_formatter_diagnostic
----------
<?xml version="1.0" encoding="UTF-8"?>
<testsuites name="Oxlint" tests="1" failures="0" errors="1">
<testsuite name="parser-error.js" tests="1" disabled="0" errors="1" failures="0">
<testcase name="">
<error message="Expected `;` but found `:`">line 3, column 9, Expected `;` but found `:`</error>
</testcase>
</testsuite>
</testsuites>
----------
CLI result: LintFoundErrors
----------
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
source: apps/oxlint/src/tester.rs
---
##########
arguments: --format=stylish parser-error.js
working directory: fixtures/output_formatter_diagnostic
----------

parser-error.js
3:9 error Expected `;` but found `:` 

✖ 1 problem (1 error, 0 warnings)
----------
CLI result: LintFoundErrors
----------
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
source: apps/oxlint/src/tester.rs
---
##########
arguments: --format=unix parser-error.js
working directory: fixtures/output_formatter_diagnostic
----------
parser-error.js:3:9: Expected `;` but found `:` [Error]

1 problem
----------
CLI result: LintFoundErrors
----------
66 changes: 33 additions & 33 deletions apps/oxlint/test/fixtures/comments/output.snap.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,16 @@
4 |
`----

x test-comments(test-comments): commentsExistBetween(topLevelFunction, topLevelVariable2): false
x test-comments(test-comments): FunctionDeclaration(topLevelFunction):
| getCommentsBefore: 0 comments
| getCommentsInside: 5 comments
| [0] Line: " Line comment 2" at [163, 180]
| [1] Block: " Block comment 2 " at [183, 204]
| [2] Block: "*\n * JSDoc comment 2\n " at [256, 286]
| [3] Line: " Line comment 3" at [321, 338]
| [4] Line: " Line comment 4" at [405, 422]
| getCommentsAfter: 1 comment
| [0] Block: " Block comment 3 " at [426, 447]
,-[files/comments.js:8:8]
7 | */
8 | ,-> export function topLevelFunction() {
Expand All @@ -105,16 +114,7 @@
21 |
`----

x test-comments(test-comments): FunctionDeclaration(topLevelFunction):
| getCommentsBefore: 0 comments
| getCommentsInside: 5 comments
| [0] Line: " Line comment 2" at [163, 180]
| [1] Block: " Block comment 2 " at [183, 204]
| [2] Block: "*\n * JSDoc comment 2\n " at [256, 286]
| [3] Line: " Line comment 3" at [321, 338]
| [4] Line: " Line comment 4" at [405, 422]
| getCommentsAfter: 1 comment
| [0] Block: " Block comment 3 " at [426, 447]
x test-comments(test-comments): commentsExistBetween(topLevelFunction, topLevelVariable2): false
,-[files/comments.js:8:8]
7 | */
8 | ,-> export function topLevelFunction() {
Expand Down Expand Up @@ -255,37 +255,37 @@
7 | `-> export function topLevelFunction() {}
`----

x test-comments(test-comments): commentsExistBetween(topLevelVariable2, topLevelFunction): false
x test-comments(test-comments): VariableDeclaration(topLevelVariable2):
| getCommentsBefore: 0 comments
| getCommentsInside: 0 comments
| getCommentsAfter: 0 comments
| commentsExistBetween(id, init): false
,-[files/hashbang.js:5:1]
4 | const topLevelVariable1 = 1;
5 | const topLevelVariable2 = 2;
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6 |
`----

x test-comments(test-comments): VariableDeclaration(topLevelVariable2):
| getCommentsBefore: 0 comments
| getCommentsInside: 0 comments
| getCommentsAfter: 0 comments
| commentsExistBetween(id, init): false
x test-comments(test-comments): commentsExistBetween(topLevelVariable2, topLevelFunction): false
,-[files/hashbang.js:5:1]
4 | const topLevelVariable1 = 1;
5 | const topLevelVariable2 = 2;
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6 |
`----

x test-comments(test-comments): commentsExistBetween(topLevelFunction, topLevelVariable2): false
x test-comments(test-comments): FunctionDeclaration(topLevelFunction):
| getCommentsBefore: 0 comments
| getCommentsInside: 0 comments
| getCommentsAfter: 0 comments
,-[files/hashbang.js:7:8]
6 |
7 | export function topLevelFunction() {}
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
`----

x test-comments(test-comments): FunctionDeclaration(topLevelFunction):
| getCommentsBefore: 0 comments
| getCommentsInside: 0 comments
| getCommentsAfter: 0 comments
x test-comments(test-comments): commentsExistBetween(topLevelFunction, topLevelVariable2): false
,-[files/hashbang.js:7:8]
6 |
7 | export function topLevelFunction() {}
Expand Down Expand Up @@ -323,27 +323,30 @@
16 | `-> const topLevelVariable7 = 7;
`----

x test-comments(test-comments): commentsExistBetween(topLevelVariable2, topLevelFunction): false
x test-comments(test-comments): VariableDeclaration(topLevelVariable2):
| getCommentsBefore: 0 comments
| getCommentsInside: 0 comments
| getCommentsAfter: 0 comments
| commentsExistBetween(id, init): false
,-[files/no_comments.js:2:1]
1 | const topLevelVariable1 = 1;
2 | const topLevelVariable2 = 2;
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3 |
`----

x test-comments(test-comments): VariableDeclaration(topLevelVariable2):
| getCommentsBefore: 0 comments
| getCommentsInside: 0 comments
| getCommentsAfter: 0 comments
| commentsExistBetween(id, init): false
x test-comments(test-comments): commentsExistBetween(topLevelVariable2, topLevelFunction): false
,-[files/no_comments.js:2:1]
1 | const topLevelVariable1 = 1;
2 | const topLevelVariable2 = 2;
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3 |
`----

x test-comments(test-comments): commentsExistBetween(topLevelFunction, topLevelVariable2): false
x test-comments(test-comments): FunctionDeclaration(topLevelFunction):
| getCommentsBefore: 0 comments
| getCommentsInside: 0 comments
| getCommentsAfter: 0 comments
,-[files/no_comments.js:4:8]
3 |
4 | ,-> export function topLevelFunction() {
Expand All @@ -356,10 +359,7 @@
11 |
`----

x test-comments(test-comments): FunctionDeclaration(topLevelFunction):
| getCommentsBefore: 0 comments
| getCommentsInside: 0 comments
| getCommentsAfter: 0 comments
x test-comments(test-comments): commentsExistBetween(topLevelFunction, topLevelVariable2): false
,-[files/no_comments.js:4:8]
3 |
4 | ,-> export function topLevelFunction() {
Expand Down
Loading
Loading