rust-lang / rust-clippy

A bunch of lints to catch common mistakes and improve your Rust code. Book: https://doc.rust-lang.org/clippy/
https://rust-lang.github.io/rust-clippy/
Other
11.48k stars 1.55k forks source link

Look for more lints in `credo` #1026

Open Manishearth opened 8 years ago

Manishearth commented 8 years ago

https://github.com/rrrene/credo has a bunch of lints for Elixir, we may be able to write similar ones.

killercup commented 8 years ago

Today, I infiltrated the local Elixir meetup (memo to self: buy killercup.ninja domain); there was a talk about the linting tool Credo by its main author, @rrrene. Credo has some pretty interesting features, e.g. extended error messages, and consistency checks.

Extended error messages

Does clippy plan showing longer lint descriptions in the CLI? There are already docs for each lint, and I think I saw an issue about cargo clippy --explain (or something like that) once. Rene stressed that his goal was to write nice, friendly explanations, that are more like guides to writing good Elixir code than lists of stuff that is considered wrong. Additionally, those extended explainations are also specific to an error you encounter, i.e. they show snippets of your code (and not some random example). Interestingly, this is also something that this post on rustc's new error format mentions—which was published during that meetup!

Consistency checks

Clippy has a lint to find enum variants that end with a redundant suffix, because it's considered bad practice in Rust. Credo instead has a lint for consistent pre/suffixes: If you have the exception types UserError, RequestError, and InvalidDateFormat, it will suggest you change the last one to DateFormatError (IIRC).

There are also consistency checks for code style, but this is something better suited for rustfmt.

Categories and priorities

In credo, lints are in one of five categories: Consistency, Readability, Refactoring Opportunities, Software Design, or Warnings. In addition to that, each lint has a priority and credos exit code is basically the sum of all the matched lints' priorities.

I don't think this is a good fit for clippy, as it will probably want to stay with rustc's lint levels—but it's a bunch of nice category names to keep in mind.

sanxiyn commented 5 years ago

Update: Clippy adopted these categories: Complexity, Correctness, Pedantic, Nursery, Style, Perf, Cargo, Deprecated, Restriction.