From 781a3a1317810d3b60486622912b2adc487cbbbe 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 | 27 +++++++++++++++++++++------ src/formatting.rs | 5 +++++ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/config.rs b/src/config.rs index 2a6e01d77..ea7a3034f 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`; @@ -354,12 +356,9 @@ impl FormattingConfig { self.timeout.unwrap_or(10_000) } - /// Whether formatting is entirely disabled (all tools explicitly - /// set to empty strings). + /// Whether formatting is explicitly disabled pub fn is_disabled(&self) -> bool { - self.php_cs_fixer.as_deref() == Some("") - && self.phpcbf.as_deref() == Some("") - && self.pint.as_deref() == Some("") + self.disabled == Some(true) } } @@ -1495,7 +1494,7 @@ paths = ["database/schema", "extra/schema.sql"] } #[test] - fn formatting_empty_string_disables_tool() { + fn formatting_empty_string_enables_tool() { let dir = tempfile::tempdir().unwrap(); let path = dir.path().join(CONFIG_FILE_NAME); std::fs::write( @@ -1507,6 +1506,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.rs b/src/formatting.rs index 36a7db2ea..6ed8f057b 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -792,6 +792,7 @@ mod tests { #[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()), @@ -804,6 +805,7 @@ mod tests { #[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()), @@ -825,6 +827,7 @@ mod tests { #[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()), @@ -1131,6 +1134,7 @@ mod tests { // 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()), @@ -1385,6 +1389,7 @@ mod tests { 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.rs | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/config.rs b/src/config.rs index ea7a3034f..4f44d5803 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`; @@ -358,7 +358,7 @@ impl FormattingConfig { /// Whether formatting is explicitly disabled pub fn is_disabled(&self) -> bool { - self.disabled == Some(true) + self.enabled == Some(false) } } @@ -1515,7 +1515,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.rs b/src/formatting.rs index 6ed8f057b..a6ffd673d 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -792,7 +792,7 @@ mod tests { #[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()), @@ -805,7 +805,7 @@ mod tests { #[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()), @@ -827,7 +827,7 @@ mod tests { #[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()), @@ -1134,7 +1134,7 @@ mod tests { // 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()), @@ -1389,7 +1389,7 @@ mod tests { fn execute_disabled_returns_none() { let content = "