From 1fd1df2c7486363cd5a3b1b46fae5bce61734129 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Mon, 19 Jun 2023 08:43:32 +0100 Subject: [PATCH] chore: apply path file only at the end --- crates/rome_cli/src/commands/check.rs | 9 +++++++-- crates/rome_cli/src/commands/ci.rs | 12 ++++++++++-- crates/rome_cli/src/commands/format.rs | 9 +++++++-- crates/rome_cli/src/execute/process_file.rs | 8 +------- crates/rome_cli/tests/main.rs | 2 +- crates/rome_deserialize/src/lib.rs | 15 +-------------- .../rome_service/src/configuration/diagnostics.rs | 2 +- crates/rome_service/src/configuration/mod.rs | 4 +--- crates/rome_service/src/diagnostics.rs | 2 +- editors/vscode/configuration_schema.json | 4 ++++ npm/backend-jsonrpc/src/workspace.ts | 6 +++++- npm/rome/configuration_schema.json | 4 ++++ 12 files changed, 43 insertions(+), 34 deletions(-) diff --git a/crates/rome_cli/src/commands/check.rs b/crates/rome_cli/src/commands/check.rs index 0abcb816604..467cb4c6858 100644 --- a/crates/rome_cli/src/commands/check.rs +++ b/crates/rome_cli/src/commands/check.rs @@ -3,7 +3,7 @@ use crate::configuration::{load_configuration, LoadedConfiguration}; use crate::vcs::store_path_to_ignore_from_vcs; use crate::{execute_mode, CliDiagnostic, CliSession, Execution, TraversalMode}; use rome_console::{markup, ConsoleExt}; -use rome_diagnostics::{PrintDiagnostic, Severity}; +use rome_diagnostics::{DiagnosticExt, PrintDiagnostic}; use rome_service::configuration::organize_imports::OrganizeImports; use rome_service::configuration::{FormatterConfiguration, LinterConfiguration}; use rome_service::workspace::{FixFileMode, UpdateSettingsParams}; @@ -57,7 +57,7 @@ pub(crate) fn check( configuration: mut fs_configuration, diagnostics, directory_path: configuration_path, - .. + file_path, } = load_configuration(&mut session, &cli_options)?; if !diagnostics.is_empty() { let console = &mut session.app.console; @@ -65,6 +65,11 @@ pub(crate) fn check( "Found errors in the configuration file, Rome will use its defaults for the sections that are incorrect." }); for diagnostic in diagnostics { + let diagnostic = if let Some(file_path) = &file_path { + diagnostic.with_file_path(file_path.display().to_string()) + } else { + diagnostic + }; console.error(markup! { {if cli_options.verbose { PrintDiagnostic::verbose(&diagnostic) } else { PrintDiagnostic::simple(&diagnostic) }} }) diff --git a/crates/rome_cli/src/commands/ci.rs b/crates/rome_cli/src/commands/ci.rs index 4ab1a5a1c04..860aaf8c3c2 100644 --- a/crates/rome_cli/src/commands/ci.rs +++ b/crates/rome_cli/src/commands/ci.rs @@ -6,7 +6,7 @@ use crate::{ TraversalMode, }; use rome_console::{markup, ConsoleExt}; -use rome_diagnostics::PrintDiagnostic; +use rome_diagnostics::{DiagnosticExt, PrintDiagnostic}; use rome_service::configuration::organize_imports::OrganizeImports; use rome_service::configuration::{FormatterConfiguration, LinterConfiguration}; use rome_service::workspace::UpdateSettingsParams; @@ -28,12 +28,20 @@ pub(crate) fn ci(mut session: CliSession, payload: CiCommandPayload) -> Result<( mut configuration, diagnostics, directory_path: configuration_path, - .. + file_path, } = load_configuration(&mut session, &payload.cli_options)?; if !diagnostics.is_empty() { let console = &mut session.app.console; + console.log(markup!{ + "Found errors in the configuration file, Rome will use its defaults for the sections that are incorrect." + }); for diagnostic in diagnostics { + let diagnostic = if let Some(file_path) = &file_path { + diagnostic.with_file_path(file_path.display().to_string()) + } else { + diagnostic + }; console.error(markup! { {if payload.cli_options.verbose { PrintDiagnostic::verbose(&diagnostic) } else { PrintDiagnostic::simple(&diagnostic) }} }) diff --git a/crates/rome_cli/src/commands/format.rs b/crates/rome_cli/src/commands/format.rs index 3c8973a762d..863b6ca1601 100644 --- a/crates/rome_cli/src/commands/format.rs +++ b/crates/rome_cli/src/commands/format.rs @@ -42,14 +42,19 @@ pub(crate) fn format( mut configuration, diagnostics, directory_path: configuration_path, - .. + file_path, } = load_configuration(&mut session, &cli_options)?; if !diagnostics.is_empty() { let console = &mut session.app.console; console.log(markup!{ - "Found errors in the configuration file, Rome will use its defaults for the sections that are incorrect." + "Found errors in the configuration file, Rome will use its defaults for the sections that are incorrect." }); for diagnostic in diagnostics { + let diagnostic = if let Some(file_path) = &file_path { + diagnostic.with_file_path(file_path.display().to_string()) + } else { + diagnostic + }; let diagnostic = diagnostic.with_severity(Severity::Warning); console.log(markup! { {PrintDiagnostic::verbose(&diagnostic)} diff --git a/crates/rome_cli/src/execute/process_file.rs b/crates/rome_cli/src/execute/process_file.rs index 09204789832..8ba23fcb3f1 100644 --- a/crates/rome_cli/src/execute/process_file.rs +++ b/crates/rome_cli/src/execute/process_file.rs @@ -330,13 +330,7 @@ pub(crate) fn process_file(ctx: &TraversalOptions, path: &Path) -> FileResult { let should_write = match ctx.execution.traversal_mode() { // In check mode do not run the formatter and return the result immediately, // but only if the argument `--apply` is not passed. - TraversalMode::Check { .. } => { - if ctx.execution.as_fix_file_mode().is_some() { - true - } else { - false - } - } + TraversalMode::Check { .. } => ctx.execution.as_fix_file_mode().is_some(), TraversalMode::CI { .. } => false, TraversalMode::Format { write, .. } => *write, TraversalMode::Migrate { write: dry_run, .. } => *dry_run, diff --git a/crates/rome_cli/tests/main.rs b/crates/rome_cli/tests/main.rs index 15875b8286e..a981854be5a 100644 --- a/crates/rome_cli/tests/main.rs +++ b/crates/rome_cli/tests/main.rs @@ -1,8 +1,8 @@ +mod cases; mod commands; mod configs; #[cfg(test)] mod snap_test; -mod cases; #[cfg(test)] use snap_test::assert_cli_snapshot; diff --git a/crates/rome_deserialize/src/lib.rs b/crates/rome_deserialize/src/lib.rs index 8466eabe098..1765f3706d2 100644 --- a/crates/rome_deserialize/src/lib.rs +++ b/crates/rome_deserialize/src/lib.rs @@ -3,7 +3,7 @@ mod visitor; pub mod json; pub use diagnostics::{DeserializationAdvice, DeserializationDiagnostic}; -use rome_diagnostics::{DiagnosticExt, Error}; +use rome_diagnostics::Error; pub use visitor::VisitNode; /// A small type to interrogate the result of a JSON deserialization @@ -44,17 +44,4 @@ impl

Deserialized

{ pub fn consume(self) -> (P, Vec) { (self.deserialized, self.diagnostics) } - - /// It inject the file path to the current diagnostics - pub fn with_file_path(self, path: &str) -> Self { - let (deserialized, diagnostics) = self.consume(); - - Deserialized { - deserialized, - diagnostics: diagnostics - .into_iter() - .map(|diagnostic| diagnostic.with_file_path(path)) - .collect(), - } - } } diff --git a/crates/rome_service/src/configuration/diagnostics.rs b/crates/rome_service/src/configuration/diagnostics.rs index dd561240d89..762d29a5469 100644 --- a/crates/rome_service/src/configuration/diagnostics.rs +++ b/crates/rome_service/src/configuration/diagnostics.rs @@ -274,7 +274,7 @@ mod test { #[test] fn diagnostic_size() { - assert_eq!(std::mem::size_of::(), 88); + assert_eq!(std::mem::size_of::(), 104); } #[test] diff --git a/crates/rome_service/src/configuration/mod.rs b/crates/rome_service/src/configuration/mod.rs index e213bf23a80..c6fe15b32e3 100644 --- a/crates/rome_service/src/configuration/mod.rs +++ b/crates/rome_service/src/configuration/mod.rs @@ -333,7 +333,6 @@ pub fn load_config( None => PathBuf::new(), }, }; - let configuration_file_path = configuration_directory.join(config_name); let should_error = base_path.is_from_user(); let result = file_system.auto_search(configuration_directory, config_name, should_error)?; @@ -344,8 +343,7 @@ pub fn load_config( directory_path, file_path, } = auto_search_result; - let deserialized = deserialize_from_json_str::(&content) - .with_file_path(&configuration_file_path.display().to_string()); + let deserialized = deserialize_from_json_str::(&content); Ok(Some(ConfigurationPayload { deserialized, configuration_file_path: file_path, diff --git a/crates/rome_service/src/diagnostics.rs b/crates/rome_service/src/diagnostics.rs index 9c7913b5ddf..754aa3b568b 100644 --- a/crates/rome_service/src/diagnostics.rs +++ b/crates/rome_service/src/diagnostics.rs @@ -547,7 +547,7 @@ mod test { #[test] fn diagnostic_size() { - assert_eq!(std::mem::size_of::(), 88) + assert_eq!(std::mem::size_of::(), 104) } #[test] diff --git a/editors/vscode/configuration_schema.json b/editors/vscode/configuration_schema.json index 3e80ffe513d..37472844498 100644 --- a/editors/vscode/configuration_schema.json +++ b/editors/vscode/configuration_schema.json @@ -8,6 +8,10 @@ "description": "A field for the [JSON schema](https://json-schema.org/) specification", "type": ["string", "null"] }, + "extends": { + "description": "A list of paths to other JSON files, used to extends the current configuration.", + "anyOf": [{ "$ref": "#/definitions/StringSet" }, { "type": "null" }] + }, "files": { "description": "The configuration of the filesystem", "anyOf": [ diff --git a/npm/backend-jsonrpc/src/workspace.ts b/npm/backend-jsonrpc/src/workspace.ts index b87109beb67..2b95c14382a 100644 --- a/npm/backend-jsonrpc/src/workspace.ts +++ b/npm/backend-jsonrpc/src/workspace.ts @@ -27,6 +27,10 @@ export interface Configuration { * A field for the [JSON schema](https://json-schema.org/) specification */ $schema?: string; + /** + * A list of paths to other JSON files, used to extends the current configuration. + */ + extends?: StringSet; /** * The configuration of the filesystem */ @@ -52,6 +56,7 @@ export interface Configuration { */ vcs?: VcsConfiguration; } +export type StringSet = string[]; /** * The configuration of the filesystem */ @@ -153,7 +158,6 @@ If Rome can't find the configuration, it will attempt to use the current working */ useIgnoreFile?: boolean; } -export type StringSet = string[]; export type PlainIndentStyle = "tab" | "space"; /** * Validated value for the `line_width` formatter options diff --git a/npm/rome/configuration_schema.json b/npm/rome/configuration_schema.json index 3e80ffe513d..37472844498 100644 --- a/npm/rome/configuration_schema.json +++ b/npm/rome/configuration_schema.json @@ -8,6 +8,10 @@ "description": "A field for the [JSON schema](https://json-schema.org/) specification", "type": ["string", "null"] }, + "extends": { + "description": "A list of paths to other JSON files, used to extends the current configuration.", + "anyOf": [{ "$ref": "#/definitions/StringSet" }, { "type": "null" }] + }, "files": { "description": "The configuration of the filesystem", "anyOf": [