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 and intermediate users of the Nu shell. Nu shell has a lot of useful features not found in other scripting languages. This linter will give you hints to use all of them and even offer automatic fixes.
All rules are optional and can be disabled with a configuration file. The rule definitions are designed to be compatible with:
- The standard Nu parser nu-check.
- The standard Nu formatter topiary-nushell.
Example
The rule prefer_pipeline_input recommends to use pipelines instead of positional arguments:
def filter-positive [numbers] {
$numbers | where $it > 0
}
def filter-positive [] {
where $it > 0
}
This rule in particular encourages you to use lazy pipeline input. When you evaluate a traditional positional list argument, the whole list is processed at once, but when you use implicit pipeline input (by starting the function body with where), the list processed lazily (without loading the list in memory completely at once).
Installation
From crates.io:
Source
Build from source:
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
];
}
Editor extension
VS Code extension
Available at VS Code Marketplace.
Helix
Add to your ~/.config/helix/languages.toml:
[]
= "nu-lint"
= ["lsp"]
[[]]
= "nu"
= ["nu-lint"]
Other
You can also implement your own editor extensions using the lsp subcommand as in: nu-lint lsp. This will spawn a language server compliant with the Language Server Protocol.
CLI usage
Run this linter from the command-line with:
|
Apply automatic fixes:
|
Configuration
Show all rules:
Show all rule groups:
Create .nu-lint.toml in your project root (or any parent directory):
# Simple format - just list rules and sets with their levels
= "warn"
= "deny"
= "deny" # Apply deny level to all rules in the "naming" set
# Or use the structured format for more complex configs
[]
= "warn"
= "deny"
[]
= "deny"
= "allow"
Available lint levels: allow, warn, deny.
The linter will automatically find and use this config file when you run it. Otherwise:
Rules
You can add, remove or change rules by forking this repo and opening a PR (see ./CONTRIBUTING.md).
License
MIT