diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7978ef57ee4..3f22cfa317d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,11 @@
## [Unreleased]
### CLI
+
+#### Other changes
+- Add new command `rome migrate` the transform the configuration file `rome.json`
+when there are breaking changes.
+
### Configuration
### Editors
### Formatter
diff --git a/Cargo.lock b/Cargo.lock
index b5e184928e7..a113a247030 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1669,7 +1669,10 @@ dependencies = [
"rome_js_formatter",
"rome_json_formatter",
"rome_json_parser",
+ "rome_json_syntax",
"rome_lsp",
+ "rome_migrate",
+ "rome_rowan",
"rome_service",
"rome_text_edit",
"rome_text_size",
@@ -2039,6 +2042,18 @@ dependencies = [
"quote",
]
+[[package]]
+name = "rome_migrate"
+version = "0.1.0"
+dependencies = [
+ "lazy_static",
+ "rome_analyze",
+ "rome_diagnostics",
+ "rome_json_parser",
+ "rome_json_syntax",
+ "rome_rowan",
+]
+
[[package]]
name = "rome_parser"
version = "0.0.1"
diff --git a/Cargo.toml b/Cargo.toml
index 161307c8b3d..73294426f8d 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -32,3 +32,4 @@ countme = "3.0.1"
tokio = { version = "~1.18.5" }
insta = "1.21.2"
quote = { version = "1.0.21" }
+lazy_static = "1.4.0"
diff --git a/crates/rome_cli/Cargo.toml b/crates/rome_cli/Cargo.toml
index e371e4a55a8..8130a884ddc 100644
--- a/crates/rome_cli/Cargo.toml
+++ b/crates/rome_cli/Cargo.toml
@@ -26,7 +26,7 @@ tracing = { workspace = true }
tracing-tree = "0.2.2"
tracing-subscriber = { version = "0.3.16", features = ["env-filter"] }
tracing-appender = "0.2"
-lazy_static = "1.4.0"
+lazy_static = { workspace = true }
hdrhistogram = { version = "7.5.0", default-features = false }
crossbeam = "0.8.1"
rayon = "1.5.1"
@@ -36,6 +36,11 @@ tokio = { workspace = true, features = ["io-std", "io-util", "net", "time", "rt"
anyhow = "1.0.52"
dashmap = { workspace = true }
rome_text_size = { path = "../rome_text_size" }
+rome_json_parser = { path = "../rome_json_parser" }
+rome_json_formatter = { path = "../rome_json_formatter" }
+rome_json_syntax = { path = "../rome_json_syntax" }
+rome_migrate = { path = "../rome_migrate" }
+rome_rowan = { path = "../rome_rowan" }
[target.'cfg(unix)'.dependencies]
libc = "0.2.127"
diff --git a/crates/rome_cli/src/commands/check.rs b/crates/rome_cli/src/commands/check.rs
index 9cffd8f9b96..01cfa41205b 100644
--- a/crates/rome_cli/src/commands/check.rs
+++ b/crates/rome_cli/src/commands/check.rs
@@ -7,7 +7,7 @@ use rome_service::workspace::{FixFileMode, UpdateSettingsParams};
/// Handler for the "check" command of the Rome CLI
pub(crate) fn check(mut session: CliSession) -> Result<(), CliDiagnostic> {
- let (mut configuration, diagnostics) = load_configuration(&mut session)?.consume();
+ let (mut configuration, diagnostics, _) = load_configuration(&mut session)?.consume();
if !diagnostics.is_empty() {
let console = &mut session.app.console;
console.log(markup!{
diff --git a/crates/rome_cli/src/commands/ci.rs b/crates/rome_cli/src/commands/ci.rs
index 775fc63dc78..fcb4d9b5d66 100644
--- a/crates/rome_cli/src/commands/ci.rs
+++ b/crates/rome_cli/src/commands/ci.rs
@@ -11,7 +11,7 @@ use rome_service::workspace::UpdateSettingsParams;
/// Handler for the "ci" command of the Rome CLI
pub(crate) fn ci(mut session: CliSession) -> Result<(), CliDiagnostic> {
- let (mut configuration, diagnostics) = load_configuration(&mut session)?.consume();
+ let (mut configuration, diagnostics, _) = load_configuration(&mut session)?.consume();
if !diagnostics.is_empty() {
let console = &mut session.app.console;
diff --git a/crates/rome_cli/src/commands/format.rs b/crates/rome_cli/src/commands/format.rs
index f69719790a9..f467942d1bb 100644
--- a/crates/rome_cli/src/commands/format.rs
+++ b/crates/rome_cli/src/commands/format.rs
@@ -9,7 +9,7 @@ use std::path::PathBuf;
/// Handler for the "format" command of the Rome CLI
pub(crate) fn format(mut session: CliSession) -> Result<(), CliDiagnostic> {
- let (mut configuration, diagnostics) = load_configuration(&mut session)?.consume();
+ let (mut configuration, diagnostics, _) = load_configuration(&mut session)?.consume();
if !diagnostics.is_empty() {
let console = &mut session.app.console;
console.log(markup!{
diff --git a/crates/rome_cli/src/commands/help.rs b/crates/rome_cli/src/commands/help.rs
index ecaf3be0abb..55149021740 100644
--- a/crates/rome_cli/src/commands/help.rs
+++ b/crates/rome_cli/src/commands/help.rs
@@ -10,12 +10,13 @@ const MAIN: Markup = markup! {
- ""ci"" Run the linter and check the formatting of a set of files
- ""format"" Run the formatter on a set of files
- ""init"" Bootstraps a new rome project
- - ""start"" Start the Rome daemon server process
- - ""stop"" Stop the Rome daemon server process
+ - ""help"" Prints this help message
- ""lsp-proxy"" Acts as a server for the Language Server Protocol over stdin/stdout
+ - ""migrate"" It updates the configuration when there are breaking changes
- ""rage"" Prints information for debugging
+ - ""start"" Start the Rome daemon server process
+ - ""stop"" Stop the Rome daemon server process
- ""version"" Shows the Rome version information and quit
- - ""help"" Prints this help message
""OPTIONS:""
""--colors="" Set the formatting mode for markup: \"off\" prints everything as plain text, \"force\" forces the formatting of markup using ANSI even if the console output is determined to be incompatible
@@ -146,6 +147,18 @@ const VERSION_HELP_TEXT: Markup = markup! {
rome version"
};
+const MIGRATE: Markup = markup! {
+"Rome migrate: updates the configuration file to a newer version
+
+""EXAMPLES:""
+ rome migrate
+ rome migrate --write
+
+""OPTIONS:""
+ ""--write"" It writes the contents to disk
+"
+};
+
pub(crate) fn help(session: CliSession, command: Option<&str>) -> Result<(), CliDiagnostic> {
let help_text = match command {
Some("help") | None => MAIN,
@@ -158,6 +171,7 @@ pub(crate) fn help(session: CliSession, command: Option<&str>) -> Result<(), Cli
Some("lsp-proxy") => START_LSP_PROXY,
Some("version") => VERSION_HELP_TEXT,
Some("rage") => RAGE,
+ Some("migrate") => MIGRATE,
Some(cmd) => return Err(CliDiagnostic::new_unknown_help(cmd)),
};
diff --git a/crates/rome_cli/src/commands/migrate.rs b/crates/rome_cli/src/commands/migrate.rs
new file mode 100644
index 00000000000..df799dca695
--- /dev/null
+++ b/crates/rome_cli/src/commands/migrate.rs
@@ -0,0 +1,22 @@
+use crate::configuration::load_configuration;
+use crate::diagnostics::MigrationDiagnostic;
+use crate::execute::{execute_mode, Execution, TraversalMode};
+use crate::{CliDiagnostic, CliSession};
+
+/// Handler for the "check" command of the Rome CLI
+pub(crate) fn migrate(mut session: CliSession) -> Result<(), CliDiagnostic> {
+ let (_, _, path) = load_configuration(&mut session)?.consume();
+ if let Some(path) = path {
+ execute_mode(
+ Execution::new(TraversalMode::Migrate {
+ write: session.args.contains("--dry-run"),
+ configuration_path: path,
+ }),
+ session,
+ )
+ } else {
+ Err(CliDiagnostic::MigrateError(MigrationDiagnostic {
+ reason: "Rome couldn't find the configuration file".to_string(),
+ }))
+ }
+}
diff --git a/crates/rome_cli/src/commands/mod.rs b/crates/rome_cli/src/commands/mod.rs
index aa82c4cd87c..a489cb6edaa 100644
--- a/crates/rome_cli/src/commands/mod.rs
+++ b/crates/rome_cli/src/commands/mod.rs
@@ -4,5 +4,6 @@ pub(crate) mod daemon;
pub(crate) mod format;
pub(crate) mod help;
pub(crate) mod init;
+pub(crate) mod migrate;
pub(crate) mod rage;
pub(crate) mod version;
diff --git a/crates/rome_cli/src/commands/rage.rs b/crates/rome_cli/src/commands/rage.rs
index e5a25f94b6a..4bccfb0397b 100644
--- a/crates/rome_cli/src/commands/rage.rs
+++ b/crates/rome_cli/src/commands/rage.rs
@@ -166,6 +166,7 @@ impl Display for RageConfiguration<'_, '_> {
match load_config(self.0, ConfigurationBasePath::default()) {
Ok(None) => KeyValuePair("Status", markup!("unset")).fmt(fmt)?,
Ok(Some(deserialized)) => {
+ let (deserialized, _) = deserialized;
let (configuration, diagnostics) = deserialized.consume();
let status = if !diagnostics.is_empty() {
for diagnostic in diagnostics {
diff --git a/crates/rome_cli/src/configuration.rs b/crates/rome_cli/src/configuration.rs
index f2f63f84f96..352a68b77c9 100644
--- a/crates/rome_cli/src/configuration.rs
+++ b/crates/rome_cli/src/configuration.rs
@@ -4,11 +4,38 @@ use crate::{CliDiagnostic, CliSession};
use rome_deserialize::Deserialized;
use rome_service::{load_config, Configuration, ConfigurationBasePath};
+#[derive(Default)]
+pub struct LoadedConfiguration {
+ deserialized: Deserialized,
+ path: Option,
+}
+
+impl LoadedConfiguration {
+ pub fn consume(self) -> (Configuration, Vec, Option) {
+ let path = self.path;
+ let (configuration, diagnostics) = self.deserialized.consume();
+ (configuration, diagnostics, path)
+ }
+}
+
+impl From