Lints and suggestions for the Nix programming language
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

set internal crates to 0.0.0, bump to v0.2.0

Akshay 20d19598 393c2856

+58 -44
+4 -4
Cargo.lock
··· 183 183 184 184 [[package]] 185 185 name = "lib" 186 - version = "0.1.0" 186 + version = "0.0.0" 187 187 dependencies = [ 188 188 "if_chain", 189 189 "lazy_static", ··· 211 211 212 212 [[package]] 213 213 name = "macros" 214 - version = "0.1.0" 214 + version = "0.0.0" 215 215 dependencies = [ 216 216 "proc-macro2", 217 217 "quote", ··· 388 388 389 389 [[package]] 390 390 name = "statix" 391 - version = "0.1.0" 391 + version = "0.2.0" 392 392 dependencies = [ 393 393 "ariadne", 394 394 "clap", ··· 495 495 496 496 [[package]] 497 497 name = "vfs" 498 - version = "0.1.0" 498 + version = "0.0.0" 499 499 dependencies = [ 500 500 "indexmap", 501 501 ]
+1 -1
bin/Cargo.toml
··· 1 1 [package] 2 2 name = "statix" 3 - version = "0.1.0" 3 + version = "0.2.0" 4 4 edition = "2018" 5 5 6 6 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+2 -1
bin/src/config.rs
··· 234 234 match value.to_ascii_lowercase().as_str() { 235 235 #[cfg(feature = "json")] 236 236 "json" => Ok(Self::Json), 237 + #[cfg(not(feature = "json"))] 238 + "json" => Err("statix was not compiled with the `json` feature flag"), 237 239 "errfmt" => Ok(Self::Errfmt), 238 240 "stderr" => Ok(Self::StdErr), 239 - "json" => Err("statix was not compiled with the `json` feature flag"), 240 241 _ => Err("unknown output format, try: json, errfmt"), 241 242 } 242 243 }
+1 -1
bin/src/err.rs
··· 11 11 #[error("path error: {0}")] 12 12 InvalidPath(#[from] io::Error), 13 13 #[error("unable to parse `{0}` as line and column")] 14 - InvalidPosition(String) 14 + InvalidPosition(String), 15 15 } 16 16 17 17 #[derive(Error, Debug)]
+4 -1
bin/src/fix.rs
··· 24 24 25 25 impl<'a> FixResult<'a> { 26 26 fn empty(src: Source<'a>) -> Self { 27 - Self { src, fixed: Vec::new() } 27 + Self { 28 + src, 29 + fixed: Vec::new(), 30 + } 28 31 } 29 32 }
+2 -2
bin/src/fix/all.rs
··· 3 3 use lib::{Report, LINTS}; 4 4 use rnix::{parser::ParseError as RnixParseErr, WalkEvent}; 5 5 6 - use crate::fix::{Fixed, FixResult}; 6 + use crate::fix::{FixResult, Fixed}; 7 7 8 8 fn collect_fixes(source: &str) -> Result<Vec<Report>, RnixParseErr> { 9 9 let parsed = rnix::parse(source).as_result()?; ··· 73 73 74 74 Some(FixResult { 75 75 src: self.src.clone(), 76 - fixed 76 + fixed, 77 77 }) 78 78 } 79 79 }
+8 -6
bin/src/fix/single.rs
··· 12 12 13 13 fn pos_to_byte(line: usize, col: usize, src: &str) -> Result<TextSize, SingleFixErr> { 14 14 let mut byte: TextSize = TextSize::of(""); 15 - for (l, _) in src.split_inclusive('\n').zip(1..).take_while(|(_, i)| i < &line) { 15 + for (l, _) in src 16 + .split_inclusive('\n') 17 + .zip(1..) 18 + .take_while(|(_, i)| i < &line) 19 + { 16 20 byte += TextSize::of(l); 17 21 } 18 22 byte += TextSize::try_from(col).map_err(|_| SingleFixErr::Conversion(col))?; ··· 45 49 } else { 46 50 None 47 51 } 48 - }, 49 - _ => None 52 + } 53 + _ => None, 50 54 }) 51 55 .flatten() 52 56 .next() ··· 60 64 61 65 report.apply(src.to_mut()); 62 66 63 - Ok(SingleFixResult { 64 - src 65 - }) 67 + Ok(SingleFixResult { src }) 66 68 }
+18 -13
bin/src/main.rs
··· 6 6 7 7 use std::io; 8 8 9 - use crate::{err::{StatixErr, FixErr, SingleFixErr}, traits::WriteDiagnostic}; 9 + use crate::{ 10 + err::{FixErr, SingleFixErr, StatixErr}, 11 + traits::WriteDiagnostic, 12 + }; 10 13 11 14 use clap::Clap; 12 15 use config::{Opts, SubCommand}; ··· 17 20 match opts.cmd { 18 21 SubCommand::Check(check_config) => { 19 22 let vfs = check_config.vfs()?; 20 - let (lints, errors): (Vec<_>, Vec<_>) = vfs.iter().map(lint::lint).partition(Result::is_ok); 23 + let (lints, errors): (Vec<_>, Vec<_>) = 24 + vfs.iter().map(lint::lint).partition(Result::is_ok); 21 25 let lint_results = lints.into_iter().map(Result::unwrap); 22 26 let errors = errors.into_iter().map(Result::unwrap_err); 23 27 ··· 28 32 errors.for_each(|e| { 29 33 eprintln!("{}", e); 30 34 }); 31 - }, 35 + } 32 36 SubCommand::Fix(fix_config) => { 33 37 let vfs = fix_config.vfs()?; 34 38 for entry in vfs.iter() { ··· 40 44 println!( 41 45 "{}", 42 46 text_diff 43 - .unified_diff() 44 - .context_radius(4) 45 - .header(&old_file, &new_file) 46 - ); 47 + .unified_diff() 48 + .context_radius(4) 49 + .header(&old_file, &new_file) 50 + ); 47 51 } else { 48 52 let path = entry.file_path; 49 53 std::fs::write(path, &*fix_result.src).map_err(FixErr::InvalidPath)?; 50 54 } 51 55 } 52 56 } 53 - }, 57 + } 54 58 SubCommand::Single(single_config) => { 55 59 let path = single_config.target; 56 60 let src = std::fs::read_to_string(&path).map_err(SingleFixErr::InvalidPath)?; ··· 63 67 println!( 64 68 "{}", 65 69 text_diff 66 - .unified_diff() 67 - .context_radius(4) 68 - .header(&old_file, &new_file) 69 - ); 70 + .unified_diff() 71 + .context_radius(4) 72 + .header(&old_file, &new_file) 73 + ); 70 74 } else { 71 - std::fs::write(&path, &*single_fix_result.src).map_err(SingleFixErr::InvalidPath)?; 75 + std::fs::write(&path, &*single_fix_result.src) 76 + .map_err(SingleFixErr::InvalidPath)?; 72 77 } 73 78 } 74 79 }
+1 -1
flake.nix
··· 49 49 50 50 statix = with final; pkgs.stdenv.mkDerivation { 51 51 pname = "statix"; 52 - version = "v0.1.0"; 52 + version = "v0.2.0"; 53 53 src = builtins.path { 54 54 path = ./.; 55 55 name = "statix";
+1 -1
lib/Cargo.toml
··· 1 1 [package] 2 2 name = "lib" 3 - version = "0.1.0" 3 + version = "0.0.0" 4 4 edition = "2018" 5 5 6 6 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+4 -1
lib/src/lib.rs
··· 7 7 use std::{convert::Into, default::Default}; 8 8 9 9 #[cfg(feature = "json-out")] 10 - use serde::{Serialize, ser::{SerializeStruct, Serializer}}; 10 + use serde::{ 11 + ser::{SerializeStruct, Serializer}, 12 + Serialize, 13 + }; 11 14 12 15 /// Report generated by a lint 13 16 #[derive(Debug, Default)]
+1 -1
macros/Cargo.toml
··· 1 1 [package] 2 2 name = "macros" 3 - version = "0.1.0" 3 + version = "0.0.0" 4 4 edition = "2018" 5 5 6 6 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+10 -10
readme.md
··· 2 2 3 3 > Lints and suggestions for the Nix programming language. 4 4 5 - `statix` highlights antipatterns in Nix code. `statix --fix` 6 - can fix several such occurrences. 5 + `statix check` highlights antipatterns in Nix code. `statix 6 + fix` can fix several such occurrences. 7 7 8 8 For the time-being, `statix` works only with ASTs 9 9 produced by the `rnix-parser` crate and does not evaluate ··· 12 12 ## Examples 13 13 14 14 ```shell 15 - $ statix tests/c.nix 15 + $ statix check tests/c.nix 16 16 [W04] Warning: Assignment instead of inherit from 17 17 ╭─[tests/c.nix:2:3] 18 18 ··· 21 21 · ╰───────────────── This assignment is better written with inherit 22 22 ───╯ 23 23 24 - $ statix --fix --dry-run tests/c.nix 24 + $ statix fix --dry-run tests/c.nix 25 25 --- tests/c.nix 26 26 +++ tests/c.nix [fixed] 27 27 @@ -1,6 +1,6 @@ ··· 54 54 55 55 ```shell 56 56 # recursively finds nix files and raises lints 57 - statix /path/to/dir 57 + statix check /path/to/dir 58 58 59 59 # ignore generated files, such as Cargo.nix 60 - statix /path/to/dir -i '*Cargo.nix' 60 + statix check /path/to/dir -i '*Cargo.nix' 61 61 62 62 # see `statix -h` for a full list of options 63 63 ``` ··· 66 66 the source with: 67 67 68 68 ```shell 69 - statix --fix /path/to/file 69 + statix fix /path/to/file 70 70 71 71 # show diff, do not write to file 72 - statix --fix --dry-run /path/to/file 72 + statix fix --dry-run /path/to/file 73 73 ``` 74 74 75 75 `statix` supports a variety of output formats; standard, 76 76 json and errfmt: 77 77 78 78 ```shell 79 - statix /path/to/dir -o json 80 - statix /path/to/dir -o errfmt # singleline, easy to integrate with vim 79 + statix check /path/to/dir -o json # only when compiled with --all-features 80 + statix check /path/to/dir -o errfmt # singleline, easy to integrate with vim 81 81 ``` 82 82 83 83 ## Architecture
+1 -1
vfs/Cargo.toml
··· 1 1 [package] 2 2 name = "vfs" 3 - version = "0.1.0" 3 + version = "0.0.0" 4 4 edition = "2018" 5 5 6 6 [dependencies]