Skip to content

Commit 565976a

Browse files
ruidosujeiraautofix-ci[bot]
authored andcommitted
fix(config): inherit enabled state from global config in overrides (biomejs#8436)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent c4f0bb9 commit 565976a

File tree

3 files changed

+81
-4
lines changed

3 files changed

+81
-4
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
Fixed [#8429](https://github.com/biomejs/biome/issues/8429). Formatter, linter, and assist settings now correctly inherit from global configuration when not explicitly specified in overrides.
6+
7+
Before this fix, when an override specified only one feature (e.g., only `linter`), other features would be incorrectly disabled instead of inheriting from global settings.
8+
9+
Example configuration that now works correctly:
10+
```json
11+
{
12+
"formatter": { "enabled": true },
13+
"overrides": [{
14+
"includes": ["*.vue"],
15+
"linter": { "enabled": false }
16+
}]
17+
}
18+
```
19+
20+
After this fix, `.vue` files will have the linter disabled (as specified in the override) but the formatter enabled (inherited from global settings).

crates/biome_service/src/settings.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1750,7 +1750,7 @@ pub fn to_override_settings(
17501750
let formatter = pattern
17511751
.formatter
17521752
.map(|formatter| OverrideFormatSettings {
1753-
enabled: formatter.enabled,
1753+
enabled: formatter.enabled.or(current_settings.formatter.enabled),
17541754
format_with_errors: formatter
17551755
.format_with_errors
17561756
.or(current_settings.formatter.format_with_errors),
@@ -1767,15 +1767,15 @@ pub fn to_override_settings(
17671767
let linter = pattern
17681768
.linter
17691769
.map(|linter| OverrideLinterSettings {
1770-
enabled: linter.enabled,
1770+
enabled: linter.enabled.or(current_settings.linter.enabled),
17711771
rules: linter.rules,
17721772
domains: linter.domains,
17731773
})
17741774
.unwrap_or_default();
17751775
let assist = pattern
17761776
.assist
17771777
.map(|assist| OverrideAssistSettings {
1778-
enabled: assist.enabled,
1778+
enabled: assist.enabled.or(current_settings.assist.enabled),
17791779
actions: assist.actions,
17801780
})
17811781
.unwrap_or_default();

crates/biome_service/src/settings.tests.rs

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use biome_configuration::javascript::JsxRuntime;
66
use biome_configuration::json::{JsonAssistConfiguration, JsonLinterConfiguration};
77
use biome_configuration::max_size::MaxSize;
88
use biome_configuration::{
9-
Configuration, JsConfiguration, JsonConfiguration, LinterConfiguration,
9+
Configuration, FormatterConfiguration, JsConfiguration, JsonConfiguration, LinterConfiguration,
1010
OverrideFilesConfiguration, OverrideGlobs, OverrideLinterConfiguration, OverridePattern,
1111
Overrides, RuleConfiguration, RulePlainConfiguration, Rules,
1212
};
@@ -174,3 +174,60 @@ fn json_to_settings_includes_linter_and_assist() {
174174
assert_eq!(settings.linter.enabled, Some(true.into()));
175175
assert_eq!(settings.assist.enabled, Some(true.into()));
176176
}
177+
178+
#[test]
179+
fn override_inherits_global_formatter_when_not_specified() {
180+
// the formatter should inherit from global settings instead of being disabled
181+
let configuration = Configuration {
182+
formatter: Some(FormatterConfiguration {
183+
enabled: Some(true.into()),
184+
..FormatterConfiguration::default()
185+
}),
186+
linter: Some(LinterConfiguration {
187+
enabled: Some(true.into()),
188+
..LinterConfiguration::default()
189+
}),
190+
overrides: Some(Overrides(vec![OverridePattern {
191+
includes: Some(OverrideGlobs::Globs(Box::new([
192+
biome_glob::NormalizedGlob::from_str("*.vue").unwrap(),
193+
]))),
194+
// Override only specifies linter, not formatter
195+
linter: Some(OverrideLinterConfiguration {
196+
enabled: Some(false.into()),
197+
..OverrideLinterConfiguration::default()
198+
}),
199+
..OverridePattern::default()
200+
}])),
201+
..Default::default()
202+
};
203+
204+
let mut settings = Settings::default();
205+
settings
206+
.merge_with_configuration(configuration, None, vec![])
207+
.expect("valid configuration");
208+
209+
// For .vue files, linter should be disabled (from override)
210+
let linter_enabled =
211+
JsLanguage::linter_enabled_for_file_path(&settings, Utf8Path::new("test.vue"));
212+
assert!(!linter_enabled, "Linter should be disabled for .vue files");
213+
214+
// For .vue files, formatter should be enabled (inherited from global)
215+
let formatter_enabled =
216+
JsLanguage::formatter_enabled_for_file_path(&settings, Utf8Path::new("test.vue"));
217+
assert!(
218+
formatter_enabled,
219+
"Formatter should be enabled for .vue files (inherited from global)"
220+
);
221+
222+
// For non .vue files, both should be enabled (from global)
223+
let linter_enabled_js =
224+
JsLanguage::linter_enabled_for_file_path(&settings, Utf8Path::new("test.js"));
225+
assert!(linter_enabled_js, "Linter should be enabled for .js files");
226+
227+
let formatter_enabled_js =
228+
JsLanguage::formatter_enabled_for_file_path(&settings, Utf8Path::new("test.js"));
229+
assert!(
230+
formatter_enabled_js,
231+
"Formatter should be enabled for .js files"
232+
);
233+
}

0 commit comments

Comments
 (0)