diff options
-rw-r--r-- | bin/src/config.rs | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/bin/src/config.rs b/bin/src/config.rs index 28e6cc3..29b6c9e 100644 --- a/bin/src/config.rs +++ b/bin/src/config.rs | |||
@@ -53,7 +53,7 @@ pub struct Check { | |||
53 | pub format: OutFormat, | 53 | pub format: OutFormat, |
54 | 54 | ||
55 | /// Path to statix.toml | 55 | /// Path to statix.toml |
56 | #[clap(short = 'c', long = "config", default_value = "./statix.toml")] | 56 | #[clap(short = 'c', long = "config", default_value = ".")] |
57 | pub conf_path: PathBuf, | 57 | pub conf_path: PathBuf, |
58 | 58 | ||
59 | /// Enable "streaming" mode, accept file on stdin, output diagnostics on stdout | 59 | /// Enable "streaming" mode, accept file on stdin, output diagnostics on stdout |
@@ -99,7 +99,7 @@ pub struct Fix { | |||
99 | pub diff_only: bool, | 99 | pub diff_only: bool, |
100 | 100 | ||
101 | /// Path to statix.toml | 101 | /// Path to statix.toml |
102 | #[clap(short = 'c', long = "config", default_value = "./statix.toml")] | 102 | #[clap(short = 'c', long = "config", default_value = ".")] |
103 | pub conf_path: PathBuf, | 103 | pub conf_path: PathBuf, |
104 | 104 | ||
105 | /// Enable "streaming" mode, accept file on stdin, output diagnostics on stdout | 105 | /// Enable "streaming" mode, accept file on stdin, output diagnostics on stdout |
@@ -163,7 +163,7 @@ pub struct Single { | |||
163 | pub streaming: bool, | 163 | pub streaming: bool, |
164 | 164 | ||
165 | /// Path to statix.toml | 165 | /// Path to statix.toml |
166 | #[clap(short = 'c', long = "config", default_value = "./statix.toml")] | 166 | #[clap(short = 'c', long = "config", default_value = ".")] |
167 | pub conf_path: PathBuf, | 167 | pub conf_path: PathBuf, |
168 | } | 168 | } |
169 | 169 | ||
@@ -260,7 +260,7 @@ pub struct ConfFile { | |||
260 | impl Default for ConfFile { | 260 | impl Default for ConfFile { |
261 | fn default() -> Self { | 261 | fn default() -> Self { |
262 | let disabled = vec![]; | 262 | let disabled = vec![]; |
263 | let nix_version = Some(utils::default_nix_version()); | 263 | let nix_version = None; |
264 | Self { | 264 | Self { |
265 | disabled, | 265 | disabled, |
266 | nix_version, | 266 | nix_version, |
@@ -277,7 +277,11 @@ impl ConfFile { | |||
277 | pub fn discover<P: AsRef<Path>>(path: P) -> Result<Self, ConfigErr> { | 277 | pub fn discover<P: AsRef<Path>>(path: P) -> Result<Self, ConfigErr> { |
278 | let cannonical_path = fs::canonicalize(path.as_ref()).map_err(ConfigErr::InvalidPath)?; | 278 | let cannonical_path = fs::canonicalize(path.as_ref()).map_err(ConfigErr::InvalidPath)?; |
279 | for p in cannonical_path.ancestors() { | 279 | for p in cannonical_path.ancestors() { |
280 | let statix_toml_path = p.with_file_name("statix.toml"); | 280 | let statix_toml_path = if p.is_dir() { |
281 | p.join("statix.toml") | ||
282 | } else { | ||
283 | p.with_file_name("statix.toml") | ||
284 | }; | ||
281 | if statix_toml_path.exists() { | 285 | if statix_toml_path.exists() { |
282 | return Self::from_path(statix_toml_path); | 286 | return Self::from_path(statix_toml_path); |
283 | }; | 287 | }; |
@@ -285,7 +289,15 @@ impl ConfFile { | |||
285 | Ok(Self::default()) | 289 | Ok(Self::default()) |
286 | } | 290 | } |
287 | pub fn dump(&self) -> String { | 291 | pub fn dump(&self) -> String { |
288 | toml::ser::to_string_pretty(&self).unwrap() | 292 | let ideal_config = { |
293 | let disabled = vec![]; | ||
294 | let nix_version = Some(utils::default_nix_version()); | ||
295 | Self { | ||
296 | disabled, | ||
297 | nix_version, | ||
298 | } | ||
299 | }; | ||
300 | toml::ser::to_string_pretty(&ideal_config).unwrap() | ||
289 | } | 301 | } |
290 | pub fn lints(&self) -> LintMap { | 302 | pub fn lints(&self) -> LintMap { |
291 | utils::lint_map_of( | 303 | utils::lint_map_of( |