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
4 changes: 0 additions & 4 deletions apps/oxlint/src/output_formatter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,6 @@ mod test {
Tester::new().with_cwd(TEST_CWD.into()).test_and_snapshot(args);
}

/// disabled for windows
/// stylish will output the offset which will be different for windows
/// when there are multiple lines (`\r\n` vs `\n`)
#[cfg(all(test, not(target_os = "windows")))]
#[test]
fn test_output_formatter_diagnostic_stylish() {
let args = &["--format=stylish", "test.js"];
Expand Down
20 changes: 10 additions & 10 deletions apps/oxlint/src/output_formatter/stylish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ fn format_stylish(diagnostics: &[Error]) -> String {
};
let max_len_width = diagnostics
.iter()
.filter_map(|diagnostic| diagnostic.labels())
.flat_map(std::iter::Iterator::collect::<Vec<_>>)
.map(|label| format!("{}:{}", label.offset(), label.len()).len())
.map(|diagnostic| {
let start = Info::new(diagnostic).start;
format!("{}:{}", start.line, start.column).len()
})
.max()
.unwrap_or(0);

Expand All @@ -83,13 +84,12 @@ fn format_stylish(diagnostics: &[Error]) -> String {
"\u{1b}[33mwarning\u{1b}[0m"
};

if let Some(label) = diagnostic.labels().expect("should have labels").next() {
let rule = diagnostic.code().map_or_else(String::new, |code| code.to_string());
let position = format!("{}:{}", label.offset(), label.len());
output.push_str(
&format!(" \u{1b}[2m{position:max_len_width$}\u{1b}[0m {severity_str} {diagnostic} \u{1b}[2m{rule}\u{1b}[0m\n"),
);
}
let info = Info::new(diagnostic);
let rule = diagnostic.code().map_or_else(String::new, |code| code.to_string());
let position = format!("{}:{}", info.start.line, info.start.column);
output.push_str(
&format!(" \u{1b}[2m{position:max_len_width$}\u{1b}[0m {severity_str} {diagnostic} \u{1b}[2m{rule}\u{1b}[0m\n"),
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ working directory: fixtures/output_formatter_diagnostic
----------

test.js
9:3  warning Function 'foo' is declared but never used. eslint(no-unused-vars)
16:1 warning Parameter 'b' is declared but never used. Unused parameters should start with a '_'. eslint(no-unused-vars)
38:9 error `debugger` statement is not allowed eslint(no-debugger)
1:10 warning Function 'foo' is declared but never used. eslint(no-unused-vars)
1:17 warning Parameter 'b' is declared but never used. Unused parameters should start with a '_'. eslint(no-unused-vars)
5:1  error `debugger` statement is not allowed eslint(no-debugger)

✖ 3 problems (1 error, 2 warnings)
----------
Expand Down
Loading