diff --git a/crates/biome_cli/src/execute/process_file/lint.rs b/crates/biome_cli/src/execute/process_file/lint.rs index 91eecd29f672..8638d8b2a2d2 100644 --- a/crates/biome_cli/src/execute/process_file/lint.rs +++ b/crates/biome_cli/src/execute/process_file/lint.rs @@ -22,10 +22,16 @@ pub(crate) fn lint_with_guard<'ctx>( move || { let mut input = workspace_file.input()?; let mut changed = false; + let (only, skip) = + if let TraversalMode::Lint { only, skip, .. } = ctx.execution.traversal_mode() { + (only.clone(), skip.clone()) + } else { + (Vec::new(), Vec::new()) + }; if let Some(fix_mode) = ctx.execution.as_fix_file_mode() { let fix_result = workspace_file .guard() - .fix_file(*fix_mode, false) + .fix_file(*fix_mode, false, only.clone(), skip.clone()) .with_file_path_and_code( workspace_file.path.display().to_string(), category!("lint"), @@ -57,12 +63,6 @@ pub(crate) fn lint_with_guard<'ctx>( } let max_diagnostics = ctx.remaining_diagnostics.load(Ordering::Relaxed); - let (only, skip) = - if let TraversalMode::Lint { only, skip, .. } = ctx.execution.traversal_mode() { - (only.clone(), skip.clone()) - } else { - (Vec::new(), Vec::new()) - }; let pull_diagnostics_result = workspace_file .guard() .pull_diagnostics( diff --git a/crates/biome_cli/src/execute/std_in.rs b/crates/biome_cli/src/execute/std_in.rs index ecdb12d0d69d..840c882a77d5 100644 --- a/crates/biome_cli/src/execute/std_in.rs +++ b/crates/biome_cli/src/execute/std_in.rs @@ -108,12 +108,20 @@ pub(crate) fn run<'a>( return Ok(()); }; + let (only, skip) = if let TraversalMode::Lint { only, skip, .. } = mode.traversal_mode() { + (only.clone(), skip.clone()) + } else { + (Vec::new(), Vec::new()) + }; + if let Some(fix_file_mode) = mode.as_fix_file_mode() { if file_features.supports_lint() { let fix_file_result = workspace.fix_file(FixFileParams { fix_file_mode: *fix_file_mode, path: biome_path.clone(), should_format: mode.is_check() && file_features.supports_format(), + only: only.clone(), + skip: skip.clone(), })?; let code = fix_file_result.code; let output = match biome_path.extension_as_str() { @@ -156,11 +164,6 @@ pub(crate) fn run<'a>( } } - let (only, skip) = if let TraversalMode::Lint { only, skip, .. } = mode.traversal_mode() { - (only.clone(), skip.clone()) - } else { - (Vec::new(), Vec::new()) - }; if !mode.is_check_apply_unsafe() { let result = workspace.pull_diagnostics(PullDiagnosticsParams { categories: RuleCategoriesBuilder::default() diff --git a/crates/biome_cli/tests/commands/lint.rs b/crates/biome_cli/tests/commands/lint.rs index 3b641565d003..b3a7a4578f86 100644 --- a/crates/biome_cli/tests/commands/lint.rs +++ b/crates/biome_cli/tests/commands/lint.rs @@ -3806,6 +3806,46 @@ fn lint_only_group_with_disabled_rule() { )); } +#[test] +fn lint_only_write() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + let config = r#"{}"#; + let content = r#" + export const z = function (array) { + array.map((sentence) => sentence.split(" ")).flat(); + return 0; + }; + "#; + + let file_path = Path::new("check.js"); + fs.insert(file_path.into(), content.as_bytes()); + let config_path = Path::new("biome.json"); + fs.insert(config_path.into(), config.as_bytes()); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from( + [ + ("lint"), + "--write", + "--only=complexity/useArrowFunction", + file_path.as_os_str().to_str().unwrap(), + ] + .as_slice(), + ), + ); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "lint_only_write", + fs, + console, + result, + )); +} + #[test] fn lint_skip_rule() { let mut fs = MemoryFileSystem::default(); @@ -3943,6 +3983,46 @@ fn lint_skip_rule_and_group() { )); } +#[test] +fn lint_skip_write() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + let config = r#"{}"#; + let content = r#" + export const z = function (array) { + array.map((sentence) => sentence.split(" ")).flat(); + return 0; + }; + "#; + + let file_path = Path::new("check.js"); + fs.insert(file_path.into(), content.as_bytes()); + let config_path = Path::new("biome.json"); + fs.insert(config_path.into(), config.as_bytes()); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from( + [ + ("lint"), + "--write", + "--skip=complexity/useArrowFunction", + file_path.as_os_str().to_str().unwrap(), + ] + .as_slice(), + ), + ); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "lint_skip_write", + fs, + console, + result, + )); +} + #[test] fn lint_only_group_skip_rule() { let mut fs = MemoryFileSystem::default(); diff --git a/crates/biome_cli/tests/snapshots/main_commands_lint/lint_only_write.snap b/crates/biome_cli/tests/snapshots/main_commands_lint/lint_only_write.snap new file mode 100644 index 000000000000..23aac6f49400 --- /dev/null +++ b/crates/biome_cli/tests/snapshots/main_commands_lint/lint_only_write.snap @@ -0,0 +1,26 @@ +--- +source: crates/biome_cli/tests/snap_test.rs +expression: content +--- +## `biome.json` + +```json +{} +``` + +## `check.js` + +```js + + export const z = (array) => { + array.map((sentence) => sentence.split(" ")).flat(); + return 0; + }; + +``` + +# Emitted Messages + +```block +Checked 1 file in