refactor(rome_service): remove `root` field from configuration
MODIFY
crates/rome_cli/src/commands/check.rs
crates/rome_cli/src/commands/check.rs
@@ -4,13 +4,13 @@ use crate::{
CliSession, Termination,
};
use rome_diagnostics::MAXIMUM_DISPLAYABLE_DIAGNOSTICS;
+use rome_service::load_config;
use rome_service::settings::WorkspaceSettings;
use rome_service::workspace::UpdateSettingsParams;
-use rome_service::{load_config, ConfigurationType};
/// Handler for the "check" command of the Rome CLI
pub(crate) fn check(mut session: CliSession) -> Result<(), Termination> {
- let configuration = load_config(&session.app.fs, ConfigurationType::Root)?;
+ let configuration = load_config(&session.app.fs)?;
let mut workspace_settings = WorkspaceSettings::default();
let max_diagnostics: Option<u8> = session

MODIFY
crates/rome_cli/src/commands/ci.rs
crates/rome_cli/src/commands/ci.rs
@@ -2,15 +2,15 @@ use crate::{
traversal::{traverse, TraversalMode},
CliSession, Termination,
};
+use rome_service::load_config;
use rome_service::settings::WorkspaceSettings;
use rome_service::workspace::UpdateSettingsParams;
-use rome_service::{load_config, ConfigurationType};
use super::format::apply_format_settings_from_cli;
/// Handler for the "ci" command of the Rome CLI
pub(crate) fn ci(mut session: CliSession) -> Result<(), Termination> {
- let configuration = load_config(&session.app.fs, ConfigurationType::Root)?;
+ let configuration = load_config(&session.app.fs)?;
let mut workspace_settings = WorkspaceSettings::default();
if let Some(configuration) = configuration {

MODIFY
crates/rome_cli/src/commands/format.rs
crates/rome_cli/src/commands/format.rs
use rome_formatter::IndentStyle;
-use rome_service::{
- load_config, settings::WorkspaceSettings, workspace::UpdateSettingsParams, ConfigurationType,
-};
+use rome_service::{load_config, settings::WorkspaceSettings, workspace::UpdateSettingsParams};
use crate::{
traversal::{traverse, TraversalMode},
@@ -10,7 +8,7 @@ use crate::{
/// Handler for the "format" command of the Rome CLI
pub(crate) fn format(mut session: CliSession) -> Result<(), Termination> {
- let configuration = load_config(&session.app.fs, ConfigurationType::Root)?;
+ let configuration = load_config(&session.app.fs)?;
let mut workspace_settings = WorkspaceSettings::default();
if let Some(configuration) = &configuration {

MODIFY
crates/rome_cli/tests/configs.rs
crates/rome_cli/tests/configs.rs
pub const CONFIG_FORMAT: &str = r#"{
- "root": true,
"formatter": {
"enabled": true,
"lineWidth": 160,
@@ -10,27 +9,19 @@ pub const CONFIG_FORMAT: &str = r#"{
"#;
pub const CONFIG_INIT_DEFAULT: &str = r#"{
- "root": true,
"linter": {
"enabled": true
}
}"#;
pub const CONFIG_DISABLED_FORMATTER: &str = r#"{
- "root": true,
"formatter": {
"enabled": false
}
}
"#;
-pub const CONFIG_ROOT_FALSE: &str = r#"{
- "root": false
-}
-"#;
-
pub const CONFIG_ALL_FIELDS: &str = r#"{
- "root": true,
"formatter": {
"enabled": true,
"formatWithErrors": true,
@@ -63,21 +54,18 @@ pub const CONFIG_ALL_FIELDS: &str = r#"{
}"#;
pub const CONFIG_BAD_LINE_WIDTH: &str = r#"{
- "root": true,
"formatter": {
"lineWidth": 500
}
}"#;
pub const CONFIG_LINTER_DISABLED: &str = r#"{
- "root": true,
"linter": {
"enabled": false
}
}"#;
pub const CONFIG_LINTER_WRONG_RULE: &str = r#"{
- "root": true,
"linter": {
"enabled": true,
"rules": {
@@ -92,7 +80,6 @@ pub const CONFIG_LINTER_WRONG_RULE: &str = r#"{
}"#;
pub const CONFIG_INCORRECT_GLOBALS: &str = r#"{
- "root": true,
"linter": {
"enabled": false
},

MODIFY
crates/rome_cli/tests/main.rs
crates/rome_cli/tests/main.rs
@@ -858,7 +858,7 @@ mod init {
mod configuration {
use crate::configs::{
CONFIG_ALL_FIELDS, CONFIG_BAD_LINE_WIDTH, CONFIG_INCORRECT_GLOBALS,
- CONFIG_LINTER_WRONG_RULE, CONFIG_ROOT_FALSE,
+ CONFIG_LINTER_WRONG_RULE,
};
use pico_args::Arguments;
use rome_cli::{run_cli, CliSession};
@@ -868,33 +868,6 @@ mod configuration {
use std::ffi::OsString;
use std::path::Path;
- #[test]
- fn incorrect_root() {
- let mut fs = MemoryFileSystem::default();
- let file_path = Path::new("rome.json");
- fs.insert(file_path.into(), CONFIG_ROOT_FALSE.as_bytes());
-
- let result = run_cli(CliSession {
- app: App::with_filesystem_and_console(
- DynRef::Borrowed(&mut fs),
- DynRef::Owned(Box::new(BufferConsole::default())),
- ),
- args: Arguments::from_vec(vec![OsString::from("format"), OsString::from("file.js")]),
- });
-
- assert!(result.is_err());
-
- match result {
- Err(error) => {
- assert_eq!(
- error.to_string(),
- "the main configuration file, rome.json, must have the field 'root' set to `true`"
- )
- }
- _ => panic!("expected an error, but found none"),
- }
- }
-
#[test]
fn correct_root() {
let mut fs = MemoryFileSystem::default();

MODIFY
crates/rome_lsp/src/server.rs
crates/rome_lsp/src/server.rs
@@ -3,7 +3,7 @@ use crate::requests::syntax_tree::{SyntaxTreePayload, SYNTAX_TREE_REQUEST};
use crate::session::Session;
use crate::utils::into_lsp_error;
use crate::{handlers, requests};
-use rome_service::{load_config, ConfigurationType};
+use rome_service::load_config;
use serde_json::Value;
use tokio::io::{Stdin, Stdout};
use tower_lsp::jsonrpc::Result as LspResult;
@@ -61,7 +61,7 @@ impl LanguageServer for LSPServer {
async fn initialized(&self, _: InitializedParams) {
info!("Attempting to load the configuration from 'rome.json' file");
- match load_config(&self.session.fs, ConfigurationType::Root) {
+ match load_config(&self.session.fs) {
Ok(Some(configuration)) => {
info!("Configuration found, and it is valid!");
self.session.configuration.write().replace(configuration);

MODIFY
crates/rome_service/src/configuration/mod.rs
crates/rome_service/src/configuration/mod.rs
@@ -23,11 +23,6 @@ pub use linter::{RuleConfiguration, Rules};
#[derive(Debug, Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
pub struct Configuration {
- /// One root file should exist. Useful when `extends` comes into play.
- ///
- /// If `true`, this file should be the master configuration.
- pub root: bool,
-
/// The configuration of the formatter
#[serde(skip_serializing_if = "Option::is_none")]
pub formatter: Option<FormatterConfiguration>,
@@ -45,7 +40,6 @@ impl Default for Configuration {
fn default() -> Self {
// TODO: enable recommendation settings https://github.com/rome/tools/issues/2912
Self {
- root: true,
linter: Some(LinterConfiguration {
enabled: true,
..LinterConfiguration::default()
@@ -68,8 +62,6 @@ impl Configuration {
/// Series of errors that can be thrown while computing the configuration
pub enum ConfigurationError {
- /// Thrown when the main configuration file doesn't have
- NotRoot,
/// Thrown when the program can't serialize the configuration, while saving it
SerializationError,
@@ -86,7 +78,6 @@ pub enum ConfigurationError {
impl Debug for ConfigurationError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
- ConfigurationError::NotRoot => std::fmt::Display::fmt(self, f),
ConfigurationError::SerializationError => std::fmt::Display::fmt(self, f),
ConfigurationError::DeserializationError(_) => std::fmt::Display::fmt(self, f),
@@ -98,12 +89,6 @@ impl Debug for ConfigurationError {
impl Display for ConfigurationError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
- ConfigurationError::NotRoot => {
- write!(
- f,
- "the main configuration file, rome.json, must have the field 'root' set to `true`"
- )
- }
ConfigurationError::SerializationError => {
write!(
f,
@@ -129,7 +114,6 @@ impl Display for ConfigurationError {
/// The `file_system` will read the configuration file
pub fn load_config(
file_system: &DynRef<dyn FileSystem>,
- configuration_type: ConfigurationType,
) -> Result<Option<Configuration>, RomeError> {
let config_name = file_system.config_name();
let configuration_path = PathBuf::from(config_name);
@@ -146,7 +130,7 @@ pub fn load_config(
RomeError::Configuration(ConfigurationError::DeserializationError(err.to_string()))
})?;
- compute_configuration(configuration, configuration_type)
+ Ok(Some(configuration))
}
Err(err) => {
// We throw an error only when the error is found.
@@ -192,33 +176,3 @@ pub fn create_config(
Ok(())
}
-
-/// The type of configuration we want to load
-pub enum ConfigurationType {
- /// The main configuration, usually `rome.json`
- Root,
- /// The extended configuration, usually to be loaded via `extends` field
- #[allow(unused_imports)]
- Extended,
-}
-
-impl ConfigurationType {
- fn is_root(&self) -> bool {
- matches!(self, ConfigurationType::Root)
- }
-}
-
-/// This function computes the configuration that is being loaded and makes sure that is correct.
-///
-/// Operations are:
-/// - making sure that the master configuration is set to `root: true`
-fn compute_configuration(
- configuration: Configuration,
- configuration_type: ConfigurationType,
-) -> Result<Option<Configuration>, RomeError> {
- if configuration_type.is_root() && !configuration.root {
- return Err(RomeError::Configuration(ConfigurationError::NotRoot));
- }
-
- Ok(Some(configuration))
-}

MODIFY
crates/rome_service/src/lib.rs
crates/rome_service/src/lib.rs
@@ -13,8 +13,7 @@ pub mod settings;
pub mod workspace;
pub use crate::configuration::{
- create_config, load_config, Configuration, ConfigurationError, ConfigurationType,
- RuleConfiguration, Rules,
+ create_config, load_config, Configuration, ConfigurationError, RuleConfiguration, Rules,
};
pub use crate::file_handlers::JsFormatSettings;
pub use crate::workspace::Workspace;

refactor(rome_service): remove `root` field from configuration (#2927)