nu-lint 0.0.52

Linter for Nu shell scripts that helpfully suggests improvements
Documentation

Nu-Lint

Linter for the innovative Nu shell.

Learning to use a new shell is a radical change that can use some assistance. This project is aimed at helping new users of the Nu shell. Nu shell has a lot of interesting and useful features and this program will give you hints to use all the features of Nu.

For example, the rule prefer_pipeline_input in this program recommends to use pipelines instead of positional arguments:

def filter-positive [numbers] { 
    $numbers | where $it > 0 
}
def filter-positive [] { 
    where $it > 0 
}

All rules are optional and can be disabled with a configuration file. The rule definitions are designed to be compatible with:

Installation

Cross-platform

From crates.io:

cargo install nu-lint

Source

Build from source:

cargo install --path .
cargo install --git . "$THIS_GIT_URL"

VS Code extension

Available at VS Code Marketplace.

Nix

To install in Nix or NixOS, add to configuration.nix:

let
  nu-lint = pkgs.callPackage (pkgs.fetchFromGitHub {
    owner = "wvhulle";
    repo = "nu-lint";
    rev = "COMMIT_HASH";
    sha256 = ""; # nix will tell you the correct hash
  }) {};
in
{
  environment.systemPackages = [
    nu-lint
  ];
}

Usage

Basic:

nu-lint                                    # Lint working directory
nu-lint script.nu                          # Lint a file
nu-lint directory/                         # Lint directory
'let x =' | nu-lint                   # Pipe in over stdin

Apply fixes (also works with STDIN):

nu-lint --fix --dry-run   # Test
nu-lint --fix             # Apply

Output formats:

nu-lint script.nu --format text            # Human-readable (default)
nu-lint script.nu --format lsp             # LSP-compatible JSON (recommended for editors)

The lsp format outputs diagnostics compatible with the Language Server Protocol (LSP 3.17), which is supported by most modern editors including VS Code, Neovim, Helix, Emacs, and Sublime Text.

Configuration

Show all rules:

nu-lint list-rules                         

Show all rule sets:

nu-lint list-sets

Create .nu-lint.toml in your project root (or any parent directory):

# Simple format - just list rules and sets with their levels
systemd_journal_prefix = "warn"
snake_case_variables = "deny"
naming = "deny"  # Apply deny level to all rules in the "naming" set

# Or use the structured format for more complex configs
[lints.sets]
performance = "warn"
type-safety = "deny"

[lints.rules]
prefer_pipeline_input = "deny"
max_function_body_length = "allow"

Available lint levels: allow, warn, deny.

The linter will automatically find and use this config file when you run it. Otherwise:

nu-lint --config custom.toml script.nu  

Rules

You can add, remove or change rules by forking this repo and opening a PR (see ./CONTRIBUTING.md).

License

MIT