Compare commits

...

2 Commits

Author SHA1 Message Date
Akshay
d197ae1124 update readme 2022-05-01 20:47:35 +05:30
Akshay
53b454cd6a add ignore to statix.toml 2022-05-01 20:42:12 +05:30
8 changed files with 49 additions and 14 deletions

2
Cargo.lock generated
View File

@ -588,7 +588,7 @@ dependencies = [
[[package]]
name = "statix"
version = "0.5.4"
version = "0.5.5"
dependencies = [
"ariadne",
"clap",

View File

@ -4,6 +4,6 @@ members = [
"bin",
"lib",
"macros",
"vfs"
"vfs",
]

View File

@ -1,6 +1,6 @@
[package]
name = "statix"
version = "0.5.4"
version = "0.5.5"
edition = "2018"
license = "MIT"
authors = [ "Akshay <nerdy@peppe.rs>" ]

View File

@ -65,7 +65,7 @@ pub struct Check {
}
impl Check {
pub fn vfs(&self) -> Result<ReadOnlyVfs, ConfigErr> {
pub fn vfs(&self, extra_ignores: &[String]) -> Result<ReadOnlyVfs, ConfigErr> {
if self.streaming {
use std::io::{self, BufRead};
let src = io::stdin()
@ -76,7 +76,8 @@ impl Check {
.join("\n");
Ok(ReadOnlyVfs::singleton("<stdin>", 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::<Vec<_>>())
}
@ -117,7 +118,7 @@ pub enum FixOut {
}
impl Fix {
pub fn vfs(&self) -> Result<ReadOnlyVfs, ConfigErr> {
pub fn vfs(&self, extra_ignores: &[String]) -> Result<ReadOnlyVfs, ConfigErr> {
if self.streaming {
use std::io::{self, BufRead};
let src = io::stdin()
@ -128,7 +129,8 @@ impl Fix {
.join("\n");
Ok(ReadOnlyVfs::singleton("<stdin>", 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::<Vec<_>>())
}
@ -260,16 +262,22 @@ impl FromStr for OutFormat {
pub struct ConfFile {
#[serde(default = "Vec::new")]
disabled: Vec<String>,
nix_version: Option<String>,
#[serde(default = "Vec::new")]
pub ignore: Vec<String>,
}
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()

View File

@ -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()?;

View File

@ -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()

View File

@ -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";
};
}
);
};
}

View File

@ -121,7 +121,8 @@ to the `statix.toml` file on the command line with the
`--config` flag (available on `statix check` and `statix
fix`).
The available lints are:
The available lints are (see `statix list` for an updated
list):
```
bool_comparison
@ -140,9 +141,12 @@ empty_inherit
faster_groupby
faster_zipattrswith
deprecated_to_path
bool_simplification
useless_has_attr
```
All lints are enabled by default.
All lints are enabled by default. Generate a minimal config
with `statix dump > statix.toml`.
## TODO