Add suggestion to use raw identifiers when fixing snake-case lints
This commit is contained in:
parent
b919aa4c0f
commit
91f436b456
1 changed files with 16 additions and 2 deletions
|
@ -275,10 +275,24 @@ impl NonSnakeCase {
|
||||||
// We have a valid span in almost all cases, but we don't have one when linting a crate
|
// We have a valid span in almost all cases, but we don't have one when linting a crate
|
||||||
// name provided via the command line.
|
// name provided via the command line.
|
||||||
if !ident.span.is_dummy() {
|
if !ident.span.is_dummy() {
|
||||||
|
let sc_ident = Ident::from_str_and_span(&sc, ident.span);
|
||||||
|
let (message, suggestion) = if sc_ident.is_reserved() {
|
||||||
|
// We shouldn't suggest a reserved identifier to fix non-snake-case identifiers.
|
||||||
|
// Instead, recommend renaming the identifier entirely or, if permitted,
|
||||||
|
// escaping it to create a raw identifier.
|
||||||
|
if sc_ident.name.can_be_raw() {
|
||||||
|
("rename the identifier or convert it to a snake case raw identifier", sc_ident.to_string())
|
||||||
|
} else {
|
||||||
|
("rename the identifier", String::new())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
("convert the identifier to snake case", sc)
|
||||||
|
};
|
||||||
|
|
||||||
err.span_suggestion(
|
err.span_suggestion(
|
||||||
ident.span,
|
ident.span,
|
||||||
"convert the identifier to snake case",
|
message,
|
||||||
sc,
|
suggestion,
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue