Skip to content

Commit b61caa6

Browse files
ematipicoautofix-ci[bot]coderabbitai[bot]
authored andcommitted
fix(lint): improve noBiomeFirstException (biomejs#8326)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 5f3d98c commit b61caa6

File tree

47 files changed

+762
-231
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+762
-231
lines changed

.changeset/cruel-meals-talk.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
Improved the rule `noBiomeFirstException`. The rule can now inspect if extended configurations already contain the catch-all `**` inside `files.includes` and, if so, the rule suggests removing `**` from the user configuration.

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/biome_cli/src/commands/check.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ use biome_configuration::{Configuration, FormatterConfiguration, LinterConfigura
1111
use biome_console::Console;
1212
use biome_deserialize::Merge;
1313
use biome_fs::FileSystem;
14-
use biome_service::{Workspace, WorkspaceError, configuration::LoadedConfiguration};
14+
use biome_service::{Workspace, WorkspaceError};
15+
use camino::Utf8PathBuf;
1516
use std::ffi::OsString;
1617

1718
pub(crate) struct CheckCommandPayload {
@@ -47,17 +48,15 @@ impl CommandRunner for CheckCommandPayload {
4748

4849
fn merge_configuration(
4950
&mut self,
50-
loaded_configuration: LoadedConfiguration,
51+
loaded_configuration: Configuration,
52+
loaded_directory: Option<Utf8PathBuf>,
53+
_loaded_file: Option<Utf8PathBuf>,
54+
5155
fs: &dyn FileSystem,
5256
_console: &mut dyn Console,
5357
) -> Result<Configuration, WorkspaceError> {
54-
let LoadedConfiguration {
55-
configuration: biome_configuration,
56-
directory_path,
57-
..
58-
} = loaded_configuration;
5958
let mut configuration =
60-
self.combine_configuration(directory_path, biome_configuration, fs)?;
59+
self.combine_configuration(loaded_directory, loaded_configuration, fs)?;
6160

6261
let formatter = configuration
6362
.formatter

crates/biome_cli/src/commands/ci.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use biome_configuration::{
1313
use biome_console::Console;
1414
use biome_deserialize::Merge;
1515
use biome_fs::FileSystem;
16-
use biome_service::configuration::LoadedConfiguration;
1716
use biome_service::{Workspace, WorkspaceError};
17+
use camino::Utf8PathBuf;
1818
use std::ffi::OsString;
1919

2020
pub(crate) struct CiCommandPayload {
@@ -45,17 +45,15 @@ impl CommandRunner for CiCommandPayload {
4545

4646
fn merge_configuration(
4747
&mut self,
48-
loaded_configuration: LoadedConfiguration,
48+
loaded_configuration: Configuration,
49+
loaded_directory: Option<Utf8PathBuf>,
50+
_loaded_file: Option<Utf8PathBuf>,
51+
4952
fs: &dyn FileSystem,
5053
_console: &mut dyn Console,
5154
) -> Result<Configuration, WorkspaceError> {
52-
let LoadedConfiguration {
53-
configuration: biome_configuration,
54-
directory_path: configuration_path,
55-
..
56-
} = loaded_configuration;
5755
let mut configuration =
58-
self.combine_configuration(configuration_path, biome_configuration, fs)?;
56+
self.combine_configuration(loaded_directory, loaded_configuration, fs)?;
5957

6058
let formatter = configuration
6159
.formatter

crates/biome_cli/src/commands/format.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use biome_configuration::{Configuration, FilesConfiguration, FormatterConfigurat
1111
use biome_console::Console;
1212
use biome_deserialize::Merge;
1313
use biome_fs::FileSystem;
14-
use biome_service::configuration::LoadedConfiguration;
1514
use biome_service::{Workspace, WorkspaceError};
15+
use camino::Utf8PathBuf;
1616
use std::ffi::OsString;
1717

1818
pub(crate) struct FormatCommandPayload {
@@ -49,18 +49,15 @@ impl CommandRunner for FormatCommandPayload {
4949

5050
fn merge_configuration(
5151
&mut self,
52-
loaded_configuration: LoadedConfiguration,
52+
loaded_configuration: Configuration,
53+
loaded_directory: Option<Utf8PathBuf>,
54+
_loaded_file: Option<Utf8PathBuf>,
55+
5356
fs: &dyn FileSystem,
5457
_console: &mut dyn Console,
5558
) -> Result<Configuration, WorkspaceError> {
56-
let LoadedConfiguration {
57-
configuration: biome_configuration,
58-
directory_path: configuration_path,
59-
..
60-
} = loaded_configuration;
61-
6259
let mut configuration =
63-
self.combine_configuration(configuration_path, biome_configuration, fs)?;
60+
self.combine_configuration(loaded_directory, loaded_configuration, fs)?;
6461

6562
// merge formatter options
6663
if configuration

crates/biome_cli/src/commands/lint.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use biome_configuration::{Configuration, FilesConfiguration, LinterConfiguration
1212
use biome_console::Console;
1313
use biome_deserialize::Merge;
1414
use biome_fs::FileSystem;
15-
use biome_service::configuration::LoadedConfiguration;
1615
use biome_service::{Workspace, WorkspaceError};
16+
use camino::Utf8PathBuf;
1717
use std::ffi::OsString;
1818

1919
pub(crate) struct LintCommandPayload {
@@ -45,17 +45,14 @@ impl CommandRunner for LintCommandPayload {
4545

4646
fn merge_configuration(
4747
&mut self,
48-
loaded_configuration: LoadedConfiguration,
48+
mut loaded_configuration: Configuration,
49+
_loaded_directory: Option<Utf8PathBuf>,
50+
_loaded_file: Option<Utf8PathBuf>,
4951
_fs: &dyn FileSystem,
5052
_console: &mut dyn Console,
5153
) -> Result<Configuration, WorkspaceError> {
52-
let LoadedConfiguration {
53-
configuration: mut fs_configuration,
54-
..
55-
} = loaded_configuration;
56-
57-
fs_configuration.merge_with(Configuration {
58-
linter: if fs_configuration
54+
loaded_configuration.merge_with(Configuration {
55+
linter: if loaded_configuration
5956
.linter
6057
.as_ref()
6158
.is_some_and(LinterConfiguration::is_enabled)
@@ -73,7 +70,9 @@ impl CommandRunner for LintCommandPayload {
7370
..Default::default()
7471
});
7572

76-
let css = fs_configuration.css.get_or_insert_with(Default::default);
73+
let css = loaded_configuration
74+
.css
75+
.get_or_insert_with(Default::default);
7776
if self.css_linter.is_some() {
7877
css.linter.merge_with(self.css_linter.clone());
7978
}
@@ -82,26 +81,28 @@ impl CommandRunner for LintCommandPayload {
8281
}
8382

8483
if self.graphql_linter.is_some() {
85-
let graphql = fs_configuration
84+
let graphql = loaded_configuration
8685
.graphql
8786
.get_or_insert_with(Default::default);
8887
graphql.linter.merge_with(self.graphql_linter.clone());
8988
}
9089
if self.javascript_linter.is_some() {
91-
let javascript = fs_configuration
90+
let javascript = loaded_configuration
9291
.javascript
9392
.get_or_insert_with(Default::default);
9493
javascript.linter.merge_with(self.javascript_linter.clone());
9594
}
96-
let json = fs_configuration.json.get_or_insert_with(Default::default);
95+
let json = loaded_configuration
96+
.json
97+
.get_or_insert_with(Default::default);
9798
if self.json_linter.is_some() {
9899
json.linter.merge_with(self.json_linter.clone());
99100
}
100101
if self.json_parser.is_some() {
101102
json.parser.merge_with(self.json_parser.clone());
102103
}
103104

104-
Ok(fs_configuration)
105+
Ok(loaded_configuration)
105106
}
106107

107108
fn get_files_to_process(

crates/biome_cli/src/commands/migrate.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use crate::execute::{Execution, TraversalMode};
88
use biome_configuration::Configuration;
99
use biome_console::{Console, ConsoleExt, markup};
1010
use biome_fs::FileSystem;
11-
use biome_service::configuration::LoadedConfiguration;
1211
use biome_service::{Workspace, WorkspaceError};
1312
use camino::Utf8PathBuf;
1413
use std::ffi::OsString;
@@ -26,13 +25,15 @@ impl CommandRunner for MigrateCommandPayload {
2625

2726
fn merge_configuration(
2827
&mut self,
29-
loaded_configuration: LoadedConfiguration,
28+
loaded_configuration: Configuration,
29+
loaded_directory: Option<Utf8PathBuf>,
30+
loaded_file: Option<Utf8PathBuf>,
3031
_fs: &dyn FileSystem,
3132
_console: &mut dyn Console,
3233
) -> Result<Configuration, WorkspaceError> {
33-
self.configuration_file_path = loaded_configuration.file_path;
34-
self.configuration_directory_path = loaded_configuration.directory_path;
35-
Ok(loaded_configuration.configuration)
34+
self.configuration_file_path = loaded_file;
35+
self.configuration_directory_path = loaded_directory;
36+
Ok(loaded_configuration)
3637
}
3738

3839
fn get_files_to_process(

crates/biome_cli/src/commands/mod.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -955,14 +955,26 @@ pub(crate) trait CommandRunner: Sized {
955955
loaded_configuration.file_path,
956956
loaded_configuration.diagnostics.len(),
957957
);
958-
let configuration_dir_path = loaded_configuration.directory_path.clone();
958+
let LoadedConfiguration {
959+
extended_configurations,
960+
configuration,
961+
diagnostics: _,
962+
directory_path,
963+
file_path,
964+
} = loaded_configuration;
959965

960966
// Merge the FS configuration with the CLI arguments
961-
let configuration = self.merge_configuration(loaded_configuration, fs, console)?;
967+
let configuration = self.merge_configuration(
968+
configuration,
969+
directory_path.clone(),
970+
file_path,
971+
fs,
972+
console,
973+
)?;
962974

963975
let execution = self.get_execution(cli_options, console, workspace)?;
964976

965-
let root_configuration_dir = configuration_dir_path
977+
let root_configuration_dir = directory_path
966978
.clone()
967979
.unwrap_or_else(|| working_dir.clone());
968980
// Using `--config-path`, users can point to a (root) config file that
@@ -1003,6 +1015,10 @@ pub(crate) trait CommandRunner: Sized {
10031015
project_key: open_project_result.project_key,
10041016
workspace_directory: Some(BiomePath::new(project_dir)),
10051017
configuration,
1018+
extended_configurations: extended_configurations
1019+
.into_iter()
1020+
.map(|(path, config)| (BiomePath::from(path), config))
1021+
.collect(),
10061022
})?;
10071023
if self.should_validate_configuration_diagnostics() {
10081024
print_diagnostics_from_workspace_result(
@@ -1080,7 +1096,9 @@ pub(crate) trait CommandRunner: Sized {
10801096
/// The CLI arguments take precedence over the option configured in the configuration file.
10811097
fn merge_configuration(
10821098
&mut self,
1083-
loaded_configuration: LoadedConfiguration,
1099+
loaded_configuration: Configuration,
1100+
loaded_directory: Option<Utf8PathBuf>,
1101+
loaded_file: Option<Utf8PathBuf>,
10841102
fs: &dyn FileSystem,
10851103
console: &mut dyn Console,
10861104
) -> Result<Configuration, WorkspaceError>;

crates/biome_cli/src/commands/rage.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,16 @@ impl Display for RageConfiguration<'_> {
216216
diagnostics,
217217
directory_path,
218218
file_path,
219+
extended_configurations,
219220
} = loaded_configuration;
220221
let vcs_enabled = configuration.is_vcs_enabled();
221222
let mut settings = Settings::default();
222223
settings
223-
.merge_with_configuration(configuration.clone(), None)
224+
.merge_with_configuration(
225+
configuration.clone(),
226+
None,
227+
extended_configurations,
228+
)
224229
.unwrap();
225230

226231
let status = if !diagnostics.is_empty() {

crates/biome_cli/src/commands/search.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ use biome_console::Console;
77
use biome_deserialize::Merge;
88
use biome_fs::FileSystem;
99
use biome_grit_patterns::GritTargetLanguage;
10-
use biome_service::configuration::LoadedConfiguration;
1110
use biome_service::workspace::ParsePatternParams;
1211
use biome_service::{Workspace, WorkspaceError};
12+
use camino::Utf8PathBuf;
1313
use std::ffi::OsString;
1414

1515
pub(crate) struct SearchCommandPayload {
@@ -26,19 +26,20 @@ impl CommandRunner for SearchCommandPayload {
2626

2727
fn merge_configuration(
2828
&mut self,
29-
loaded_configuration: LoadedConfiguration,
29+
mut loaded_configuration: Configuration,
30+
_loaded_directory: Option<Utf8PathBuf>,
31+
_loaded_file: Option<Utf8PathBuf>,
3032
_fs: &dyn FileSystem,
3133
_console: &mut dyn Console,
3234
) -> Result<Configuration, WorkspaceError> {
33-
let LoadedConfiguration {
34-
mut configuration, ..
35-
} = loaded_configuration;
36-
configuration
35+
loaded_configuration
3736
.files
3837
.merge_with(self.files_configuration.clone());
39-
configuration.vcs.merge_with(self.vcs_configuration.clone());
38+
loaded_configuration
39+
.vcs
40+
.merge_with(self.vcs_configuration.clone());
4041

41-
Ok(configuration)
42+
Ok(loaded_configuration)
4243
}
4344

4445
fn get_files_to_process(

0 commit comments

Comments
 (0)