GitCorner

Code

ossartcraftcadcraft🌐
a770fa5a5e5f
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\(