Skip to content

Commit

Permalink
fixup! Rename lint and fix review issues, not done yet
Browse files Browse the repository at this point in the history
  • Loading branch information
DevinR528 committed Jun 22, 2021
1 parent 72e6ce7 commit b3dd177
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 14 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2657,7 +2657,7 @@ Released 2018-09-13
[`misrefactored_assign_op`]: https://rust-lang.github.io/rust-clippy/master/index.html#misrefactored_assign_op
[`missing_const_for_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_const_for_fn
[`missing_docs_in_private_items`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_docs_in_private_items
[`missing_enforced_import_rename`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_enforced_import_rename
[`missing_enforced_import_renames`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_enforced_import_renames
[`missing_errors_doc`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_errors_doc
[`missing_inline_in_public_items`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_inline_in_public_items
[`missing_panics_doc`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_panics_doc
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
misc_early::ZERO_PREFIXED_LITERAL,
missing_const_for_fn::MISSING_CONST_FOR_FN,
missing_doc::MISSING_DOCS_IN_PRIVATE_ITEMS,
missing_enforced_import_rename::MISSING_ENFORCED_IMPORT_RENAME,
missing_enforced_import_rename::MISSING_ENFORCED_IMPORT_RENAMES,
missing_inline::MISSING_INLINE_IN_PUBLIC_ITEMS,
modulo_arithmetic::MODULO_ARITHMETIC,
multiple_crate_versions::MULTIPLE_CRATE_VERSIONS,
Expand Down Expand Up @@ -1019,7 +1019,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
LintId::of(misc::FLOAT_CMP_CONST),
LintId::of(misc_early::UNNEEDED_FIELD_PATTERN),
LintId::of(missing_doc::MISSING_DOCS_IN_PRIVATE_ITEMS),
LintId::of(missing_enforced_import_rename::MISSING_ENFORCED_IMPORT_RENAME),
LintId::of(missing_enforced_import_rename::MISSING_ENFORCED_IMPORT_RENAMES),
LintId::of(missing_inline::MISSING_INLINE_IN_PUBLIC_ITEMS),
LintId::of(modulo_arithmetic::MODULO_ARITHMETIC),
LintId::of(panic_in_result_fn::PANIC_IN_RESULT_FN),
Expand Down
24 changes: 17 additions & 7 deletions clippy_lints/src/missing_enforced_import_rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ use crate::utils::conf::Rename;

declare_clippy_lint! {
/// **What it does:** Checks for imports that do not rename the item as specified
/// in the `import-renames` config option.
/// in the `enforce-import-renames` config option.
///
/// **Why is this bad?** Some item names are too vague outside of their defining scope.
/// **Why is this bad?** Consistency is important, if a project has defined import
/// renames they should be followed. More practically, some item names are too
/// vague outside of their defining scope this can enforce a more meaningful naming.
///
/// **Known problems:** None
///
Expand All @@ -32,7 +34,7 @@ declare_clippy_lint! {
/// ```rust,ignore
/// use serde_json::Value as JsonValue;
/// ```
pub MISSING_ENFORCED_IMPORT_RENAME,
pub MISSING_ENFORCED_IMPORT_RENAMES,
restriction,
"enforce import renames"
}
Expand All @@ -51,7 +53,7 @@ impl ImportRename {
}
}

impl_lint_pass!(ImportRename => [MISSING_ENFORCED_IMPORT_RENAME]);
impl_lint_pass!(ImportRename => [MISSING_ENFORCED_IMPORT_RENAMES]);

impl LateLintPass<'_> for ImportRename {
fn check_crate(&mut self, cx: &LateContext<'_>, _: &Crate<'_>) {
Expand All @@ -70,12 +72,20 @@ impl LateLintPass<'_> for ImportRename {
// Remove semicolon since it is not present for nested imports
let span_without_semi = cx.sess().source_map().span_until_char(item.span, ';');
if let Some(snip) = snippet_opt(cx, span_without_semi);
if !snip.trim_end().ends_with(&*name.as_str());
if let Some(import) = match snip.split_once(" as ") {
None => Some(snip.as_str()),
Some((import, rename)) => {
if rename.trim() == &*name.as_str() {
None
} else {
Some(import.trim())
}
},
};
then {
let import = snip.split(" as").next().unwrap_or(&snip);
span_lint_and_sugg(
cx,
MISSING_ENFORCED_IMPORT_RENAME,
MISSING_ENFORCED_IMPORT_RENAMES,
span_without_semi,
"this import should be renamed",
"try",
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/utils/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::error::Error;
use std::path::{Path, PathBuf};
use std::{env, fmt, fs, io};

/// Holds information used by `MISSING_ENFORCED_IMPORT_RENAME` lint.
/// Holds information used by `MISSING_ENFORCED_IMPORT_RENAMES` lint.
#[derive(Clone, Debug, Deserialize)]
pub struct Rename {
pub path: String,
Expand Down Expand Up @@ -210,7 +210,7 @@ define_Conf! {
(cargo_ignore_publish: bool = false),
/// Lint: NONSTANDARD_MACRO_BRACES. Enforce the named macros always use the braces specified. <br> A `MacroMatcher` can be added like so `{ name = "macro_name", brace = "(" }`. If the macro is could be used with a full path two `MacroMatcher`s have to be added one with the full path `crate_name::macro_name` and one with just the macro name.
(standard_macro_braces: Vec<crate::nonstandard_macro_braces::MacroMatcher> = Vec::new()),
/// Lint: MISSING_ENFORCED_IMPORT_RENAME. The list of imports to always rename, a fully qualified path followed by the rename.
/// Lint: MISSING_ENFORCED_IMPORT_RENAMES. The list of imports to always rename, a fully qualified path followed by the rename.
(enforced_import_renames: Vec<crate::utils::conf::Rename> = Vec::new()),
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![warn(clippy::missing_enforced_import_rename)]
#![warn(clippy::missing_enforced_import_renames)]

use std::alloc as colla;
use std::option::Option as Maybe;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error: this import should be renamed
LL | use std::process::{exit as wrong_exit, Child as Kid};
| ^^^^^^^^^^^^^^^^^^ help: try: `exit as goodbye`
|
= note: `-D clippy::missing-enforced-import-rename` implied by `-D warnings`
= note: `-D clippy::missing-enforced-import-renames` implied by `-D warnings`

error: this import should be renamed
--> $DIR/conf_missing_enforced_import_rename.rs:6:1
Expand Down

0 comments on commit b3dd177

Please sign in to comment.