rust-lang / rust-lang/rust-clippy

Warn if error message doesn't conform to style guideline

Open
#8,172 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-lint
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

What it does

According to the Rust API Guidelines:

The error message given by the Display representation of an error type should be lowercase without trailing punctuation, and typically concise.

Clippy could make sure that error message are lowercase without trailing punctuation, by checking

  • the Display impl on types that have an Error impl
  • .ok_or("error message"), .map_err(|_| "error message") and similar methods
Lint Name

misformatted_error_message

Category

style

Advantage

An error message that conforms to the official guidelines fits more easily into the ecosystem

Drawbacks

No response

Example
.ok_or_else(|| format!("Unknown wifescore or grade `{}`!", threshold_str))?

Could be written as:

.ok_or_else(|| format!("unknown wifescore or grade `{}`", threshold_str))?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Display impl and Error impl cases, then examine the ok_or, map_err, and ok_or_else examples described in the issue. Define the lint's supported error-message forms and verify that it identifies messages that are not lowercase or that have trailing punctuation, while accepting conforming messages.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.