Skip to content

Commit

Permalink
Exclude reexport imports.
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongmao86 committed Jan 29, 2020
1 parent 4c63760 commit 9f62355
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
9 changes: 8 additions & 1 deletion clippy_lints/src/single_component_path_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ declare_clippy_lint! {
/// fn main() {
/// regex::Regex::new(r"^\d{4}-\d{2}-\d{2}$").unwrap();
/// }
///```
/// ```
/// Better as
/// ```rust, ignore
/// fn main() {
/// regex::Regex::new(r"^\d{4}-\d{2}-\d{2}$").unwrap();
/// }
/// ```
pub SINGLE_COMPONENT_PATH_IMPORTS,
style,
"imports with single component path are redundant"
Expand All @@ -34,6 +40,7 @@ impl EarlyLintPass for SingleComponentPathImports {
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
if_chain! {
if cx.sess.opts.edition == Edition::Edition2018;
if !item.vis.node.is_pub();
if let ItemKind::Use(use_tree) = &item.kind;
if let segments = &use_tree.prefix.segments;
if segments.len() == 1;
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/single_component_path_imports.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#![warn(clippy::single_component_path_imports)]


use serde as edres;
pub use serde;

fn main() {
regex::Regex::new(r"^\d{4}-\d{2}-\d{2}$").unwrap();
Expand Down
1 change: 1 addition & 0 deletions tests/ui/single_component_path_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use regex;
use serde as edres;
pub use serde;

fn main() {
regex::Regex::new(r"^\d{4}-\d{2}-\d{2}$").unwrap();
Expand Down

0 comments on commit 9f62355

Please sign in to comment.