mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 21:23:56 +00:00
Suggest similar lint name on unknown_clippy_lints
This commit is contained in:
parent
0fcb5304e2
commit
5962fffcfe
1 changed files with 25 additions and 18 deletions
|
@ -18,6 +18,7 @@ use rustc_session::declare_tool_lint;
|
|||
use semver::Version;
|
||||
use syntax::ast::{AttrKind, AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem};
|
||||
use syntax::source_map::Span;
|
||||
use syntax::util::lev_distance::find_best_match_for_name;
|
||||
use syntax_pos::symbol::Symbol;
|
||||
|
||||
declare_clippy_lint! {
|
||||
|
@ -329,24 +330,30 @@ fn check_clippy_lint_names(cx: &LateContext<'_, '_>, items: &[NestedMetaItem]) {
|
|||
lint.span(),
|
||||
&format!("unknown clippy lint: clippy::{}", name),
|
||||
|db| {
|
||||
if name.as_str().chars().any(char::is_uppercase) {
|
||||
let name_lower = name.as_str().to_lowercase();
|
||||
match lint_store.check_lint_name(
|
||||
&name_lower,
|
||||
Some(tool_name.name)
|
||||
) {
|
||||
// FIXME: can we suggest similar lint names here?
|
||||
// https://github.com/rust-lang/rust/pull/56992
|
||||
CheckLintNameResult::NoLint(None) => (),
|
||||
_ => {
|
||||
let symbols = lint_store.get_lints().iter().map(
|
||||
|l| Symbol::intern(&l.name_lower())
|
||||
).collect::<Vec<_>>();
|
||||
let sugg = find_best_match_for_name(
|
||||
symbols.iter(),
|
||||
&format!("clippy::{}", name_lower),
|
||||
None,
|
||||
);
|
||||
if name.as_str().chars().any(char::is_uppercase)
|
||||
&& lint_store.find_lints(&format!("clippy::{}", name_lower)).is_ok() {
|
||||
db.span_suggestion(
|
||||
lint.span(),
|
||||
"lowercase the lint name",
|
||||
name_lower,
|
||||
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 a new issue