From 20d195988de1014517ff1a1c8c1041cff5f88e05 Mon Sep 17 00:00:00 2001 From: Akshay Date: Tue, 26 Oct 2021 19:18:28 +0530 Subject: set internal crates to 0.0.0, bump to v0.2.0 --- Cargo.lock | 8 ++++---- bin/Cargo.toml | 2 +- bin/src/config.rs | 3 ++- bin/src/err.rs | 2 +- bin/src/fix.rs | 5 ++++- bin/src/fix/all.rs | 4 ++-- bin/src/fix/single.rs | 14 ++++++++------ bin/src/main.rs | 31 ++++++++++++++++++------------- flake.nix | 2 +- lib/Cargo.toml | 2 +- lib/src/lib.rs | 5 ++++- macros/Cargo.toml | 2 +- readme.md | 20 ++++++++++---------- vfs/Cargo.toml | 2 +- 14 files changed, 58 insertions(+), 44 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a527d30..3be258a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -183,7 +183,7 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "lib" -version = "0.1.0" +version = "0.0.0" dependencies = [ "if_chain", "lazy_static", @@ -211,7 +211,7 @@ dependencies = [ [[package]] name = "macros" -version = "0.1.0" +version = "0.0.0" dependencies = [ "proc-macro2", "quote", @@ -388,7 +388,7 @@ checksum = "b203e79e90905594272c1c97c7af701533d42adaab0beb3859018e477d54a3b0" [[package]] name = "statix" -version = "0.1.0" +version = "0.2.0" dependencies = [ "ariadne", "clap", @@ -495,7 +495,7 @@ checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" [[package]] name = "vfs" -version = "0.1.0" +version = "0.0.0" dependencies = [ "indexmap", ] diff --git a/bin/Cargo.toml b/bin/Cargo.toml index 528f804..c5f222b 100644 --- a/bin/Cargo.toml +++ b/bin/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "statix" -version = "0.1.0" +version = "0.2.0" edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/bin/src/config.rs b/bin/src/config.rs index 8ddfb4a..c856a59 100644 --- a/bin/src/config.rs +++ b/bin/src/config.rs @@ -234,9 +234,10 @@ impl FromStr for OutFormat { match value.to_ascii_lowercase().as_str() { #[cfg(feature = "json")] "json" => Ok(Self::Json), + #[cfg(not(feature = "json"))] + "json" => Err("statix was not compiled with the `json` feature flag"), "errfmt" => Ok(Self::Errfmt), "stderr" => Ok(Self::StdErr), - "json" => Err("statix was not compiled with the `json` feature flag"), _ => Err("unknown output format, try: json, errfmt"), } } diff --git a/bin/src/err.rs b/bin/src/err.rs index 5f71b57..53c3222 100644 --- a/bin/src/err.rs +++ b/bin/src/err.rs @@ -11,7 +11,7 @@ pub enum ConfigErr { #[error("path error: {0}")] InvalidPath(#[from] io::Error), #[error("unable to parse `{0}` as line and column")] - InvalidPosition(String) + InvalidPosition(String), } #[derive(Error, Debug)] diff --git a/bin/src/fix.rs b/bin/src/fix.rs index a7ddc4f..c378c13 100644 --- a/bin/src/fix.rs +++ b/bin/src/fix.rs @@ -24,6 +24,9 @@ pub struct Fixed { impl<'a> FixResult<'a> { fn empty(src: Source<'a>) -> Self { - Self { src, fixed: Vec::new() } + Self { + src, + fixed: Vec::new(), + } } } diff --git a/bin/src/fix/all.rs b/bin/src/fix/all.rs index 8c0770d..7f04f2c 100644 --- a/bin/src/fix/all.rs +++ b/bin/src/fix/all.rs @@ -3,7 +3,7 @@ use std::borrow::Cow; use lib::{Report, LINTS}; use rnix::{parser::ParseError as RnixParseErr, WalkEvent}; -use crate::fix::{Fixed, FixResult}; +use crate::fix::{FixResult, Fixed}; fn collect_fixes(source: &str) -> Result, RnixParseErr> { let parsed = rnix::parse(source).as_result()?; @@ -73,7 +73,7 @@ impl<'a> Iterator for FixResult<'a> { Some(FixResult { src: self.src.clone(), - fixed + fixed, }) } } diff --git a/bin/src/fix/single.rs b/bin/src/fix/single.rs index 24b5c51..c09c710 100644 --- a/bin/src/fix/single.rs +++ b/bin/src/fix/single.rs @@ -12,7 +12,11 @@ pub struct SingleFixResult<'δ> { fn pos_to_byte(line: usize, col: usize, src: &str) -> Result { let mut byte: TextSize = TextSize::of(""); - for (l, _) in src.split_inclusive('\n').zip(1..).take_while(|(_, i)| i < &line) { + for (l, _) in src + .split_inclusive('\n') + .zip(1..) + .take_while(|(_, i)| i < &line) + { byte += TextSize::of(l); } byte += TextSize::try_from(col).map_err(|_| SingleFixErr::Conversion(col))?; @@ -45,8 +49,8 @@ fn find(offset: TextSize, src: &str) -> Result { } else { None } - }, - _ => None + } + _ => None, }) .flatten() .next() @@ -60,7 +64,5 @@ pub fn single(line: usize, col: usize, src: &str) -> Result Result<(), StatixErr> { match opts.cmd { SubCommand::Check(check_config) => { let vfs = check_config.vfs()?; - let (lints, errors): (Vec<_>, Vec<_>) = vfs.iter().map(lint::lint).partition(Result::is_ok); + let (lints, errors): (Vec<_>, Vec<_>) = + vfs.iter().map(lint::lint).partition(Result::is_ok); let lint_results = lints.into_iter().map(Result::unwrap); let errors = errors.into_iter().map(Result::unwrap_err); @@ -28,7 +32,7 @@ fn _main() -> Result<(), StatixErr> { errors.for_each(|e| { eprintln!("{}", e); }); - }, + } SubCommand::Fix(fix_config) => { let vfs = fix_config.vfs()?; for entry in vfs.iter() { @@ -40,17 +44,17 @@ fn _main() -> Result<(), StatixErr> { println!( "{}", text_diff - .unified_diff() - .context_radius(4) - .header(&old_file, &new_file) - ); + .unified_diff() + .context_radius(4) + .header(&old_file, &new_file) + ); } else { let path = entry.file_path; std::fs::write(path, &*fix_result.src).map_err(FixErr::InvalidPath)?; } } } - }, + } SubCommand::Single(single_config) => { let path = single_config.target; let src = std::fs::read_to_string(&path).map_err(SingleFixErr::InvalidPath)?; @@ -63,12 +67,13 @@ fn _main() -> Result<(), StatixErr> { println!( "{}", text_diff - .unified_diff() - .context_radius(4) - .header(&old_file, &new_file) - ); + .unified_diff() + .context_radius(4) + .header(&old_file, &new_file) + ); } else { - std::fs::write(&path, &*single_fix_result.src).map_err(SingleFixErr::InvalidPath)?; + std::fs::write(&path, &*single_fix_result.src) + .map_err(SingleFixErr::InvalidPath)?; } } } diff --git a/flake.nix b/flake.nix index 2c1db03..9bef554 100644 --- a/flake.nix +++ b/flake.nix @@ -49,7 +49,7 @@ statix = with final; pkgs.stdenv.mkDerivation { pname = "statix"; - version = "v0.1.0"; + version = "v0.2.0"; src = builtins.path { path = ./.; name = "statix"; diff --git a/lib/Cargo.toml b/lib/Cargo.toml index e9bca06..b876c4c 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lib" -version = "0.1.0" +version = "0.0.0" edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/lib/src/lib.rs b/lib/src/lib.rs index bde039f..41e38c8 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -7,7 +7,10 @@ use rnix::{SyntaxElement, SyntaxKind, TextRange}; use std::{convert::Into, default::Default}; #[cfg(feature = "json-out")] -use serde::{Serialize, ser::{SerializeStruct, Serializer}}; +use serde::{ + ser::{SerializeStruct, Serializer}, + Serialize, +}; /// Report generated by a lint #[derive(Debug, Default)] diff --git a/macros/Cargo.toml b/macros/Cargo.toml index b2027fc..ae24eee 100644 --- a/macros/Cargo.toml +++ b/macros/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "macros" -version = "0.1.0" +version = "0.0.0" edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/readme.md b/readme.md index 293b72e..d1eda39 100644 --- a/readme.md +++ b/readme.md @@ -2,8 +2,8 @@ > Lints and suggestions for the Nix programming language. -`statix` highlights antipatterns in Nix code. `statix --fix` -can fix several such occurrences. +`statix check` highlights antipatterns in Nix code. `statix +fix` can fix several such occurrences. For the time-being, `statix` works only with ASTs produced by the `rnix-parser` crate and does not evaluate @@ -12,7 +12,7 @@ any nix code (imports, attr sets etc.). ## Examples ```shell -$ statix tests/c.nix +$ statix check tests/c.nix [W04] Warning: Assignment instead of inherit from ╭─[tests/c.nix:2:3] │ @@ -21,7 +21,7 @@ $ statix tests/c.nix · ╰───────────────── This assignment is better written with inherit ───╯ -$ statix --fix --dry-run tests/c.nix +$ statix fix --dry-run tests/c.nix --- tests/c.nix +++ tests/c.nix [fixed] @@ -1,6 +1,6 @@ @@ -54,10 +54,10 @@ Basic usage is as simple as: ```shell # recursively finds nix files and raises lints -statix /path/to/dir +statix check /path/to/dir # ignore generated files, such as Cargo.nix -statix /path/to/dir -i '*Cargo.nix' +statix check /path/to/dir -i '*Cargo.nix' # see `statix -h` for a full list of options ``` @@ -66,18 +66,18 @@ Certain lints have suggestions. Apply suggestions back to the source with: ```shell -statix --fix /path/to/file +statix fix /path/to/file # show diff, do not write to file -statix --fix --dry-run /path/to/file +statix fix --dry-run /path/to/file ``` `statix` supports a variety of output formats; standard, json and errfmt: ```shell -statix /path/to/dir -o json -statix /path/to/dir -o errfmt # singleline, easy to integrate with vim +statix check /path/to/dir -o json # only when compiled with --all-features +statix check /path/to/dir -o errfmt # singleline, easy to integrate with vim ``` ## Architecture diff --git a/vfs/Cargo.toml b/vfs/Cargo.toml index 56a2c61..b8aa8d9 100644 --- a/vfs/Cargo.toml +++ b/vfs/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "vfs" -version = "0.1.0" +version = "0.0.0" edition = "2018" [dependencies] -- cgit v1.2.3