mirror of
https://github.com/nerdypepper/statix.git
synced 2024-10-05 17:58:08 +03:00
set internal crates to 0.0.0, bump to v0.2.0
This commit is contained in:
parent
393c285662
commit
20d195988d
8
Cargo.lock
generated
8
Cargo.lock
generated
@ -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",
|
||||
]
|
||||
|
@ -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
|
||||
|
@ -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"),
|
||||
}
|
||||
}
|
||||
|
@ -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)]
|
||||
|
@ -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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<Vec<Report>, 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,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,11 @@ pub struct SingleFixResult<'δ> {
|
||||
|
||||
fn pos_to_byte(line: usize, col: usize, src: &str) -> Result<TextSize, SingleFixErr> {
|
||||
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<Report, SingleFixErr> {
|
||||
} else {
|
||||
None
|
||||
}
|
||||
},
|
||||
_ => None
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
.flatten()
|
||||
.next()
|
||||
@ -60,7 +64,5 @@ pub fn single(line: usize, col: usize, src: &str) -> Result<SingleFixResult, Sin
|
||||
|
||||
report.apply(src.to_mut());
|
||||
|
||||
Ok(SingleFixResult {
|
||||
src
|
||||
})
|
||||
Ok(SingleFixResult { src })
|
||||
}
|
||||
|
@ -6,7 +6,10 @@ mod traits;
|
||||
|
||||
use std::io;
|
||||
|
||||
use crate::{err::{StatixErr, FixErr, SingleFixErr}, traits::WriteDiagnostic};
|
||||
use crate::{
|
||||
err::{FixErr, SingleFixErr, StatixErr},
|
||||
traits::WriteDiagnostic,
|
||||
};
|
||||
|
||||
use clap::Clap;
|
||||
use config::{Opts, SubCommand};
|
||||
@ -17,7 +20,8 @@ fn _main() -> 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)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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";
|
||||
|
@ -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
|
||||
|
@ -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)]
|
||||
|
@ -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
|
||||
|
20
readme.md
20
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
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "vfs"
|
||||
version = "0.1.0"
|
||||
version = "0.0.0"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
|
Loading…
Reference in New Issue
Block a user