From b4dadd8ed0f9e123cfaf7acc9fee8c96e19aa3dc Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Sat, 16 Sep 2023 10:00:25 +0100 Subject: [PATCH] fix(cli): correctly apply import sorting on --apply (#299) --- CHANGELOG.md | 9 + .../execute/process_file/organize_imports.rs | 2 +- crates/biome_cli/tests/commands/check.rs | 6 +- .../different_all_rules.snap | 174 ------------------ .../fs_error_dereferenced_symlink_unix.snap | 27 --- ...error_infinite_symlink_expansion_unix.snap | 37 ---- ...should_organize_imports_diff_on_check.snap | 25 +++ ..._organize_imports_diff_on_check_apply.snap | 57 ------ .../treats_typescript_json_like_jsonc.snap | 37 ---- .../apply_unsafe_no_assign_in_expression.snap | 17 -- .../main_commands_rage/with_server_logs.snap | 2 + editors/vscode/package.json | 2 +- packages/@biomejs/biome/package.json | 2 +- website/src/content/docs/analyzer/index.mdx | 8 +- .../src/content/docs/internals/changelog.mdx | 9 + .../src/pages/schemas/1.2.2/schema.json.js | 18 ++ 16 files changed, 73 insertions(+), 359 deletions(-) delete mode 100644 crates/biome_cli/tests/snapshots/main_commands_check/different_all_rules.snap delete mode 100644 crates/biome_cli/tests/snapshots/main_commands_check/fs_error_dereferenced_symlink_unix.snap delete mode 100644 crates/biome_cli/tests/snapshots/main_commands_check/fs_error_infinite_symlink_expansion_unix.snap create mode 100644 crates/biome_cli/tests/snapshots/main_commands_check/should_organize_imports_diff_on_check.snap delete mode 100644 crates/biome_cli/tests/snapshots/main_commands_check/shows_organize_imports_diff_on_check_apply.snap delete mode 100644 crates/biome_cli/tests/snapshots/main_commands_format/treats_typescript_json_like_jsonc.snap delete mode 100644 crates/biome_cli/tests/snapshots/main_commands_lint/apply_unsafe_no_assign_in_expression.snap create mode 100644 website/src/pages/schemas/1.2.2/schema.json.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 1605e6867d4f..bca87f6253cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,15 @@ Read our [guidelines for writing a good changelog entry](https://github.com/biom ### Parser ### VSCode +## 1.2.2 (2023-09-16) + +### CLI + +#### Bug fixes + +- Fix a condition where import sorting wasn't applied when running `biome check --apply` + + ## 1.2.1 (2023-09-15) ### Configuration diff --git a/crates/biome_cli/src/execute/process_file/organize_imports.rs b/crates/biome_cli/src/execute/process_file/organize_imports.rs index d7d6ec39a456..cf0086c2f975 100644 --- a/crates/biome_cli/src/execute/process_file/organize_imports.rs +++ b/crates/biome_cli/src/execute/process_file/organize_imports.rs @@ -20,7 +20,7 @@ pub(crate) fn organize_imports_with_guard<'ctx>( let input = workspace_file.input()?; if sorted.code != input { - if ctx.execution.is_check_apply_unsafe() { + if ctx.execution.is_check_apply_unsafe() || ctx.execution.is_check_apply() { workspace_file.update_file(sorted.code)?; } else { return Ok(FileStatus::Message(Message::Diff { diff --git a/crates/biome_cli/tests/commands/check.rs b/crates/biome_cli/tests/commands/check.rs index 8f748420655f..42739046e9b8 100644 --- a/crates/biome_cli/tests/commands/check.rs +++ b/crates/biome_cli/tests/commands/check.rs @@ -1628,7 +1628,7 @@ import * as something from "../something"; } #[test] -fn shows_organize_imports_diff_on_check_apply() { +fn should_organize_imports_diff_on_check() { let mut fs = MemoryFileSystem::default(); let mut console = BufferConsole::default(); @@ -1656,7 +1656,7 @@ import * as something from "../something"; ), ); - assert!(result.is_err(), "run_cli returned {result:?}"); + assert!(result.is_ok(), "run_cli returned {result:?}"); let mut file = fs .open(file_path) @@ -1672,7 +1672,7 @@ import * as something from "../something"; assert_cli_snapshot(SnapshotPayload::new( module_path!(), - "shows_organize_imports_diff_on_check_apply", + "should_organize_imports_diff_on_check", fs, console, result, diff --git a/crates/biome_cli/tests/snapshots/main_commands_check/different_all_rules.snap b/crates/biome_cli/tests/snapshots/main_commands_check/different_all_rules.snap deleted file mode 100644 index dab3d28ef6a8..000000000000 --- a/crates/biome_cli/tests/snapshots/main_commands_check/different_all_rules.snap +++ /dev/null @@ -1,174 +0,0 @@ ---- -source: crates/biome_cli/tests/snap_test.rs -expression: content ---- -## `rome.json` - -```json -{ - "linter": { - "rules": { - "all": true, - "style": { - "all": false - } - } - } -} -``` - -## `fix.js` - -```js - - function f() {arguments;} - const FOO = "FOO"; - var x, y; - -``` - -# Termination Message - -```block -internalError/io ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Some errors were emitted while running checks - - - -``` - -# Emitted Messages - -```block -fix.js:2:19 lint/correctness/noUndeclaredVariables ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - ! The arguments variable is undeclared - - > 2 │ function f() {arguments;} - │ ^^^^^^^^^ - 3 │ const FOO = "FOO"; - 4 │ var x, y; - - -``` - -```block -fix.js:2:14 lint/correctness/noUnusedVariables ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - ! This function is unused. - - > 2 │ function f() {arguments;} - │ ^ - 3 │ const FOO = "FOO"; - 4 │ var x, y; - - i Unused variables usually are result of incomplete refactoring, typos and other source of bugs. - - -``` - -```block -fix.js:3:11 lint/correctness/noUnusedVariables FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - ! This variable is unused. - - 2 │ function f() {arguments;} - > 3 │ const FOO = "FOO"; - │ ^^^ - 4 │ var x, y; - 5 │ - - i Unused variables usually are result of incomplete refactoring, typos and other source of bugs. - - i Suggested fix: If this is intentional, prepend FOO with an underscore. - - 1 1 │ - 2 2 │ function f() {arguments;} - 3 │ - ····const·FOO·=·"FOO"; - 3 │ + ····const·_FOO·=·"FOO"; - 4 4 │ var x, y; - 5 5 │ - - -``` - -```block -fix.js:4:5 lint/nursery/noVar FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - × Use let or const instead of var. - - 2 │ function f() {arguments;} - 3 │ const FOO = "FOO"; - > 4 │ var x, y; - │ ^^^^^^^^ - 5 │ - - i A variable declared with var is accessible in the whole module. Thus, the variable can be accessed before its initialization and outside the block where it is declared. - - i See MDN web docs for more details. - - i Suggested fix: Use 'let' instead. - - 2 2 │ function f() {arguments;} - 3 3 │ const FOO = "FOO"; - 4 │ - ····var·x,·y; - 4 │ + ····let·x,·y; - 5 5 │ - - -``` - -```block -fix.js:4:9 lint/correctness/noUnusedVariables FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - ! This variable is unused. - - 2 │ function f() {arguments;} - 3 │ const FOO = "FOO"; - > 4 │ var x, y; - │ ^ - 5 │ - - i Unused variables usually are result of incomplete refactoring, typos and other source of bugs. - - i Suggested fix: If this is intentional, prepend x with an underscore. - - 2 2 │ function f() {arguments;} - 3 3 │ const FOO = "FOO"; - 4 │ - ····var·x,·y; - 4 │ + ····var·_x,·y; - 5 5 │ - - -``` - -```block -fix.js:4:12 lint/correctness/noUnusedVariables FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - - ! This variable is unused. - - 2 │ function f() {arguments;} - 3 │ const FOO = "FOO"; - > 4 │ var x, y; - │ ^ - 5 │ - - i Unused variables usually are result of incomplete refactoring, typos and other source of bugs. - - i Suggested fix: If this is intentional, prepend y with an underscore. - - 2 2 │ function f() {arguments;} - 3 3 │ const FOO = "FOO"; - 4 │ - ····var·x,·y; - 4 │ + ····var·x,·_y; - 5 5 │ - - -``` - -```block -Checked 1 file(s) in