Lints and suggestions for the Nix programming language
1
fork

Configure Feed

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

flake build with json feature, add better usage docs

Akshay 781c42cc b09f1f95

+76 -33
+11 -11
flake.nix
··· 60 60 cargo 61 61 ]; 62 62 buildPhase = '' 63 - cargo build -p statix --release --offline 63 + cargo build -p statix --all-features --release --offline 64 64 ''; 65 + # statix does not have any tests currently 66 + doCheck = false; 65 67 installPhase = '' 66 68 install -Dm775 ./target/release/statix $out/bin/statix 67 69 ''; ··· 85 87 devShell = forAllSystems (system: 86 88 let 87 89 pkgs = nixpkgsFor.${system}; 88 - inherit (rustChannel pkgs) rust rust-src; 90 + inherit (rustChannel pkgs) rust rust-src rust-analysis; 89 91 in 90 92 with pkgs; 91 93 mkShell rec { 92 - buildInputs = 93 - [ 94 - rust-analyzer 95 - rustfmt 96 - cargo 97 - cargo-watch 98 - rust 99 - rust-src 100 - ]; 94 + buildInputs = [ 95 + rustfmt 96 + cargo 97 + cargo-watch 98 + rust 99 + rust-src 100 + ]; 101 101 RUST_SRC_PATH = "${rust-src}/lib/rustlib/src/rust/library"; 102 102 RUST_LOG = "info"; 103 103 RUST_BACKTRACE = 1;
+3
notes.txt
··· 37 37 - invalid or potentially risky string interpolations 38 38 - useless parens in infix exprs 39 39 - unused function params 40 + - manual map over list 41 + - merge inherit 42 + - merge inherit-from 40 43 41 44 Extensions 42 45 ----------
+62 -22
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` 5 + `statix` highlights antipatterns in Nix code. `statix --fix` 6 6 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 10 10 any nix code (imports, attr sets etc.). 11 11 12 - ## Installation 12 + ## Examples 13 13 14 - `statix` is available via a nix flake: 14 + ```shell 15 + $ statix tests/c.nix 16 + [W04] Warning: Assignment instead of inherit from 17 + ╭─[tests/c.nix:2:3] 18 + 19 + 2 │ mtl = pkgs.haskellPackages.mtl; 20 + · ───────────────┬─────────────── 21 + · ╰───────────────── This assignment is better written with inherit 22 + ───╯ 15 23 24 + $ statix --fix --dry-run tests/c.nix 25 + --- tests/c.nix 26 + +++ tests/c.nix [fixed] 27 + @@ -1,6 +1,6 @@ 28 + let 29 + - mtl = pkgs.haskellPackages.mtl; 30 + + inherit (pkgs.haskellPackages) mtl; 31 + in 32 + null 16 33 ``` 17 - nix run git+https://git.peppe.rs/languages/statix 18 34 19 - # or 35 + ## Installation 36 + 37 + `statix` is available via a nix flake: 20 38 39 + ```shell 40 + # build from source 21 41 nix build git+https://git.peppe.rs/languages/statix 22 42 ./result/bin/statix --help 43 + 44 + # statix also provides a flake app 45 + nix run git+https://git.peppe.rs/languages/statix -- --help 46 + 47 + # save time on builds using cachix 48 + cachix use statix 23 49 ``` 24 50 25 51 ## Usage 26 52 27 - ``` 28 - statix 0.1.0 53 + Basic usage is as simple as: 29 54 30 - Akshay <nerdy@peppe.rs> 55 + ```shell 56 + # recursively finds nix files and raises lints 57 + statix /path/to/dir 31 58 32 - Lints and suggestions for the Nix programming language 59 + # ignore generated files, such as Cargo.nix 60 + statix /path/to/dir -i '*Cargo.nix' 33 61 34 - USAGE: 35 - statix [FLAGS] [OPTIONS] [--] [TARGET] 62 + # see `statix -h` for a full list of options 63 + ``` 36 64 37 - ARGS: 38 - <TARGET> File or directory to run statix on [default: .] 65 + Certain lints have suggestions. Apply suggestions back to 66 + the source with: 39 67 40 - FLAGS: 41 - -d, --dry-run Do not fix files in place, display a diff instead 42 - -f, --fix Find and fix issues raised by statix 43 - -h, --help Print help information 44 - -V, --version Print version information 68 + ```shell 69 + statix --fix /path/to/file 45 70 46 - OPTIONS: 47 - -i, --ignore <IGNORE>... Globs of file patterns to skip 48 - -o, --format <FORMAT> Output format. Supported values: errfmt, json (on feature flag only) 71 + # show diff, do not write to file 72 + statix --fix --dry-run /path/to/file 73 + ``` 74 + 75 + `statix` supports a variety of output formats; standard, 76 + json and errfmt: 77 + 78 + ```shell 79 + statix /path/to/dir -o json 80 + statix /path/to/dir -o errfmt # singleline, easy to integrate with vim 49 81 ``` 50 82 51 83 ## Architecture ··· 55 87 - `bin`: the CLI/entrypoint 56 88 - `lib`: library of lints and utilities to define these 57 89 lints 90 + - `vfs`: virtual filesystem 58 91 - `macros`: procedural macros to help define a lint 59 92 60 93 ### `bin` ··· 70 103 those lints. It should be easy for newcomers to write lints 71 104 without being familiar with the rest of the codebase. 72 105 106 + ### `vfs` 107 + 108 + VFS is an in-memory filesystem. It provides cheap-to-copy 109 + handles (`FileId`s) to access paths and file contents. 110 + 73 111 ### `macros` 74 112 75 113 This crate intends to be a helper layer to declare lints and ··· 79 117 80 118 - Offline documentation for each lint 81 119 - Test suite for lints and suggestions 82 - - Output singleline/errfmt + vim plugin 120 + - Vim plugin (qf list population, apply suggestions) 121 + - Resolve imports and scopes for better lints 122 + - Add silent flag that exits with status