From 31dc7ac765103bcdddeb03582cd0811ad6de1c62 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Tue, 16 Jan 2024 10:48:05 +0000 Subject: [PATCH] feat(cli): file system prettier migration (#1567) --- crates/biome_cli/fixtures/input.json | 8 - crates/biome_cli/src/execute/migrate.rs | 123 ++++++++++-- .../biome_cli/src/execute/migrate/prettier.rs | 181 ++++++++++++++---- crates/biome_cli/src/execute/process_file.rs | 2 +- crates/biome_cli/tests/commands/migrate.rs | 120 ++++++++++++ .../emit_diagnostic_for_rome_json.snap | 2 +- .../prettier_migrate.snap | 57 ++++++ .../prettier_migrate_no_file.snap | 22 +++ .../prettier_migrate_write.snap | 45 +++++ .../prettier_migrate_yml_file.snap | 69 +++++++ 10 files changed, 566 insertions(+), 63 deletions(-) delete mode 100644 crates/biome_cli/fixtures/input.json create mode 100644 crates/biome_cli/tests/snapshots/main_commands_migrate/prettier_migrate.snap create mode 100644 crates/biome_cli/tests/snapshots/main_commands_migrate/prettier_migrate_no_file.snap create mode 100644 crates/biome_cli/tests/snapshots/main_commands_migrate/prettier_migrate_write.snap create mode 100644 crates/biome_cli/tests/snapshots/main_commands_migrate/prettier_migrate_yml_file.snap diff --git a/crates/biome_cli/fixtures/input.json b/crates/biome_cli/fixtures/input.json deleted file mode 100644 index 217c9ce522a0..000000000000 --- a/crates/biome_cli/fixtures/input.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "string": "foo", - "boolean": false, - "number": 15, - "object": { - "something": 15 - } -} diff --git a/crates/biome_cli/src/execute/migrate.rs b/crates/biome_cli/src/execute/migrate.rs index fe3b8645eadf..4db51f35551b 100644 --- a/crates/biome_cli/src/execute/migrate.rs +++ b/crates/biome_cli/src/execute/migrate.rs @@ -1,17 +1,25 @@ mod prettier; +use crate::diagnostics::MigrationDiagnostic; use crate::execute::diagnostics::{ContentDiffAdvice, MigrateDiffDiagnostic}; +use crate::execute::migrate::prettier::read_prettier_files; use crate::{CliDiagnostic, CliSession}; use biome_console::{markup, ConsoleExt}; +use biome_deserialize::json::deserialize_from_json_str; +use biome_deserialize::Merge; +use biome_deserialize::NoneState; use biome_diagnostics::Diagnostic; use biome_diagnostics::{category, PrintDiagnostic}; -use biome_fs::{FileSystemExt, OpenOptions}; -use biome_json_parser::JsonParserOptions; +use biome_fs::{FileSystemExt, OpenOptions, RomePath}; +use biome_json_parser::{parse_json_with_cache, JsonParserOptions}; use biome_json_syntax::JsonRoot; use biome_migrate::{migrate_configuration, ControlFlow}; -use biome_rowan::AstNode; -use biome_service::workspace::FixAction; -use biome_service::VERSION; +use biome_rowan::{AstNode, NodeCache}; +use biome_service::configuration::JavascriptConfiguration; +use biome_service::workspace::{ + ChangeFileParams, FixAction, FormatFileParams, Language, OpenFileParams, +}; +use biome_service::{Configuration, VERSION}; use std::borrow::Cow; use std::ffi::OsStr; use std::path::PathBuf; @@ -33,10 +41,13 @@ pub(crate) fn run(migrate_payload: MigratePayload) -> Result<(), CliDiagnostic> configuration_file_path, configuration_directory_path, verbose, - // we will use it later - prettier: _, + prettier, } = migrate_payload; - let fs = &*session.app.fs; + let mut cache = NodeCache::default(); + let fs = &session.app.fs; + let console = session.app.console; + let workspace = session.app.workspace; + let has_deprecated_configuration = configuration_file_path.file_name() == Some(OsStr::new("rome.json")); @@ -50,8 +61,21 @@ pub(crate) fn run(migrate_payload: MigratePayload) -> Result<(), CliDiagnostic> fs.open_with_options(configuration_file_path.as_path(), open_options)?; let mut configuration_content = String::new(); configuration_file.read_to_string(&mut configuration_content)?; - let parsed = - biome_json_parser::parse_json(&configuration_content, JsonParserOptions::default()); + + let rome_path = RomePath::new(configuration_file_path.as_path()); + workspace.open_file(OpenFileParams { + path: rome_path.clone(), + content: configuration_content.to_string(), + version: 0, + language_hint: Language::Json, + })?; + + let parsed = parse_json_with_cache( + &configuration_content, + &mut cache, + JsonParserOptions::default(), + ); + let mut errors = 0; let mut tree = parsed.tree(); let mut actions = Vec::new(); @@ -94,10 +118,70 @@ pub(crate) fn run(migrate_payload: MigratePayload) -> Result<(), CliDiagnostic> } } } - let console = &mut *session.app.console; + let new_configuration_content = tree.to_string(); - if configuration_content != new_configuration_content || has_deprecated_configuration { + if prettier { + let prettier_configuration = read_prettier_files(fs, console)?; + + if let Some((formatter_configuration, javascript_configuration)) = + prettier_configuration.get_biome_configuration() + { + let configuration = deserialize_from_json_str::( + configuration_content.as_str(), + JsonParserOptions::default(), + "", + ) + .into_deserialized(); + if let Some(mut configuration) = configuration { + configuration.merge_with(Configuration { + formatter: Some(formatter_configuration.clone()), + javascript: Some(JavascriptConfiguration { + formatter: Some(javascript_configuration.clone()), + ..NoneState::none() + }), + ..NoneState::none() + }); + + let new_content = serde_json::to_string(&configuration).map_err(|err| { + CliDiagnostic::MigrateError(MigrationDiagnostic { + reason: err.to_string(), + }) + })?; + + workspace.change_file(ChangeFileParams { + path: rome_path.clone(), + content: new_content, + version: 1, + })?; + + let printed = workspace.format_file(FormatFileParams { + path: rome_path.clone(), + })?; + + if write { + configuration_file.set_content(printed.as_code().as_bytes())?; + console.log(markup!{ + "The configuration "{{configuration_file_path.display().to_string()}}" has been successfully migrated." + }); + } else { + let file_name = configuration_file_path.display().to_string(); + let diagnostic = MigrateDiffDiagnostic { + file_name, + diff: ContentDiffAdvice { + old: configuration_content, + new: printed.as_code().to_string(), + }, + }; + console.error(markup! {{PrintDiagnostic::simple(&diagnostic)}}); + + console.log(markup! { + "Run the command with the option ""--write"" to apply the changes." + }) + } + } + } + } else if configuration_content != new_configuration_content || has_deprecated_configuration { if write { let mut configuration_file = if has_deprecated_configuration { let biome_file_path = configuration_directory_path.join(fs.config_name()); @@ -107,8 +191,8 @@ pub(crate) fn run(migrate_payload: MigratePayload) -> Result<(), CliDiagnostic> }; configuration_file.set_content(tree.to_string().as_bytes())?; console.log(markup!{ - "The configuration "{{configuration_file_path.display().to_string()}}" has been successfully migrated." - }) + "The configuration "{{configuration_file_path.display().to_string()}}" has been successfully migrated." + }) } else { let file_name = configuration_file_path.display().to_string(); let diagnostic = if has_deprecated_configuration { @@ -128,14 +212,16 @@ pub(crate) fn run(migrate_payload: MigratePayload) -> Result<(), CliDiagnostic> }, } }; - if diagnostic.tags().is_verbose() && verbose { - console.error(markup! {{PrintDiagnostic::verbose(&diagnostic)}}) + if diagnostic.tags().is_verbose() { + if verbose { + console.error(markup! {{PrintDiagnostic::verbose(&diagnostic)}}) + } } else { console.error(markup! {{PrintDiagnostic::simple(&diagnostic)}}) } console.log(markup! { - "Run the command ""biome migrate --write"" to apply the changes." - }) + "Run the command with the option ""--write"" to apply the changes." + }) } } else { console.log(markup! { @@ -144,5 +230,6 @@ pub(crate) fn run(migrate_payload: MigratePayload) -> Result<(), CliDiagnostic> }) } + Ok(()) } diff --git a/crates/biome_cli/src/execute/migrate/prettier.rs b/crates/biome_cli/src/execute/migrate/prettier.rs index 4ab3054c0863..d992ee127895 100644 --- a/crates/biome_cli/src/execute/migrate/prettier.rs +++ b/crates/biome_cli/src/execute/migrate/prettier.rs @@ -1,15 +1,23 @@ +use crate::diagnostics::MigrationDiagnostic; +use crate::CliDiagnostic; +use biome_console::{markup, Console, ConsoleExt}; +use biome_deserialize::json::deserialize_from_json_str; use biome_deserialize::{ Deserializable, DeserializableValue, DeserializationDiagnostic, DeserializationVisitor, Text, VisitableType, }; +use biome_diagnostics::{DiagnosticExt, PrintDiagnostic}; use biome_formatter::{LineEnding, LineWidth, QuoteStyle}; +use biome_fs::{FileSystem, OpenOptions}; use biome_js_formatter::context::{ArrowParentheses, QuoteProperties, Semicolons, TrailingComma}; +use biome_json_parser::JsonParserOptions; use biome_service::configuration::{FormatterConfiguration, PlainIndentStyle}; -use biome_service::JavascriptFormatter; +use biome_service::{DynRef, JavascriptFormatter}; use biome_text_size::TextRange; +use std::path::{Path, PathBuf}; -#[derive(Debug, Eq, PartialEq)] -struct PrettierConfiguration { +#[derive(Debug, Eq, PartialEq, Clone)] +pub(crate) struct PrettierConfiguration { /// https://prettier.io/docs/en/options#print-width print_width: u16, /// https://prettier.io/docs/en/options#use-tabs @@ -36,7 +44,27 @@ struct PrettierConfiguration { end_of_line: EndOfLine, } -#[derive(Debug, Eq, PartialEq, Default)] +impl Default for PrettierConfiguration { + fn default() -> Self { + Self { + print_width: 80, + + use_tabs: false, + trailing_comma: PrettierTrailingComma::default(), + tab_width: 2, + semi: false, + single_quote: true, + bracket_spacing: true, + bracket_line: false, + quote_props: QuoteProps::default(), + jsx_single_quote: false, + arrow_parens: ArrowParens::default(), + end_of_line: EndOfLine::default(), + } + } +} + +#[derive(Debug, Eq, PartialEq, Default, Clone)] enum EndOfLine { #[default] Lf, @@ -67,7 +95,7 @@ impl Deserializable for EndOfLine { } } -#[derive(Debug, Eq, PartialEq, Default)] +#[derive(Debug, Eq, PartialEq, Default, Clone)] enum ArrowParens { #[default] Always, @@ -96,7 +124,7 @@ impl Deserializable for ArrowParens { } } -#[derive(Debug, Eq, PartialEq, Default)] +#[derive(Debug, Default, Eq, PartialEq, Clone)] enum PrettierTrailingComma { #[default] All, @@ -127,8 +155,7 @@ impl Deserializable for PrettierTrailingComma { } } -#[derive(Debug, Eq, PartialEq, Default)] - +#[derive(Debug, Eq, Default, PartialEq, Clone)] enum QuoteProps { #[default] AsNeeded, @@ -169,26 +196,6 @@ impl TryFrom<&str> for PrettierTrailingComma { } } -impl Default for PrettierConfiguration { - fn default() -> Self { - Self { - print_width: 80, - - use_tabs: false, - trailing_comma: PrettierTrailingComma::default(), - tab_width: 4, - semi: false, - single_quote: true, - bracket_spacing: true, - bracket_line: false, - quote_props: QuoteProps::default(), - jsx_single_quote: false, - arrow_parens: ArrowParens::default(), - end_of_line: EndOfLine::default(), - } - } -} - impl Deserializable for PrettierConfiguration { fn deserialize( value: &impl DeserializableValue, @@ -337,8 +344,7 @@ impl From for QuoteProperties { impl TryFrom for FormatterConfiguration { type Error = String; fn try_from(value: PrettierConfiguration) -> Result { - // TODO: handle error - let line_width = LineWidth::try_from(value.print_width).unwrap(); + let line_width = LineWidth::try_from(value.print_width).map_err(|err| err.to_string())?; let indent_style = if value.use_tabs { PlainIndentStyle::Tab } else { @@ -359,9 +365,8 @@ impl TryFrom for FormatterConfiguration { } } -impl TryFrom for JavascriptFormatter { - type Error = String; - fn try_from(value: PrettierConfiguration) -> Result { +impl From for JavascriptFormatter { + fn from(value: PrettierConfiguration) -> Self { let semicolons = if value.semi { Semicolons::Always } else { @@ -377,7 +382,7 @@ impl TryFrom for JavascriptFormatter { } else { QuoteStyle::Double }; - Ok(Self { + Self { indent_width: None, line_width: None, indent_style: None, @@ -395,8 +400,114 @@ impl TryFrom for JavascriptFormatter { quote_properties: Some(value.quote_props.into()), bracket_spacing: Some(value.bracket_spacing), jsx_quote_style: Some(jsx_quote_style), - }) + } + } +} + +#[derive(Debug, Default)] +pub(crate) struct FromPrettierConfiguration { + /// Path of the Prettier configuration file + configuration_path: Option, + /// Path of the `.prettierignore` file + #[allow(unused)] + ignore_path: Option, + + /// The translated Biome configuration, from the Prettier configuration + biome_configuration: Option<(FormatterConfiguration, JavascriptFormatter)>, +} + +impl FromPrettierConfiguration { + pub(crate) fn store_configuration( + &mut self, + configuration: (FormatterConfiguration, JavascriptFormatter), + ) { + self.biome_configuration = Some(configuration); + } + + pub(crate) fn store_configuration_path(&mut self, path: PathBuf) { + self.configuration_path = Some(path); + } + + #[allow(unused)] + pub(crate) fn store_ignore_path(&mut self, path: PathBuf) { + self.ignore_path = Some(path) + } + + pub(crate) fn get_biome_configuration( + &self, + ) -> Option<&(FormatterConfiguration, JavascriptFormatter)> { + self.biome_configuration.as_ref() + } +} + +const PRETTIER_CONFIG_FILES: [&str; 2] = [".prettierrc", ".prettierrc.json"]; +/// This function is in charge of reading prettier files, deserialize its contents and convert them in a Biome configuration type +pub(crate) fn read_prettier_files( + fs: &DynRef<'_, dyn FileSystem>, + console: &mut dyn Console, +) -> Result { + let mut from_prettier_configuration = FromPrettierConfiguration::default(); + let mut content = String::new(); + let mut prettier_config_path = Path::new(""); + for config_name in PRETTIER_CONFIG_FILES { + let open_options = OpenOptions::default().read(true); + let path = Path::new(config_name); + let file = fs.open_with_options(path, open_options); + match file { + Ok(mut file) => { + let result = file.read_to_string(&mut content); + if let Err(err) = result { + return Err(CliDiagnostic::io_error(err)); + } + prettier_config_path = path; + break; + } + Err(_) => { + continue; + } + } } + + if content.is_empty() { + return Err(CliDiagnostic::MigrateError(MigrationDiagnostic { + reason: "Biome couldn't find a Prettier configuration file.".to_string(), + })); + } + + from_prettier_configuration.store_configuration_path(prettier_config_path.to_path_buf()); + + let deserialized = deserialize_from_json_str::( + content.as_str(), + JsonParserOptions::default() + .with_allow_trailing_commas() + .with_allow_comments(), + "", + ); + + if deserialized.has_errors() { + let diagnostics = deserialized.into_diagnostics(); + for diagnostic in diagnostics { + let diagnostic = diagnostic.with_file_path(prettier_config_path.display().to_string()); + console.error(markup! {{PrintDiagnostic::simple(&diagnostic)}}); + } + return Err(CliDiagnostic::MigrateError(MigrationDiagnostic { + reason: "Could not deserialize the Prettier configuration file".to_string(), + })); + } else { + let prettier_configuration = deserialized.into_deserialized(); + + if let Some(prettier_configuration) = prettier_configuration { + let formatter_configuration = prettier_configuration + .clone() + .try_into() + .map_err(|err| CliDiagnostic::MigrateError(MigrationDiagnostic { reason: err }))?; + let javascript_configuration = prettier_configuration.into(); + from_prettier_configuration + .store_configuration((formatter_configuration, javascript_configuration)); + } + } + + Ok(from_prettier_configuration) } #[cfg(test)] diff --git a/crates/biome_cli/src/execute/process_file.rs b/crates/biome_cli/src/execute/process_file.rs index c5f012f4f52a..f2984070d149 100644 --- a/crates/biome_cli/src/execute/process_file.rs +++ b/crates/biome_cli/src/execute/process_file.rs @@ -2,7 +2,7 @@ mod check; mod format; mod lint; mod organize_imports; -mod workspace_file; +pub(crate) mod workspace_file; use crate::execute::diagnostics::{ResultExt, UnhandledDiagnostic}; use crate::execute::process_file::check::check_file; diff --git a/crates/biome_cli/tests/commands/migrate.rs b/crates/biome_cli/tests/commands/migrate.rs index 46e0bd75bcc9..eaa0963108bf 100644 --- a/crates/biome_cli/tests/commands/migrate.rs +++ b/crates/biome_cli/tests/commands/migrate.rs @@ -132,3 +132,123 @@ fn should_create_biome_json_file() { result, )); } + +#[test] +fn prettier_migrate() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + let configuration = r#"{ "linter": { "enabled": true } }"#; + let prettier = r#"{ "useTabs": false, "semi": true, "singleQuote": true }"#; + + let configuration_path = Path::new("biome.json"); + fs.insert(configuration_path.into(), configuration.as_bytes()); + + let prettier_path = Path::new(".prettierrc"); + fs.insert(prettier_path.into(), prettier.as_bytes()); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from([("migrate"), "--prettier"].as_slice()), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "prettier_migrate", + fs, + console, + result, + )); +} + +#[test] +fn prettier_migrate_no_file() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + let configuration = r#"{ "linter": { "enabled": true } }"#; + + let configuration_path = Path::new("biome.json"); + fs.insert(configuration_path.into(), configuration.as_bytes()); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from([("migrate"), "--prettier"].as_slice()), + ); + + assert!(result.is_err(), "run_cli returned {result:?}"); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "prettier_migrate_no_file", + fs, + console, + result, + )); +} + +#[test] +fn prettier_migrate_yml_file() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + let configuration = r#"{ "linter": { "enabled": true } }"#; + let prettier = r#"useTabs: true"#; + + let configuration_path = Path::new("biome.json"); + fs.insert(configuration_path.into(), configuration.as_bytes()); + + let prettier_path = Path::new(".prettierrc"); + fs.insert(prettier_path.into(), prettier.as_bytes()); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from([("migrate"), "--prettier"].as_slice()), + ); + + assert!(result.is_err(), "run_cli returned {result:?}"); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "prettier_migrate_yml_file", + fs, + console, + result, + )); +} + +#[test] +fn prettier_migrate_write() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + let configuration = r#"{ "linter": { "enabled": true } }"#; + let prettier = r#"{ "useTabs": false, "semi": true, "singleQuote": true }"#; + + let configuration_path = Path::new("biome.json"); + fs.insert(configuration_path.into(), configuration.as_bytes()); + + let prettier_path = Path::new(".prettierrc"); + fs.insert(prettier_path.into(), prettier.as_bytes()); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from([("migrate"), "--prettier", "--write"].as_slice()), + ); + + assert!(result.is_ok(), "run_cli returned {result:?}"); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "prettier_migrate_write", + fs, + console, + result, + )); +} diff --git a/crates/biome_cli/tests/snapshots/main_commands_migrate/emit_diagnostic_for_rome_json.snap b/crates/biome_cli/tests/snapshots/main_commands_migrate/emit_diagnostic_for_rome_json.snap index 2f2ce3db3204..36a109902322 100644 --- a/crates/biome_cli/tests/snapshots/main_commands_migrate/emit_diagnostic_for_rome_json.snap +++ b/crates/biome_cli/tests/snapshots/main_commands_migrate/emit_diagnostic_for_rome_json.snap @@ -22,7 +22,7 @@ rome.json migrate ━━━━━━━━━━━━━━━━━━━━ ``` ```block -Run the command biome migrate --write to apply the changes. +Run the command with the option --write to apply the changes. ``` diff --git a/crates/biome_cli/tests/snapshots/main_commands_migrate/prettier_migrate.snap b/crates/biome_cli/tests/snapshots/main_commands_migrate/prettier_migrate.snap new file mode 100644 index 000000000000..653d0ec8d720 --- /dev/null +++ b/crates/biome_cli/tests/snapshots/main_commands_migrate/prettier_migrate.snap @@ -0,0 +1,57 @@ +--- +source: crates/biome_cli/tests/snap_test.rs +expression: content +--- +## `biome.json` + +```json +{ "linter": { "enabled": true } } +``` + +## `.prettierrc` + +```prettierrc +{ "useTabs": false, "semi": true, "singleQuote": true } +``` + +# Emitted Messages + +```block +biome.json migrate ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + i Configuration file can be updated. + + 1 │ - {·"linter":·{·"enabled":·true·}·} + 1 │ + { + 2 │ + → "formatter":·{ + 3 │ + → → "enabled":·true, + 4 │ + → → "formatWithErrors":·false, + 5 │ + → → "indentStyle":·"space", + 6 │ + → → "indentWidth":·2, + 7 │ + → → "lineEnding":·"lf", + 8 │ + → → "lineWidth":·80 + 9 │ + → }, + 10 │ + → "linter":·{·"enabled":·true·}, + 11 │ + → "javascript":·{ + 12 │ + → → "formatter":·{ + 13 │ + → → → "jsxQuoteStyle":·"double", + 14 │ + → → → "quoteProperties":·"asNeeded", + 15 │ + → → → "trailingComma":·"all", + 16 │ + → → → "semicolons":·"always", + 17 │ + → → → "arrowParentheses":·"always", + 18 │ + → → → "bracketSpacing":·true, + 19 │ + → → → "bracketSameLine":·false, + 20 │ + → → → "quoteStyle":·"single" + 21 │ + → → } + 22 │ + → } + 23 │ + } + 24 │ + + + +``` + +```block +Run the command with the option --write to apply the changes. +``` + + diff --git a/crates/biome_cli/tests/snapshots/main_commands_migrate/prettier_migrate_no_file.snap b/crates/biome_cli/tests/snapshots/main_commands_migrate/prettier_migrate_no_file.snap new file mode 100644 index 000000000000..7db630b47423 --- /dev/null +++ b/crates/biome_cli/tests/snapshots/main_commands_migrate/prettier_migrate_no_file.snap @@ -0,0 +1,22 @@ +--- +source: crates/biome_cli/tests/snap_test.rs +expression: content +--- +## `biome.json` + +```json +{ "linter": { "enabled": true } } +``` + +# Termination Message + +```block +migrate ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Migration has encountered an error: Biome couldn't find a Prettier configuration file. + + + +``` + + diff --git a/crates/biome_cli/tests/snapshots/main_commands_migrate/prettier_migrate_write.snap b/crates/biome_cli/tests/snapshots/main_commands_migrate/prettier_migrate_write.snap new file mode 100644 index 000000000000..0e94e055c0e7 --- /dev/null +++ b/crates/biome_cli/tests/snapshots/main_commands_migrate/prettier_migrate_write.snap @@ -0,0 +1,45 @@ +--- +source: crates/biome_cli/tests/snap_test.rs +expression: content +--- +## `biome.json` + +```json +{ + "formatter": { + "enabled": true, + "formatWithErrors": false, + "indentStyle": "space", + "indentWidth": 2, + "lineEnding": "lf", + "lineWidth": 80 + }, + "linter": { "enabled": true }, + "javascript": { + "formatter": { + "jsxQuoteStyle": "double", + "quoteProperties": "asNeeded", + "trailingComma": "all", + "semicolons": "always", + "arrowParentheses": "always", + "bracketSpacing": true, + "bracketSameLine": false, + "quoteStyle": "single" + } + } +} +``` + +## `.prettierrc` + +```prettierrc +{ "useTabs": false, "semi": true, "singleQuote": true } +``` + +# Emitted Messages + +```block +The configuration biome.json has been successfully migrated. +``` + + diff --git a/crates/biome_cli/tests/snapshots/main_commands_migrate/prettier_migrate_yml_file.snap b/crates/biome_cli/tests/snapshots/main_commands_migrate/prettier_migrate_yml_file.snap new file mode 100644 index 000000000000..7195595e057b --- /dev/null +++ b/crates/biome_cli/tests/snapshots/main_commands_migrate/prettier_migrate_yml_file.snap @@ -0,0 +1,69 @@ +--- +source: crates/biome_cli/tests/snap_test.rs +expression: content +--- +## `biome.json` + +```json +{ "linter": { "enabled": true } } +``` + +## `.prettierrc` + +```prettierrc +useTabs: true +``` + +# Termination Message + +```block +migrate ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Migration has encountered an error: Could not deserialize the Prettier configuration file + + + +``` + +# Emitted Messages + +```block +.prettierrc parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × String values must be double quoted. + + +``` + +```block +.prettierrc parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × End of file expected + + i Use an array for a sequence of values: `[1, 2]` + + +``` + +```block +.prettierrc parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × End of file expected + + i Use an array for a sequence of values: `[1, 2]` + + +``` + +```block +.prettierrc:1:1 deserialize ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Incorrect type, expected an object, but received an array. + + > 1 │ useTabs: true + │ ^^^^^^^^^^^^^ + + +``` + +