Skip to content

Commit

Permalink
feat: foudations for migration from prettier (biomejs#1545)
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Jan 24, 2024
1 parent b20f0a4 commit 34c919a
Show file tree
Hide file tree
Showing 9 changed files with 521 additions and 24 deletions.
1 change: 1 addition & 0 deletions crates/biome_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ biome_diagnostics = { workspace = true }
biome_flags = { workspace = true }
biome_formatter = { workspace = true }
biome_fs = { workspace = true }
biome_js_formatter = { workspace = true }
biome_json_formatter = { workspace = true }
biome_json_parser = { workspace = true }
biome_json_syntax = { workspace = true }
Expand Down
2 changes: 2 additions & 0 deletions crates/biome_cli/src/commands/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub(crate) fn migrate(
session: CliSession,
cli_options: CliOptions,
write: bool,
prettier: bool,
) -> Result<(), CliDiagnostic> {
let base_path = match cli_options.config_path.as_ref() {
None => ConfigurationBasePath::default(),
Expand All @@ -30,6 +31,7 @@ pub(crate) fn migrate(
write,
configuration_file_path: path,
configuration_directory_path: directory_path,
prettier,
}),
session,
&cli_options,
Expand Down
25 changes: 16 additions & 9 deletions crates/biome_cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,19 @@ pub enum BiomeCommand {
),
/// It updates the configuration when there are breaking changes
#[bpaf(command)]
Migrate(
#[bpaf(external(cli_options), hide_usage)] CliOptions,
Migrate {
/// It attempts to find the files `.prettierrc`/`prettier.json` and `.prettierignore`, and map
/// Prettier's configuration into `biome.json`
#[bpaf(long("prettier"), switch, hide, hide_usage)]
prettier: bool,

#[bpaf(external, hide_usage)]
cli_options: CliOptions,

/// Writes the new configuration file to disk
#[bpaf(long("write"), switch)]
bool,
),
write: bool,
},

/// A command to retrieve the documentation of various aspects of the CLI.
///
Expand Down Expand Up @@ -294,7 +301,7 @@ impl BiomeCommand {
| BiomeCommand::Lint { cli_options, .. }
| BiomeCommand::Ci { cli_options, .. }
| BiomeCommand::Format { cli_options, .. }
| BiomeCommand::Migrate(cli_options, _) => cli_options.colors.as_ref(),
| BiomeCommand::Migrate { cli_options, .. } => cli_options.colors.as_ref(),
BiomeCommand::LspProxy(_)
| BiomeCommand::Start(_)
| BiomeCommand::Stop
Expand All @@ -313,7 +320,7 @@ impl BiomeCommand {
| BiomeCommand::Lint { cli_options, .. }
| BiomeCommand::Ci { cli_options, .. }
| BiomeCommand::Format { cli_options, .. }
| BiomeCommand::Migrate(cli_options, _) => cli_options.use_server,
| BiomeCommand::Migrate { cli_options, .. } => cli_options.use_server,
BiomeCommand::Init
| BiomeCommand::Start(_)
| BiomeCommand::Stop
Expand All @@ -334,7 +341,7 @@ impl BiomeCommand {
| BiomeCommand::Lint { cli_options, .. }
| BiomeCommand::Format { cli_options, .. }
| BiomeCommand::Ci { cli_options, .. }
| BiomeCommand::Migrate(cli_options, _) => cli_options.verbose,
| BiomeCommand::Migrate { cli_options, .. } => cli_options.verbose,
BiomeCommand::Version(_)
| BiomeCommand::Rage(..)
| BiomeCommand::Start(_)
Expand All @@ -353,7 +360,7 @@ impl BiomeCommand {
| BiomeCommand::Lint { cli_options, .. }
| BiomeCommand::Format { cli_options, .. }
| BiomeCommand::Ci { cli_options, .. }
| BiomeCommand::Migrate(cli_options, _) => cli_options.log_level.clone(),
| BiomeCommand::Migrate { cli_options, .. } => cli_options.log_level.clone(),
BiomeCommand::Version(_)
| BiomeCommand::LspProxy(_)
| BiomeCommand::Rage(..)
Expand All @@ -371,7 +378,7 @@ impl BiomeCommand {
| BiomeCommand::Lint { cli_options, .. }
| BiomeCommand::Format { cli_options, .. }
| BiomeCommand::Ci { cli_options, .. }
| BiomeCommand::Migrate(cli_options, _) => cli_options.log_kind.clone(),
| BiomeCommand::Migrate { cli_options, .. } => cli_options.log_kind.clone(),
BiomeCommand::Version(_)
| BiomeCommand::Rage(..)
| BiomeCommand::LspProxy(_)
Expand Down
29 changes: 22 additions & 7 deletions crates/biome_cli/src/execute/migrate.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
mod prettier;

use crate::execute::diagnostics::{ContentDiffAdvice, MigrateDiffDiagnostic};
use crate::{CliDiagnostic, CliSession};
use biome_console::{markup, ConsoleExt};
Expand All @@ -14,13 +16,26 @@ use std::borrow::Cow;
use std::ffi::OsStr;
use std::path::PathBuf;

pub(crate) fn run(
session: CliSession,
write: bool,
configuration_file_path: PathBuf,
configuration_directory_path: PathBuf,
verbose: bool,
) -> Result<(), CliDiagnostic> {
pub(crate) struct MigratePayload<'a> {
pub(crate) session: CliSession<'a>,
pub(crate) write: bool,
pub(crate) configuration_file_path: PathBuf,
pub(crate) configuration_directory_path: PathBuf,
pub(crate) verbose: bool,
#[allow(unused)]
pub(crate) prettier: bool,
}

pub(crate) fn run(migrate_payload: MigratePayload) -> Result<(), CliDiagnostic> {
let MigratePayload {
session,
write,
configuration_file_path,
configuration_directory_path,
verbose,
// we will use it later
prettier: _,
} = migrate_payload;
let fs = &*session.app.fs;
let has_deprecated_configuration =
configuration_file_path.file_name() == Some(OsStr::new("rome.json"));
Expand Down
Loading

0 comments on commit 34c919a

Please sign in to comment.