From d7127860e6fc09060c514d43eb7eac5bc3301f01 Mon Sep 17 00:00:00 2001 From: Moritz Wirger Date: Wed, 2 Sep 2026 12:36:41 +0200 Subject: [PATCH 1/2] Make disabling formatting explicit --- src/config.rs | 25 ++++++++++++++++++++----- src/formatting/tests.rs | 5 +++++ 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/config.rs b/src/config.rs index 6d2dbb5e3..7d7e00ff3 100644 --- a/src/config.rs +++ b/src/config.rs @@ -318,6 +318,8 @@ impl DiagnosticsConfig { #[derive(Debug, Clone, Default, Deserialize)] #[serde(default)] pub struct FormattingConfig { + /// Explicitly disable all formatting + pub disabled: Option, /// Command (path or name) to run php-cs-fixer. /// /// - `None` (default) — check `require-dev` in `composer.json`; @@ -379,12 +381,9 @@ impl FormattingConfig { self.timeout.unwrap_or(10_000) } - /// Whether formatting is entirely disabled (every tool explicitly - /// set to an empty string). + /// Whether formatting is explicitly disabled pub fn is_disabled(&self) -> bool { - crate::formatting::Tool::ALL - .into_iter() - .all(|tool| tool.configured(self) == Some("")) + self.disabled == Some(true) } } @@ -1542,6 +1541,22 @@ paths = ["database/schema", "extra/schema.sql"] assert_eq!(config.formatting.php_cs_fixer.as_deref(), Some("")); assert_eq!(config.formatting.phpcbf.as_deref(), Some("")); assert_eq!(config.formatting.pint.as_deref(), Some("")); + assert!(!config.formatting.is_disabled()); + } + + #[test] + fn formatting_disabled_disables_tool() { + let dir = tempfile::tempdir().unwrap(); + let path = dir.path().join(CONFIG_FILE_NAME); + std::fs::write( + &path, + "[formatting]\ndisabled = true\nphp-cs-fixer = \"\"\nphpcbf = \"\"\npint = \"\"\n", + ) + .unwrap(); + let config = load_config(dir.path()).unwrap(); + assert_eq!(config.formatting.php_cs_fixer.as_deref(), Some("")); + assert_eq!(config.formatting.phpcbf.as_deref(), Some("")); + assert_eq!(config.formatting.pint.as_deref(), Some("")); assert!(config.formatting.is_disabled()); } diff --git a/src/formatting/tests.rs b/src/formatting/tests.rs index 410c8dd84..99809fcdb 100644 --- a/src/formatting/tests.rs +++ b/src/formatting/tests.rs @@ -130,6 +130,7 @@ fn malformed_mago_toml_returns_error_not_panic() { #[test] fn strategy_both_disabled() { let config = FormattingConfig { + disabled: Some(false), pint: Some(String::new()), php_cs_fixer: Some(String::new()), phpcbf: Some(String::new()), @@ -144,6 +145,7 @@ fn strategy_both_disabled() { #[test] fn strategy_explicit_commands() { let config = FormattingConfig { + disabled: Some(false), pint: None, php_cs_fixer: Some("/usr/bin/php-cs-fixer".to_string()), phpcbf: Some("/usr/bin/phpcbf".to_string()), @@ -167,6 +169,7 @@ fn strategy_explicit_commands() { #[test] fn strategy_one_explicit_one_disabled() { let config = FormattingConfig { + disabled: Some(false), pint: None, php_cs_fixer: Some("/usr/bin/php-cs-fixer".to_string()), phpcbf: Some(String::new()), @@ -468,6 +471,7 @@ fn strategy_explicit_overrides_require_dev() { // User explicitly set a different path. let config = FormattingConfig { + disabled: Some(false), pint: None, php_cs_fixer: Some("/opt/php-cs-fixer".to_string()), phpcbf: Some(String::new()), @@ -725,6 +729,7 @@ fn execute_builtin_reformats_messy_class() { fn execute_disabled_returns_none() { let content = " Date: Tue, 8 Sep 2026 11:13:02 +0200 Subject: [PATCH 2/2] Invert logic --- src/config.rs | 6 +++--- src/formatting/tests.rs | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/config.rs b/src/config.rs index 7d7e00ff3..cf1e009cf 100644 --- a/src/config.rs +++ b/src/config.rs @@ -319,7 +319,7 @@ impl DiagnosticsConfig { #[serde(default)] pub struct FormattingConfig { /// Explicitly disable all formatting - pub disabled: Option, + pub enabled: Option, /// Command (path or name) to run php-cs-fixer. /// /// - `None` (default) — check `require-dev` in `composer.json`; @@ -383,7 +383,7 @@ impl FormattingConfig { /// Whether formatting is explicitly disabled pub fn is_disabled(&self) -> bool { - self.disabled == Some(true) + self.enabled == Some(false) } } @@ -1550,7 +1550,7 @@ paths = ["database/schema", "extra/schema.sql"] let path = dir.path().join(CONFIG_FILE_NAME); std::fs::write( &path, - "[formatting]\ndisabled = true\nphp-cs-fixer = \"\"\nphpcbf = \"\"\npint = \"\"\n", + "[formatting]\nenabled = false\nphp-cs-fixer = \"\"\nphpcbf = \"\"\npint = \"\"\n", ) .unwrap(); let config = load_config(dir.path()).unwrap(); diff --git a/src/formatting/tests.rs b/src/formatting/tests.rs index 99809fcdb..be81d6e1a 100644 --- a/src/formatting/tests.rs +++ b/src/formatting/tests.rs @@ -130,7 +130,7 @@ fn malformed_mago_toml_returns_error_not_panic() { #[test] fn strategy_both_disabled() { let config = FormattingConfig { - disabled: Some(false), + enabled: Some(true), pint: Some(String::new()), php_cs_fixer: Some(String::new()), phpcbf: Some(String::new()), @@ -145,7 +145,7 @@ fn strategy_both_disabled() { #[test] fn strategy_explicit_commands() { let config = FormattingConfig { - disabled: Some(false), + enabled: Some(true), pint: None, php_cs_fixer: Some("/usr/bin/php-cs-fixer".to_string()), phpcbf: Some("/usr/bin/phpcbf".to_string()), @@ -169,7 +169,7 @@ fn strategy_explicit_commands() { #[test] fn strategy_one_explicit_one_disabled() { let config = FormattingConfig { - disabled: Some(false), + enabled: Some(true), pint: None, php_cs_fixer: Some("/usr/bin/php-cs-fixer".to_string()), phpcbf: Some(String::new()), @@ -471,7 +471,7 @@ fn strategy_explicit_overrides_require_dev() { // User explicitly set a different path. let config = FormattingConfig { - disabled: Some(false), + enabled: Some(true), pint: None, php_cs_fixer: Some("/opt/php-cs-fixer".to_string()), phpcbf: Some(String::new()), @@ -729,7 +729,7 @@ fn execute_builtin_reformats_messy_class() { fn execute_disabled_returns_none() { let content = "