Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ tempfile = "*"
thiserror = "*"
toml = "*"
vfs.path = "./vfs"
xdg = "*"

[workspace.lints.clippy]
pedantic = { level = "deny", priority = -1 }
Expand Down
1 change: 1 addition & 0 deletions bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ tempfile.workspace = true
thiserror.workspace = true
toml.workspace = true
vfs.workspace = true
xdg.workspace = true

[dev-dependencies]
indoc.workspace = true
Expand Down
25 changes: 18 additions & 7 deletions bin/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self, ConfigErr> {
Ok(Self::discover_default_with_found()?.0)
}
pub fn discover<P: AsRef<Path>>(path: P) -> Result<Self, ConfigErr> {
let cannonical_path = fs::canonicalize(path.as_ref()).map_err(ConfigErr::InvalidPath)?;
for p in cannonical_path.ancestors() {
Expand All @@ -280,16 +289,18 @@ impl ConfFile {
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<String, ConfigErr> {
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 {
Expand Down
2 changes: 1 addition & 1 deletion bin/src/dump.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
}
9 changes: 5 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`).

@MrQubo MrQubo Jun 12, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that the list of subcommands, where --config flag is available, is incomplete.


The available lints are (see `statix list` for an updated
list):
Expand Down