diff --git a/src/config.rs b/src/config.rs index 2a6e01d77..4f44d5803 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 enabled: 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.enabled == Some(false) } } @@ -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]\nenabled = false\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..a6ffd673d 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -792,6 +792,7 @@ mod tests { #[test] fn strategy_both_disabled() { let config = FormattingConfig { + enabled: Some(true), 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 { + enabled: Some(true), 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 { + enabled: Some(true), 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 { + enabled: Some(true), 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 = "