diff --git a/apps/oxlint/test/fixtures/suggestions/fix-suggestions.snap.md b/apps/oxlint/test/fixtures/suggestions/fix-suggestions.snap.md index d83b28fac37b5..b97a92f957c88 100644 --- a/apps/oxlint/test/fixtures/suggestions/fix-suggestions.snap.md +++ b/apps/oxlint/test/fixtures/suggestions/fix-suggestions.snap.md @@ -7,11 +7,11 @@ | File path: /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: /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: /files/range_end_out_of_bounds.js | Invalid range: 7..7 @@ -19,11 +19,11 @@ | File path: /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: /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: /files/range_start_after_end.js | Negative range is invalid: Span { start: 3, end: 2 } diff --git a/crates/oxc_linter/src/external_linter.rs b/crates/oxc_linter/src/external_linter.rs index 338b3f7ab44f9..bba364d03595a 100644 --- a/crates/oxc_linter/src/external_linter.rs +++ b/crates/oxc_linter/src/external_linter.rs @@ -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 = @@ -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 { diff --git a/crates/oxc_linter/src/lib.rs b/crates/oxc_linter/src/lib.rs index bf41ad9fa5976..b0ec186b741b9 100644 --- a/crates/oxc_linter/src/lib.rs +++ b/crates/oxc_linter/src/lib.rs @@ -642,15 +642,20 @@ impl Linter { } // Convert a `Vec` 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), @@ -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 @@ -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)); } }