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