• Stars
    star
    391
  • Rank 106,225 (Top 3 %)
  • Language
    Rust
  • License
    MIT License
  • Created over 2 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

lints and suggestions for the nix programming language

statix

Lints and suggestions for the Nix programming language.

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 any nix code (imports, attr sets etc.).

Examples

$ statix check tests/c.nix
[W04] Warning: Assignment instead of inherit from
   โ•ญโ”€[tests/c.nix:2:3]
   โ”‚
 2 โ”‚   mtl = pkgs.haskellPackages.mtl;
   ยท   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
   ยท                  โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ This assignment is better written with inherit
โ”€โ”€โ”€โ•ฏ

$ statix fix --dry-run tests/c.nix
--- tests/c.nix
+++ tests/c.nix [fixed]
@@ -1,6 +1,6 @@
 let
-  mtl = pkgs.haskellPackages.mtl;
+  inherit (pkgs.haskellPackages) mtl;
 in
 null

Installation

statix is available via a nix flake:

# build from source
nix build git+https://git.peppe.rs/languages/statix
./result/bin/statix --help

# statix also provides a flake app
nix run git+https://git.peppe.rs/languages/statix -- --help

# save time on builds using cachix
cachix use statix

Install from nixpkgs:

nix run nixpkgs#statix -- help

Install with brew/linuxbrew

brew install statix

Usage

Basic usage is as simple as:

# recursively finds nix files and raises lints
statix check /path/to/dir

# ignore generated files, such as Cargo.nix
statix check /path/to/dir -i Cargo.nix

# ignore more than one file
statix check /path/to/dir -i a.nix b.nix c.nix

# ignore an entire directory
statix check /path/to/dir -i .direnv

# statix respects your .gitignore if it exists
# run statix in "unrestricted" mode, to disable that
statix check /path/to/dir -u

# see `statix -h` for a full list of options

Certain lints have suggestions. Apply suggestions back to the source with:

statix fix /path/to/file

# show diff, do not write to file
statix fix --dry-run /path/to/file

statix supports a variety of output formats; standard, json and errfmt:

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

Configuration

Ignore lints and fixes by creating a statix.toml file at your project root:

# within statix.toml
disabled = [
  "empty_pattern"
]

statix automatically discovers the configuration file by traversing parents of the current directory and looking for a statix.toml file. Alternatively, you can pass the path to the statix.toml file on the command line with the --config flag (available on statix check and statix fix).

The available lints are (see statix list for an updated list):

bool_comparison
empty_let_in
manual_inherit
manual_inherit_from
legacy_let_syntax
collapsible_let_in
eta_reduction
useless_parens
empty_pattern
redundant_pattern_bind
unquoted_uri
deprecated_is_null
empty_inherit
faster_groupby
faster_zipattrswith
deprecated_to_path
bool_simplification
useless_has_attr

All lints are enabled by default. Generate a minimal config with statix dump > statix.toml.

TODO

  • Resolve imports and scopes for better lints
  • Add silent flag that exits with status

More Repositories

1

dijo

scriptable, curses-based, digital habit tracker
Rust
2,679
star
2

scientifica

tall, condensed, bitmap font for geeks
Vim Script
1,745
star
3

eva

a calculator REPL, similar to bc(1)
Rust
712
star
4

dotfiles

files that define my GNU/Linux box.
Vim Script
349
star
5

taizen

curses based mediawiki browser
Rust
285
star
6

pista

a simple {bash, zsh} prompt for programmers
Rust
193
star
7

curie

An upscaled version of scientifica.
178
star
8

fondant

macro based configuration management library
Rust
60
star
9

chestnut.vim

Minimal syntax highlighting for 16-color terminals.
Vim Script
31
star
10

nerdypepper.github.io

CSS
29
star
11

lotus

simple money and number formatting for rust
Rust
28
star
12

cutlass

experimental auto-currying for rust functions
Rust
27
star
13

site

my site and its generator
Shell
24
star
14

agila.vim

a port of the agila vs code colorscheme for vim
Vim Script
19
star
15

xcursorlocate

cursor location indicator for x11
Rust
16
star
16

lien

Screenshot / File uploader program
Shell
12
star
17

obi

the 1-bit image format
Rust
11
star
18

isostatic

minimal url shortner
Rust
8
star
19

nanoid

A single header nanoid implementation in C
C
6
star
20

aksh

an interactive shell
Rust
6
star
21

SongMonger

C++ program to view and play music
C++
6
star
22

orpheus

Read short stories in a super slick GUI
Rust
6
star
23

prompt

rewrite of pista with a fork of libps1
Rust
4
star
24

aoc

my solutions to AoC '19, in guile scheme
Scheme
3
star
25

unipack

vim plugin manager, for usage on outdated university PCs
Shell
3
star
26

website-theme

Pelican theme for my website
CSS
2
star
27

rt-bench

Rust
2
star
28

nixos

nerdypepper's nixos configuration (mirrored from git.peppe.rs)
Nix
2
star
29

conversations

nix flake to build conversations.im
Nix
2
star
30

rosetta-rs

a copy of my rust tasks for rosettacode.org
Rust
1
star
31

forma

format floating points to arbitrary bases
Rust
1
star
32

cursed_game

a curses based game-of-life universe
Rust
1
star
33

styles

CSS for some websites
CSS
1
star
34

spoiler

my solutions to problems on projecteuler.net
Rust
1
star
35

mush

an mpd repl
Rust
1
star