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
Expand Up @@ -7,23 +7,23 @@
| File path: <fixture>/files/range_end_negative.js
| Failed to deserialize JSON returned by `lintFile`: invalid value: integer `-10`, expected u32 at line 1 column 158

x Plugin `suggestions-plugin/suggestions` returned invalid fixes.
x Plugin `suggestions-plugin/suggestions` returned invalid suggestions.
| File path: <fixture>/files/range_end_out_of_bounds.js
| Invalid range: 7..7

x Plugin `suggestions-plugin/suggestions` returned invalid fixes.
x Plugin `suggestions-plugin/suggestions` returned invalid suggestions.
| File path: <fixture>/files/range_end_out_of_bounds.js
| Invalid range: 7..7

x Error running JS plugin.
| File path: <fixture>/files/range_end_too_large.js
| Failed to deserialize JSON returned by `lintFile`: invalid value: integer `4294967296`, expected u32 at line 1 column 166

x Plugin `suggestions-plugin/suggestions` returned invalid fixes.
x Plugin `suggestions-plugin/suggestions` returned invalid suggestions.
| File path: <fixture>/files/range_start_after_end.js
| Negative range is invalid: Span { start: 3, end: 2 }

x Plugin `suggestions-plugin/suggestions` returned invalid fixes.
x Plugin `suggestions-plugin/suggestions` returned invalid suggestions.
| File path: <fixture>/files/range_start_after_end.js
| Negative range is invalid: Span { start: 3, end: 2 }

Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_linter/src/external_linter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use oxc_span::Span;
use crate::{
config::{OxlintEnv, OxlintGlobals},
context::ContextHost,
fixer::{CompositeFix, Fix, FixKind, MergeFixesError},
fixer::{CompositeFix, Fix, MergeFixesError},
};

pub type ExternalLinterCreateWorkspaceCb =
Expand Down Expand Up @@ -111,7 +111,7 @@ pub fn convert_and_merge_js_fixes(
let mut fixes = fixes.into_iter().map(|fix| {
let mut span = Span::new(fix.range[0], fix.range[1]);
span_converter.convert_span_back(&mut span);
Fix::new(fix.text, span).with_kind(FixKind::Fix)
Fix::new(fix.text, span)
});

if is_single {
Expand Down
20 changes: 11 additions & 9 deletions crates/oxc_linter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -642,15 +642,20 @@ impl Linter {
}

// Convert a `Vec<JsFix>` to a `Fix`, including converting spans back to UTF-8
let create_fix = |fixes| match convert_and_merge_js_fixes(
let create_fix = |fixes, fix_kind| match convert_and_merge_js_fixes(
fixes,
original_source_text,
&span_converter,
) {
Ok(fix) => Some(fix),
Ok(fix) => Some(fix.with_kind(fix_kind)),
Err(err) => {
let fixes_type = if fix_kind.contains(FixKind::Suggestion) {
"suggestions"
} else {
"fixes"
};
let message = format!(
"Plugin `{plugin_name}/{rule_name}` returned invalid fixes.\nFile path: {path}\n{err}"
"Plugin `{plugin_name}/{rule_name}` returned invalid {fixes_type}.\nFile path: {path}\n{err}"
);
ctx_host.push_diagnostic(Message::new(
OxcDiagnostic::error(message),
Expand All @@ -661,7 +666,7 @@ impl Linter {
};

// Convert fix
let fix = diagnostic.fixes.and_then(create_fix);
let fix = diagnostic.fixes.and_then(|fixes| create_fix(fixes, FixKind::Fix));

// Convert suggestions (only if fix kind allows suggestions), and combine with fix
let possible_fixes = if let Some(suggestions) = diagnostic.suggestions
Expand All @@ -674,11 +679,8 @@ impl Linter {
}

for suggestion in suggestions {
if let Some(fix) = create_fix(suggestion.fixes) {
fixes.push(
fix.with_message(suggestion.message)
.with_kind(FixKind::Suggestion),
);
if let Some(fix) = create_fix(suggestion.fixes, FixKind::Suggestion) {
fixes.push(fix.with_message(suggestion.message));
}
}

Expand Down
Loading