Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
chore: apply path file only at the end
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Jun 19, 2023
1 parent 036590e commit 1fd1df2
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 34 deletions.
9 changes: 7 additions & 2 deletions crates/rome_cli/src/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -57,14 +57,19 @@ 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;
console.log(markup!{
<Error>"Found errors in the configuration file, Rome will use its defaults for the sections that are incorrect."</Error>
});
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) }}
})
Expand Down
12 changes: 10 additions & 2 deletions crates/rome_cli/src/commands/ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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!{
<Error>"Found errors in the configuration file, Rome will use its defaults for the sections that are incorrect."</Error>
});
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) }}
})
Expand Down
9 changes: 7 additions & 2 deletions crates/rome_cli/src/commands/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!{
<Warn>"Found errors in the configuration file, Rome will use its defaults for the sections that are incorrect."</Warn>
<Error>"Found errors in the configuration file, Rome will use its defaults for the sections that are incorrect."</Error>
});
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)}
Expand Down
8 changes: 1 addition & 7 deletions crates/rome_cli/src/execute/process_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion crates/rome_cli/tests/main.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
15 changes: 1 addition & 14 deletions crates/rome_deserialize/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -44,17 +44,4 @@ impl<P> Deserialized<P> {
pub fn consume(self) -> (P, Vec<Error>) {
(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(),
}
}
}
2 changes: 1 addition & 1 deletion crates/rome_service/src/configuration/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ mod test {

#[test]
fn diagnostic_size() {
assert_eq!(std::mem::size_of::<ConfigurationDiagnostic>(), 88);
assert_eq!(std::mem::size_of::<ConfigurationDiagnostic>(), 104);
}

#[test]
Expand Down
4 changes: 1 addition & 3 deletions crates/rome_service/src/configuration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand All @@ -344,8 +343,7 @@ pub fn load_config(
directory_path,
file_path,
} = auto_search_result;
let deserialized = deserialize_from_json_str::<Configuration>(&content)
.with_file_path(&configuration_file_path.display().to_string());
let deserialized = deserialize_from_json_str::<Configuration>(&content);
Ok(Some(ConfigurationPayload {
deserialized,
configuration_file_path: file_path,
Expand Down
2 changes: 1 addition & 1 deletion crates/rome_service/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ mod test {

#[test]
fn diagnostic_size() {
assert_eq!(std::mem::size_of::<WorkspaceError>(), 88)
assert_eq!(std::mem::size_of::<WorkspaceError>(), 104)
}

#[test]
Expand Down
4 changes: 4 additions & 0 deletions editors/vscode/configuration_schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion npm/backend-jsonrpc/src/workspace.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions npm/rome/configuration_schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1fd1df2

Please sign in to comment.