mirror of
https://github.com/nerdypepper/statix.git
synced 2024-08-17 01:10:26 +03:00
Compare commits
2 Commits
448e6f2096
...
d197ae1124
Author | SHA1 | Date | |
---|---|---|---|
|
d197ae1124 | ||
|
53b454cd6a |
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -588,7 +588,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "statix"
|
name = "statix"
|
||||||
version = "0.5.4"
|
version = "0.5.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ariadne",
|
"ariadne",
|
||||||
"clap",
|
"clap",
|
||||||
|
@ -4,6 +4,6 @@ members = [
|
|||||||
"bin",
|
"bin",
|
||||||
"lib",
|
"lib",
|
||||||
"macros",
|
"macros",
|
||||||
"vfs"
|
"vfs",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "statix"
|
name = "statix"
|
||||||
version = "0.5.4"
|
version = "0.5.5"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
authors = [ "Akshay <nerdy@peppe.rs>" ]
|
authors = [ "Akshay <nerdy@peppe.rs>" ]
|
||||||
|
@ -65,7 +65,7 @@ pub struct Check {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Check {
|
impl Check {
|
||||||
pub fn vfs(&self) -> Result<ReadOnlyVfs, ConfigErr> {
|
pub fn vfs(&self, extra_ignores: &[String]) -> Result<ReadOnlyVfs, ConfigErr> {
|
||||||
if self.streaming {
|
if self.streaming {
|
||||||
use std::io::{self, BufRead};
|
use std::io::{self, BufRead};
|
||||||
let src = io::stdin()
|
let src = io::stdin()
|
||||||
@ -76,7 +76,8 @@ impl Check {
|
|||||||
.join("\n");
|
.join("\n");
|
||||||
Ok(ReadOnlyVfs::singleton("<stdin>", src.as_bytes()))
|
Ok(ReadOnlyVfs::singleton("<stdin>", src.as_bytes()))
|
||||||
} else {
|
} 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)?;
|
let files = dirs::walk_nix_files(ignore, &self.target)?;
|
||||||
vfs(files.collect::<Vec<_>>())
|
vfs(files.collect::<Vec<_>>())
|
||||||
}
|
}
|
||||||
@ -117,7 +118,7 @@ pub enum FixOut {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Fix {
|
impl Fix {
|
||||||
pub fn vfs(&self) -> Result<ReadOnlyVfs, ConfigErr> {
|
pub fn vfs(&self, extra_ignores: &[String]) -> Result<ReadOnlyVfs, ConfigErr> {
|
||||||
if self.streaming {
|
if self.streaming {
|
||||||
use std::io::{self, BufRead};
|
use std::io::{self, BufRead};
|
||||||
let src = io::stdin()
|
let src = io::stdin()
|
||||||
@ -128,7 +129,8 @@ impl Fix {
|
|||||||
.join("\n");
|
.join("\n");
|
||||||
Ok(ReadOnlyVfs::singleton("<stdin>", src.as_bytes()))
|
Ok(ReadOnlyVfs::singleton("<stdin>", src.as_bytes()))
|
||||||
} else {
|
} 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)?;
|
let files = dirs::walk_nix_files(ignore, &self.target)?;
|
||||||
vfs(files.collect::<Vec<_>>())
|
vfs(files.collect::<Vec<_>>())
|
||||||
}
|
}
|
||||||
@ -260,16 +262,22 @@ impl FromStr for OutFormat {
|
|||||||
pub struct ConfFile {
|
pub struct ConfFile {
|
||||||
#[serde(default = "Vec::new")]
|
#[serde(default = "Vec::new")]
|
||||||
disabled: Vec<String>,
|
disabled: Vec<String>,
|
||||||
|
|
||||||
nix_version: Option<String>,
|
nix_version: Option<String>,
|
||||||
|
|
||||||
|
#[serde(default = "Vec::new")]
|
||||||
|
pub ignore: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ConfFile {
|
impl Default for ConfFile {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
let disabled = vec![];
|
let disabled = Default::default();
|
||||||
let nix_version = None;
|
let ignore = Default::default();
|
||||||
|
let nix_version = Default::default();
|
||||||
Self {
|
Self {
|
||||||
disabled,
|
disabled,
|
||||||
nix_version,
|
nix_version,
|
||||||
|
ignore,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -298,9 +306,11 @@ impl ConfFile {
|
|||||||
let ideal_config = {
|
let ideal_config = {
|
||||||
let disabled = vec![];
|
let disabled = vec![];
|
||||||
let nix_version = Some(utils::default_nix_version());
|
let nix_version = Some(utils::default_nix_version());
|
||||||
|
let ignore = vec![".direnv".into()];
|
||||||
Self {
|
Self {
|
||||||
disabled,
|
disabled,
|
||||||
nix_version,
|
nix_version,
|
||||||
|
ignore,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
toml::ser::to_string_pretty(&ideal_config).unwrap()
|
toml::ser::to_string_pretty(&ideal_config).unwrap()
|
||||||
|
@ -51,8 +51,8 @@ pub mod main {
|
|||||||
use similar::TextDiff;
|
use similar::TextDiff;
|
||||||
|
|
||||||
pub fn all(fix_config: FixConfig) -> Result<(), StatixErr> {
|
pub fn all(fix_config: FixConfig) -> Result<(), StatixErr> {
|
||||||
let vfs = fix_config.vfs()?;
|
|
||||||
let conf_file = ConfFile::discover(&fix_config.conf_path)?;
|
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 lints = conf_file.lints();
|
||||||
let version = conf_file.version()?;
|
let version = conf_file.version()?;
|
||||||
|
@ -53,12 +53,14 @@ pub mod main {
|
|||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
|
|
||||||
pub fn main(check_config: CheckConfig) -> Result<(), StatixErr> {
|
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 conf_file = ConfFile::discover(&check_config.conf_path)?;
|
||||||
let lints = conf_file.lints();
|
let lints = conf_file.lints();
|
||||||
let version = conf_file.version()?;
|
let version = conf_file.version()?;
|
||||||
let session = SessionInfo::from_version(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 lint = |vfs_entry| lint_with(vfs_entry, &lints, &session);
|
||||||
let results = vfs
|
let results = vfs
|
||||||
.par_iter()
|
.par_iter()
|
||||||
|
19
flake.nix
19
flake.nix
@ -108,5 +108,24 @@
|
|||||||
RUST_BACKTRACE = 1;
|
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";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -121,7 +121,8 @@ to the `statix.toml` file on the command line with the
|
|||||||
`--config` flag (available on `statix check` and `statix
|
`--config` flag (available on `statix check` and `statix
|
||||||
fix`).
|
fix`).
|
||||||
|
|
||||||
The available lints are:
|
The available lints are (see `statix list` for an updated
|
||||||
|
list):
|
||||||
|
|
||||||
```
|
```
|
||||||
bool_comparison
|
bool_comparison
|
||||||
@ -140,9 +141,12 @@ empty_inherit
|
|||||||
faster_groupby
|
faster_groupby
|
||||||
faster_zipattrswith
|
faster_zipattrswith
|
||||||
deprecated_to_path
|
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
|
## TODO
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user