mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-28 17:53:56 +00:00
Suggest similar lint name on unknown_clippy_lints
This commit is contained in:
parent
0fcb5304e2
commit
5962fffcfe
@ -18,6 +18,7 @@ use rustc_session::declare_tool_lint;
|
|||||||
use semver::Version;
|
use semver::Version;
|
||||||
use syntax::ast::{AttrKind, AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem};
|
use syntax::ast::{AttrKind, AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem};
|
||||||
use syntax::source_map::Span;
|
use syntax::source_map::Span;
|
||||||
|
use syntax::util::lev_distance::find_best_match_for_name;
|
||||||
use syntax_pos::symbol::Symbol;
|
use syntax_pos::symbol::Symbol;
|
||||||
|
|
||||||
declare_clippy_lint! {
|
declare_clippy_lint! {
|
||||||
@ -329,24 +330,30 @@ fn check_clippy_lint_names(cx: &LateContext<'_, '_>, items: &[NestedMetaItem]) {
|
|||||||
lint.span(),
|
lint.span(),
|
||||||
&format!("unknown clippy lint: clippy::{}", name),
|
&format!("unknown clippy lint: clippy::{}", name),
|
||||||
|db| {
|
|db| {
|
||||||
if name.as_str().chars().any(char::is_uppercase) {
|
let name_lower = name.as_str().to_lowercase();
|
||||||
let name_lower = name.as_str().to_lowercase();
|
let symbols = lint_store.get_lints().iter().map(
|
||||||
match lint_store.check_lint_name(
|
|l| Symbol::intern(&l.name_lower())
|
||||||
&name_lower,
|
).collect::<Vec<_>>();
|
||||||
Some(tool_name.name)
|
let sugg = find_best_match_for_name(
|
||||||
) {
|
symbols.iter(),
|
||||||
// FIXME: can we suggest similar lint names here?
|
&format!("clippy::{}", name_lower),
|
||||||
// https://github.com/rust-lang/rust/pull/56992
|
None,
|
||||||
CheckLintNameResult::NoLint(None) => (),
|
);
|
||||||
_ => {
|
if name.as_str().chars().any(char::is_uppercase)
|
||||||
db.span_suggestion(
|
&& lint_store.find_lints(&format!("clippy::{}", name_lower)).is_ok() {
|
||||||
lint.span(),
|
db.span_suggestion(
|
||||||
"lowercase the lint name",
|
lint.span(),
|
||||||
name_lower,
|
"lowercase the lint name",
|
||||||
Applicability::MaybeIncorrect,
|
format!("clippy::{}", name_lower),
|
||||||
);
|
Applicability::MachineApplicable,
|
||||||
}
|
);
|
||||||
}
|
} else if let Some(sugg) = sugg {
|
||||||
|
db.span_suggestion(
|
||||||
|
lint.span(),
|
||||||
|
"did you mean",
|
||||||
|
sugg.to_string(),
|
||||||
|
Applicability::MachineApplicable,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user