I would like to create some custom lints for crates I'm planning on writing, how/where would you recommend creating them?
Clippy might not be the best place since the lints don't apply to general Rust code, but just to code using my crates. Rustc plugins are apparently deprecated and shortly going to be removed. rust-analyzer is apparently not a reliable place to lint for things that require knowing types and not just syntax.
I believe it's technically possible via compiler plugins as you noted (I haven't heard that they'll be removed). Aside from that, I'm not aware of anything. Any approach would take a very large amount of effort, regardless.
// lib.rs
use my_lint::abort_not_assigned;
#[abort_not_assigned]
pub fn will_abort() -> i32 {
let x: i32;
x = 5;
x
}
#[abort_not_assigned]
pub fn will_not_abort() -> i32 {
let x = 5;
x
}
There are some drawbacks however:
From what I gather there is currently no other option than emitting a hard error, so this is a pretty hardcore linter
All functions that you want linted need to be annotated with #[abort_not_assigned]
The linting is only based on syntax, not semantics, so this approach is very limited