Crates.io | splint |
lib.rs | splint |
version | 1.1.0 |
source | src |
created_at | 2024-05-20 12:58:20.556943 |
updated_at | 2024-05-28 06:16:02.050201 |
description | Custom Rust Linting |
homepage | https://github.com/tascord/splint |
repository | https://github.com/tascord/splint |
max_upload_size | |
id | 1245704 |
size | 113,036 |
# Install Splint
cargo install splint
# Run splint
splint [-r <rules.(json|toml)>] src/**/*.rs # Splint only works on rust files
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"
],
// ...
}
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", ")"]
]