From 9aa5c4eb1b3995a3242e383073613f2df6147a16 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Fri, 15 Sep 2023 17:38:43 +0100 Subject: [PATCH] fix: schema and formatter language application (#292) --- CHANGELOG.md | 19 ++++ crates/biome_cli/tests/commands/format.rs | 94 +++++++++++++++++++ .../should_apply_different_indent_style.snap | 61 ++++++++++++ .../src/configuration/javascript/formatter.rs | 1 + .../biome_service/src/configuration/json.rs | 3 +- .../src/file_handlers/javascript.rs | 33 +++---- .../biome_service/src/file_handlers/json.rs | 33 +++---- editors/vscode/configuration_schema.json | 8 +- editors/vscode/package.json | 2 +- .../@biomejs/backend-jsonrpc/src/workspace.ts | 6 +- .../@biomejs/biome/configuration_schema.json | 8 +- packages/@biomejs/biome/package.json | 2 +- .../src/content/docs/internals/changelog.mdx | 19 ++++ .../src/pages/schemas/1.2.1/schema.json.js | 18 ++++ 14 files changed, 249 insertions(+), 58 deletions(-) create mode 100644 crates/biome_cli/tests/snapshots/main_commands_format/should_apply_different_indent_style.snap create mode 100644 website/src/pages/schemas/1.2.1/schema.json.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 03a0f1c52718..1605e6867d4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,25 @@ Read our [guidelines to categorize a change](https://biomejs.dev/internals/versi New entries must be placed in a section entitled `Unreleased`. Read our [guidelines for writing a good changelog entry](https://github.com/biomejs/biome/blob/main/CONTRIBUTING.md#changelog). +## Unreleased + +### Analyzer +### CLI +### Configuration +### Editors +### Formatter +### JavaScript APIs +### Linter +### Parser +### VSCode + +## 1.2.1 (2023-09-15) + +### Configuration + +- Fix an edge case where the formatter language configuration wasn't picked. +- Fix the configuration schema, where `json.formatter` properties weren't transformed in camel case. + ## 1.2.0 (2023-09-15) ### CLI diff --git a/crates/biome_cli/tests/commands/format.rs b/crates/biome_cli/tests/commands/format.rs index 2beed9115e18..2bf5a37cc13c 100644 --- a/crates/biome_cli/tests/commands/format.rs +++ b/crates/biome_cli/tests/commands/format.rs @@ -2241,3 +2241,97 @@ const a = { result, )); } + +#[test] +fn should_apply_different_indent_style() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + let biome_json = Path::new("biome.json"); + fs.insert( + biome_json.into(), + r#"{ + "formatter": { + "indentStyle": "space" + }, + "javascript": { + "formatter": { + "lineWidth": 320, + "indentSize": 8, + "indentStyle": "tab" + } + }, + "json": { + "formatter": { + "lineWidth": 80, + "indentSize": 2, + "indentStyle": "tab" + } + } + }"#, + ); + + let json_file_content = r#" +{ + "array": ["lorem ipsum", "lorem ipsum", "lorem ipsum", "lorem ipsum", "lorem ipsum", "lorem ipsum", "lorem ipsum"] +} + "#; + let json_file = Path::new("input.json"); + fs.insert(json_file.into(), json_file_content.as_bytes()); + + let js_file_content = r#" +const a = { + "array": ["lorem ipsum", "lorem ipsum", "lorem ipsum", "lorem ipsum", "lorem ipsum", "lorem ipsum", "lorem ipsum"] +} + "#; + let js_file = Path::new("input.js"); + fs.insert(js_file.into(), js_file_content.as_bytes()); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from( + [ + ("format"), + "--write", + json_file.as_os_str().to_str().unwrap(), + js_file.as_os_str().to_str().unwrap(), + ] + .as_slice(), + ), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + let mut file = fs + .open(js_file) + .expect("formatting target file was removed by the CLI"); + + let mut content = String::new(); + file.read_to_string(&mut content) + .expect("failed to read file from memory FS"); + + assert!(content.contains('\t'), "should not contain tabs"); + + drop(file); + + let mut file = fs + .open(json_file) + .expect("formatting target file was removed by the CLI"); + + let mut content = String::new(); + file.read_to_string(&mut content) + .expect("failed to read file from memory FS"); + + assert!(content.contains('\t'), "should not contain tabs"); + + drop(file); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "should_apply_different_indent_style", + fs, + console, + result, + )); +} diff --git a/crates/biome_cli/tests/snapshots/main_commands_format/should_apply_different_indent_style.snap b/crates/biome_cli/tests/snapshots/main_commands_format/should_apply_different_indent_style.snap new file mode 100644 index 000000000000..f0ab296e6cc2 --- /dev/null +++ b/crates/biome_cli/tests/snapshots/main_commands_format/should_apply_different_indent_style.snap @@ -0,0 +1,61 @@ +--- +source: crates/biome_cli/tests/snap_test.rs +expression: content +--- +## `biome.json` + +```json +{ + "formatter": { + "indentStyle": "space" + }, + "javascript": { + "formatter": { + "lineWidth": 320, + "indentSize": 8, + "indentStyle": "tab" + } + }, + "json": { + "formatter": { + "lineWidth": 80, + "indentSize": 2, + "indentStyle": "tab" + } + } +} +``` + +## `input.js` + +```js +const a = { + array: ["lorem ipsum", "lorem ipsum", "lorem ipsum", "lorem ipsum", "lorem ipsum", "lorem ipsum", "lorem ipsum"], +}; + +``` + +## `input.json` + +```json +{ + "array": [ + "lorem ipsum", + "lorem ipsum", + "lorem ipsum", + "lorem ipsum", + "lorem ipsum", + "lorem ipsum", + "lorem ipsum" + ] +} + +``` + +# Emitted Messages + +```block +Formatted 2 file(s) in