From b3fc49c7f52ed125044e4f7e8e07b5e93c681385 Mon Sep 17 00:00:00 2001 From: MrQubo Date: Fri, 12 Jun 2026 13:23:48 +0200 Subject: [PATCH 1/3] Search for default statix.toml according to xdg spec --- Cargo.lock | 7 +++++++ Cargo.toml | 1 + bin/Cargo.toml | 1 + bin/src/config.rs | 5 +++++ 4 files changed, 14 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index a5bca267..8b07252d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -730,6 +730,7 @@ dependencies = [ "thiserror", "toml", "vfs", + "xdg", ] [[package]] @@ -1069,6 +1070,12 @@ dependencies = [ "wasmparser", ] +[[package]] +name = "xdg" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fb433233f2df9344722454bc7e96465c9d03bff9d77c248f9e7523fe79585b5" + [[package]] name = "yansi" version = "1.0.1" diff --git a/Cargo.toml b/Cargo.toml index 1cb5baf3..98b42fb6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,6 +35,7 @@ tempfile = "*" thiserror = "*" toml = "*" vfs.path = "./vfs" +xdg = "*" [workspace.lints.clippy] pedantic = { level = "deny", priority = -1 } diff --git a/bin/Cargo.toml b/bin/Cargo.toml index d9acabd9..0e66a858 100644 --- a/bin/Cargo.toml +++ b/bin/Cargo.toml @@ -31,6 +31,7 @@ tempfile.workspace = true thiserror.workspace = true toml.workspace = true vfs.workspace = true +xdg.workspace = true [dev-dependencies] indoc.workspace = true diff --git a/bin/src/config.rs b/bin/src/config.rs index 678e216a..b0e62e72 100644 --- a/bin/src/config.rs +++ b/bin/src/config.rs @@ -280,6 +280,11 @@ impl ConfFile { return Self::from_path(statix_toml_path); } } + if let Some(statix_toml_path) = + xdg::BaseDirectories::with_prefix("statix").find_config_file("statix.toml") + { + return Self::from_path(statix_toml_path); + } Ok(Self::default()) } #[must_use] From d9c52d2e59db2ae314f0880c6d93d8d1b433d0cf Mon Sep 17 00:00:00 2001 From: MrQubo Date: Fri, 12 Jun 2026 14:02:10 +0200 Subject: [PATCH 2/3] Add info about xdg spec to readme --- readme.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/readme.md b/readme.md index d371b037..387b7746 100644 --- a/readme.md +++ b/readme.md @@ -126,10 +126,11 @@ disabled = [ `statix` automatically discovers the configuration file by traversing parents of the current directory and looking for -a `statix.toml` file. Alternatively, you can pass the path -to the `statix.toml` file on the command line with the -`--config` flag (available on `statix check` and `statix -fix`). +a `statix.toml` file. If none is found it will also check +`$XDG_CONFIG_HOME/statix/statix.toml`. Alternatively, you +can pass the path to the `statix.toml` file on the command +line with the `--config` flag (available on `statix check`, +`statix fix`, and `statix single`). The available lints are (see `statix list` for an updated list): From 0f02b4d2c870636d6bc4a2412d0c9ad8e918e741 Mon Sep 17 00:00:00 2001 From: MrQubo Date: Mon, 15 Jun 2026 18:11:28 +0200 Subject: [PATCH 3/3] Modify dump command to print user-defined default --- bin/src/config.rs | 30 ++++++++++++++++++------------ bin/src/dump.rs | 2 +- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/bin/src/config.rs b/bin/src/config.rs index b0e62e72..547fea39 100644 --- a/bin/src/config.rs +++ b/bin/src/config.rs @@ -268,6 +268,15 @@ impl ConfFile { let config_file = fs::read_to_string(path).map_err(ConfigErr::InvalidPath)?; toml::de::from_str(&config_file).map_err(ConfigErr::ConfFileParse) } + fn discover_default_with_found() -> Result<(Self, bool), ConfigErr> { + match xdg::BaseDirectories::with_prefix("statix").find_config_file("statix.toml") { + Some(statix_toml_path) => Ok((Self::from_path(statix_toml_path)?, true)), + None => Ok((Self::default(), false)), + } + } + fn discover_default() -> Result { + Ok(Self::discover_default_with_found()?.0) + } pub fn discover>(path: P) -> Result { let cannonical_path = fs::canonicalize(path.as_ref()).map_err(ConfigErr::InvalidPath)?; for p in cannonical_path.ancestors() { @@ -280,21 +289,18 @@ impl ConfFile { return Self::from_path(statix_toml_path); } } - if let Some(statix_toml_path) = - xdg::BaseDirectories::with_prefix("statix").find_config_file("statix.toml") - { - return Self::from_path(statix_toml_path); - } - Ok(Self::default()) + Self::discover_default() } #[must_use] - pub fn dump(&self) -> String { - let ideal_config = { - let disabled = vec![]; - let ignore = vec![".direnv".into()]; - Self { disabled, ignore } + pub fn dump_default() -> Result { + let ideal_config = match Self::discover_default_with_found()? { + (config, true) => config, + (_, false) => Self { + disabled: vec![], + ignore: vec![".direnv".into()], + }, }; - toml::ser::to_string_pretty(&ideal_config).unwrap() + Ok(toml::ser::to_string_pretty(&ideal_config).unwrap()) } #[must_use] pub fn lints(&self) -> LintMap { diff --git a/bin/src/dump.rs b/bin/src/dump.rs index 5ec3f0dc..e038d833 100644 --- a/bin/src/dump.rs +++ b/bin/src/dump.rs @@ -1,7 +1,7 @@ pub mod main { use crate::{config::ConfFile, err::StatixErr}; pub fn main() -> Result<(), StatixErr> { - println!("{}", ConfFile::dump(&ConfFile::default())); + println!("{}", ConfFile::dump_default()?); Ok(()) } }