Skip to content

Commit

Permalink
bypass configuration diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Oct 7, 2024
1 parent 982aee5 commit 95b2409
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 40 deletions.
13 changes: 6 additions & 7 deletions crates/biome_cli/src/commands/check.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{determine_fix_file_mode, FixFileModeOptions, LoadEditorConfig};
use crate::cli_options::CliOptions;
use crate::commands::{get_files_to_process, CommandRunner};
use crate::commands::{get_files_to_process_with_cli_options, CommandRunner};
use crate::{CliDiagnostic, Execution, TraversalMode};
use biome_configuration::analyzer::assists::PartialAssistsConfiguration;
use biome_configuration::{
Expand Down Expand Up @@ -110,17 +110,16 @@ impl CommandRunner for CheckCommandPayload {
fs: &DynRef<'_, dyn FileSystem>,
configuration: &PartialConfiguration,
) -> Result<Vec<OsString>, CliDiagnostic> {
if let Some(paths) = get_files_to_process(
let paths = get_files_to_process_with_cli_options(
self.since.as_deref(),
self.changed,
self.staged,
fs,
configuration,
)? {
Ok(paths)
} else {
Ok(self.paths.clone())
}
)?
.unwrap_or(self.paths.clone());

Ok(paths)
}

fn get_stdin_file_path(&self) -> Option<&str> {
Expand Down
13 changes: 6 additions & 7 deletions crates/biome_cli/src/commands/format.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::cli_options::CliOptions;
use crate::commands::{get_files_to_process, CommandRunner, LoadEditorConfig};
use crate::commands::{get_files_to_process_with_cli_options, CommandRunner, LoadEditorConfig};
use crate::diagnostics::DeprecatedArgument;
use crate::{CliDiagnostic, Execution, TraversalMode};
use biome_configuration::vcs::PartialVcsConfiguration;
Expand Down Expand Up @@ -170,17 +170,16 @@ impl CommandRunner for FormatCommandPayload {
fs: &DynRef<'_, dyn FileSystem>,
configuration: &PartialConfiguration,
) -> Result<Vec<OsString>, CliDiagnostic> {
if let Some(paths) = get_files_to_process(
let paths = get_files_to_process_with_cli_options(
self.since.as_deref(),
self.changed,
self.staged,
fs,
configuration,
)? {
Ok(paths)
} else {
Ok(self.paths.clone())
}
)?
.unwrap_or(self.paths.clone());

Ok(paths)
}

fn get_stdin_file_path(&self) -> Option<&str> {
Expand Down
13 changes: 6 additions & 7 deletions crates/biome_cli/src/commands/lint.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{determine_fix_file_mode, FixFileModeOptions};
use crate::cli_options::CliOptions;
use crate::commands::{get_files_to_process, CommandRunner};
use crate::commands::{get_files_to_process_with_cli_options, CommandRunner};
use crate::{CliDiagnostic, Execution, TraversalMode};
use biome_configuration::analyzer::RuleSelector;
use biome_configuration::css::PartialCssLinter;
Expand Down Expand Up @@ -103,17 +103,16 @@ impl CommandRunner for LintCommandPayload {
fs: &DynRef<'_, dyn FileSystem>,
configuration: &PartialConfiguration,
) -> Result<Vec<OsString>, CliDiagnostic> {
if let Some(paths) = get_files_to_process(
let paths = get_files_to_process_with_cli_options(
self.since.as_deref(),
self.changed,
self.staged,
fs,
configuration,
)? {
Ok(paths)
} else {
Ok(self.paths.clone())
}
)?
.unwrap_or(self.paths.clone());

Ok(paths)
}

fn get_stdin_file_path(&self) -> Option<&str> {
Expand Down
4 changes: 4 additions & 0 deletions crates/biome_cli/src/commands/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,8 @@ impl CommandRunner for MigrateCommandPayload {
unsafe_: false,
})
}

fn should_validate_configuration_diagnostics(&self) -> bool {
false
}
}
20 changes: 17 additions & 3 deletions crates/biome_cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ impl BiomeCommand {

/// It accepts a [LoadedPartialConfiguration] and it prints the diagnostics emitted during parsing and deserialization.
///
/// If it contains errors, it return an error.
/// If it contains [errors](Severity::Error) or higher, it returns an error.
pub(crate) fn validate_configuration_diagnostics(
loaded_configuration: &LoadedConfiguration,
console: &mut dyn Console,
Expand Down Expand Up @@ -670,7 +670,7 @@ fn resolve_manifest(
Ok(None)
}

fn get_files_to_process(
fn get_files_to_process_with_cli_options(
since: Option<&str>,
changed: bool,
staged: bool,
Expand Down Expand Up @@ -825,7 +825,13 @@ pub(crate) trait CommandRunner: Sized {
) -> Result<(Execution, Vec<OsString>), CliDiagnostic> {
let loaded_configuration =
load_configuration(fs, cli_options.as_configuration_path_hint())?;
validate_configuration_diagnostics(&loaded_configuration, console, cli_options.verbose)?;
if self.should_validate_configuration_diagnostics() {
validate_configuration_diagnostics(
&loaded_configuration,
console,
cli_options.verbose,
)?;
}
let configuration_path = loaded_configuration.directory_path.clone();
let configuration = self.merge_configuration(loaded_configuration, fs, console)?;
let vcs_base_path = configuration_path.or(fs.working_directory());
Expand Down Expand Up @@ -915,10 +921,18 @@ pub(crate) trait CommandRunner: Sized {
fn check_incompatible_arguments(&self) -> Result<(), CliDiagnostic> {
Ok(())
}

/// Checks whether the configuration has errors.
fn should_validate_configuration_diagnostics(&self) -> bool {
true
}
}

pub trait LoadEditorConfig: CommandRunner {
/// Whether this command should load the `.editorconfig` file.
fn should_load_editor_config(&self, fs_configuration: &PartialConfiguration) -> bool;

/// It loads the `.editorconfig` from the file system, parses it and deserialize it into a [PartialConfiguration]
fn load_editor_config(
&self,
configuration_path: Option<PathBuf>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@ expression: content

# Emitted Messages

```block
rome.json internalError/fs ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! The configuration file rome.json is deprecated. Use biome.json instead.
```

```block
rome.json migrate ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@ expression: content

# Emitted Messages

```block
rome.json internalError/fs ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! The configuration file rome.json is deprecated. Use biome.json instead.
```

```block
The configuration rome.json has been successfully migrated.
```

0 comments on commit 95b2409

Please sign in to comment.