From 53b454cd6acba89fe6b5bb39df431afa28a6ee13 Mon Sep 17 00:00:00 2001 From: Akshay Date: Sun, 1 May 2022 20:42:12 +0530 Subject: add `ignore` to statix.toml --- Cargo.lock | 2 +- Cargo.toml | 2 +- bin/Cargo.toml | 2 +- bin/src/config.rs | 22 ++++++++++++++++------ bin/src/fix.rs | 2 +- bin/src/lint.rs | 6 ++++-- flake.nix | 19 +++++++++++++++++++ 7 files changed, 43 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f42ec61..7fc1004 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -588,7 +588,7 @@ dependencies = [ [[package]] name = "statix" -version = "0.5.4" +version = "0.5.5" dependencies = [ "ariadne", "clap", diff --git a/Cargo.toml b/Cargo.toml index 7303bc8..9de5b94 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,6 @@ members = [ "bin", "lib", "macros", - "vfs" + "vfs", ] diff --git a/bin/Cargo.toml b/bin/Cargo.toml index 095d048..8897996 100644 --- a/bin/Cargo.toml +++ b/bin/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "statix" -version = "0.5.4" +version = "0.5.5" edition = "2018" license = "MIT" authors = [ "Akshay " ] diff --git a/bin/src/config.rs b/bin/src/config.rs index 07b3f17..d3c3e91 100644 --- a/bin/src/config.rs +++ b/bin/src/config.rs @@ -65,7 +65,7 @@ pub struct Check { } impl Check { - pub fn vfs(&self) -> Result { + pub fn vfs(&self, extra_ignores: &[String]) -> Result { if self.streaming { use std::io::{self, BufRead}; let src = io::stdin() @@ -76,7 +76,8 @@ impl Check { .join("\n"); Ok(ReadOnlyVfs::singleton("", src.as_bytes())) } else { - let ignore = dirs::build_ignore_set(&self.ignore, &self.target, self.unrestricted)?; + let all_ignores = dbg!([self.ignore.as_slice(), extra_ignores].concat()); + let ignore = dirs::build_ignore_set(&all_ignores, &self.target, self.unrestricted)?; let files = dirs::walk_nix_files(ignore, &self.target)?; vfs(files.collect::>()) } @@ -117,7 +118,7 @@ pub enum FixOut { } impl Fix { - pub fn vfs(&self) -> Result { + pub fn vfs(&self, extra_ignores: &[String]) -> Result { if self.streaming { use std::io::{self, BufRead}; let src = io::stdin() @@ -128,7 +129,8 @@ impl Fix { .join("\n"); Ok(ReadOnlyVfs::singleton("", src.as_bytes())) } else { - let ignore = dirs::build_ignore_set(&self.ignore, &self.target, self.unrestricted)?; + let all_ignores = [self.ignore.as_slice(), extra_ignores].concat(); + let ignore = dirs::build_ignore_set(&all_ignores, &self.target, self.unrestricted)?; let files = dirs::walk_nix_files(ignore, &self.target)?; vfs(files.collect::>()) } @@ -260,16 +262,22 @@ impl FromStr for OutFormat { pub struct ConfFile { #[serde(default = "Vec::new")] disabled: Vec, + nix_version: Option, + + #[serde(default = "Vec::new")] + pub ignore: Vec, } impl Default for ConfFile { fn default() -> Self { - let disabled = vec![]; - let nix_version = None; + let disabled = Default::default(); + let ignore = Default::default(); + let nix_version = Default::default(); Self { disabled, nix_version, + ignore, } } } @@ -298,9 +306,11 @@ impl ConfFile { let ideal_config = { let disabled = vec![]; let nix_version = Some(utils::default_nix_version()); + let ignore = vec![".direnv".into()]; Self { disabled, nix_version, + ignore, } }; toml::ser::to_string_pretty(&ideal_config).unwrap() diff --git a/bin/src/fix.rs b/bin/src/fix.rs index 84186d4..da5a470 100644 --- a/bin/src/fix.rs +++ b/bin/src/fix.rs @@ -51,8 +51,8 @@ pub mod main { use similar::TextDiff; pub fn all(fix_config: FixConfig) -> Result<(), StatixErr> { - let vfs = fix_config.vfs()?; let conf_file = ConfFile::discover(&fix_config.conf_path)?; + let vfs = fix_config.vfs(conf_file.ignore.as_slice())?; let lints = conf_file.lints(); let version = conf_file.version()?; diff --git a/bin/src/lint.rs b/bin/src/lint.rs index e1544e1..b7529ba 100644 --- a/bin/src/lint.rs +++ b/bin/src/lint.rs @@ -53,12 +53,14 @@ pub mod main { use rayon::prelude::*; pub fn main(check_config: CheckConfig) -> Result<(), StatixErr> { - let vfs = check_config.vfs()?; - let mut stdout = io::stdout(); let conf_file = ConfFile::discover(&check_config.conf_path)?; let lints = conf_file.lints(); let version = conf_file.version()?; let session = SessionInfo::from_version(version); + + let vfs = check_config.vfs(conf_file.ignore.as_slice())?; + + let mut stdout = io::stdout(); let lint = |vfs_entry| lint_with(vfs_entry, &lints, &session); let results = vfs .par_iter() diff --git a/flake.nix b/flake.nix index f6099e0..1fd10a9 100644 --- a/flake.nix +++ b/flake.nix @@ -108,5 +108,24 @@ RUST_BACKTRACE = 1; }); + + apps = forAllSystems + (system: + let + pkgs = nixpkgsFor."${system}"; + cachix-push-script = pkgs.writeScriptBin "cachix-push" '' + ${pkgs.nixUnstable}/bin/nix build --json \ + | ${pkgs.jq}/bin/jq -r '.[].outputs | to_entries[].value' \ + | ${pkgs.cachix}/bin/cachix push statix + ''; + in + { + cachix-push = { + type = "app"; + program = "${cachix-push-script}/bin/cachix-push"; + }; + } + ); + }; } -- cgit v1.2.3