splint

Crates.iosplint
lib.rssplint
version1.1.0
sourcesrc
created_at2024-05-20 12:58:20.556943
updated_at2024-05-28 06:16:02.050201
descriptionCustom Rust Linting
homepagehttps://github.com/tascord/splint
repositoryhttps://github.com/tascord/splint
max_upload_size
id1245704
size113,036
flora ~ 🏳️‍⚧️ ❤ 🦀 (tascord)

documentation

README

Powered: by Black Magic Crates.io Version GitHub Actions Workflow Status

Custom Rust Linting

Cli Usage

# Install Splint
cargo install splint

# Run splint
splint [-r <rules.(json|toml)>] src/**/*.rs # Splint only works on rust files

Integration with Rust Analyzer

Add the following to your settings.json file in vscode or equivalent.
Add -r <path> if you have a non-standard rules file (see below).

{
    // ...
    "rust-analyzer.check.overrideCommand": [
        "splint",
        "-qa",
        "**/*.rs"
    ],
    "rust-analyzer.cargo.buildScripts.overrideCommand": [
    
        "splint",
        "-qa",
        "**/*.rs"
    ],
    // ...
}

Rules

The following rule looks for a sequence of .unwrap() anywhere in the file.
You don't need to worry about whitespace, as it uses a parsed stream of tokens from proc_macro2.
If no rules file is provided, splint will look for a .splint.(json|toml) or splint.(json|toml) file in the cwd.

// JSON
{
    "rules": {
        "Disallow Unwrap": {
        /* The name of your lint  */                        "name": "Disallow Unwrap",
        /* Reasoning for the lint */                        "description": "`.unwrap()` should be discouraged where possible, as it leads to less than usefull panics.",
        /* (optional) Describe a fix or alternative */      "help": "Favour '?' for Results, or handling with unwrap_or(). At the least give some diagnostics with .expect()",
        /* (optional) Link to more information */           "more": "https://doc.rust-lang.org/std/result/enum.Result.html#method.unwrap",
        /* Whether or not this lint should panic*/          "fails": false,
        /* A replacement for the match */                   "replace": ".expect(\"...\")",
        /* The inclusive range highlighted */               "range": [0, 3], // In this case . -> )
        /* Type/Value matching */                           "pattern": [
        /* Type is one of Punct/Ident/Delim */                  ["Punct", "."],
        /* Where Punctuation handles punctuation, */            ["Ident", "unwrap"],
        /* Delim brackets, and Ident other strings/ */          ["Delim", "("],
        /* Regex in value is defined by surrounding '/' */      ["Delim", ")"]
        /* The value can also be `null` */                  ]
        }
    }
}
# TOML
[rules."Disallow Unwrap"]
name = "Disallow Unwrap"
description = "`.unwrap()` should be discouraged where possible, as it leads to less than usefull panics."
help = "Favour '?' for Results, or handling with unwrap_or(). At the least give some diagnostics with .expect()"
fails = false
range = [0, 3]
pattern = [
    ["Punct", "."],
    ["Ident", "unwrap"],
    ["Delim", "("],
    ["Delim", ")"]
]

Thanks

Commit count: 14

cargo fmt