a770fa5a5e5f
clap-error-message.yml
id: clap-error-message
language: rust
severity: error
message: clap error built from a string
note: |
Give the message a variant on a #[derive(thiserror::Error)] enum and pass the variant, e.g.
`cmd.error(ErrorKind::ArgumentConflict, UsageError::BridgeRoots)`. A string literal, format!,
.to_string() or a SCREAMING_CASE const keeps the message apart from the error's type.
rule:
any:
- pattern: $CMD.error($KIND, $MSG)
- pattern: Error::raw($KIND, $MSG)
- pattern: clap::Error::raw($KIND, $MSG)
constraints:
MSG:
any:
- kind: string_literal
- all:
- kind: macro_invocation
- regex: ^format!
- all:
- kind: identifier
- regex: ^[A-Z][A-Z0-9_]*$
- all:
- kind: call_expression
- regex: \.(to_string|to_owned)\(\)$|^String::from\(
No file is open. Choose one in the tree, or press Ctrl+O (⌘O on a Mac) to find one by name.
Syntax highlighting could not load. The unmodified read-only text remains available above.