From dcef9d07952eae2a2fbfe8f01e3885352c4ce8fb Mon Sep 17 00:00:00 2001 From: Devon Hollowood Date: Thu, 11 Oct 2018 15:36:40 -0700 Subject: [PATCH] Fix `stutter` lints --- clippy_lints/src/double_comparison.rs | 1 + clippy_lints/src/enum_variants.rs | 12 ++++----- clippy_lints/src/question_mark.rs | 1 + clippy_lints/src/utils/camel_case.rs | 38 +++++++++++++-------------- clippy_lints/src/utils/mod.rs | 3 +-- 5 files changed, 28 insertions(+), 27 deletions(-) diff --git a/clippy_lints/src/double_comparison.rs b/clippy_lints/src/double_comparison.rs index 3710301c8..314ca41ba 100644 --- a/clippy_lints/src/double_comparison.rs +++ b/clippy_lints/src/double_comparison.rs @@ -40,6 +40,7 @@ declare_clippy_lint! { "unnecessary double comparisons that can be simplified" } +#[allow(clippy::stutter)] pub struct DoubleComparisonPass; impl LintPass for DoubleComparisonPass { diff --git a/clippy_lints/src/enum_variants.rs b/clippy_lints/src/enum_variants.rs index 3454eff08..16d1e4048 100644 --- a/clippy_lints/src/enum_variants.rs +++ b/clippy_lints/src/enum_variants.rs @@ -16,7 +16,7 @@ use crate::syntax::ast::*; use crate::syntax::source_map::Span; use crate::syntax::symbol::LocalInternedString; use crate::utils::{span_help_and_lint, span_lint}; -use crate::utils::{camel_case_from, camel_case_until, in_macro}; +use crate::utils::{camel_case, in_macro}; /// **What it does:** Detects enumeration variants that are prefixed or suffixed /// by the same characters. @@ -184,19 +184,19 @@ fn check_variant( } } let first = var2str(&def.variants[0]); - let mut pre = &first[..camel_case_until(&*first)]; - let mut post = &first[camel_case_from(&*first)..]; + let mut pre = &first[..camel_case::until(&*first)]; + let mut post = &first[camel_case::from(&*first)..]; for var in &def.variants { let name = var2str(var); let pre_match = partial_match(pre, &name); pre = &pre[..pre_match]; - let pre_camel = camel_case_until(pre); + let pre_camel = camel_case::until(pre); pre = &pre[..pre_camel]; while let Some((next, last)) = name[pre.len()..].chars().zip(pre.chars().rev()).next() { if next.is_lowercase() { let last = pre.len() - last.len_utf8(); - let last_camel = camel_case_until(&pre[..last]); + let last_camel = camel_case::until(&pre[..last]); pre = &pre[..last_camel]; } else { break; @@ -206,7 +206,7 @@ fn check_variant( let post_match = partial_rmatch(post, &name); let post_end = post.len() - post_match; post = &post[post_end..]; - let post_camel = camel_case_from(post); + let post_camel = camel_case::from(post); post = &post[post_camel..]; } let (what, value) = match (pre.is_empty(), post.is_empty()) { diff --git a/clippy_lints/src/question_mark.rs b/clippy_lints/src/question_mark.rs index 0ec57e0be..93a40e135 100644 --- a/clippy_lints/src/question_mark.rs +++ b/clippy_lints/src/question_mark.rs @@ -44,6 +44,7 @@ declare_clippy_lint!{ "checks for expressions that could be replaced by the question mark operator" } +#[allow(clippy::stutter)] #[derive(Copy, Clone)] pub struct QuestionMarkPass; diff --git a/clippy_lints/src/utils/camel_case.rs b/clippy_lints/src/utils/camel_case.rs index 2b60e2c32..5ce1e08d8 100644 --- a/clippy_lints/src/utils/camel_case.rs +++ b/clippy_lints/src/utils/camel_case.rs @@ -10,7 +10,7 @@ /// Return the index of the character after the first camel-case component of /// `s`. -pub fn camel_case_until(s: &str) -> usize { +pub fn until(s: &str) -> usize { let mut iter = s.char_indices(); if let Some((_, first)) = iter.next() { if !first.is_uppercase() { @@ -43,7 +43,7 @@ pub fn camel_case_until(s: &str) -> usize { } /// Return index of the last camel-case component of `s`. -pub fn camel_case_from(s: &str) -> usize { +pub fn from(s: &str) -> usize { let mut iter = s.char_indices().rev(); if let Some((_, first)) = iter.next() { if !first.is_lowercase() { @@ -73,52 +73,52 @@ pub fn camel_case_from(s: &str) -> usize { #[cfg(test)] mod test { - use super::{camel_case_from, camel_case_until}; + use super::{from, until}; #[test] fn from_full() { - assert_eq!(camel_case_from("AbcDef"), 0); - assert_eq!(camel_case_from("Abc"), 0); + assert_eq!(from("AbcDef"), 0); + assert_eq!(from("Abc"), 0); } #[test] fn from_partial() { - assert_eq!(camel_case_from("abcDef"), 3); - assert_eq!(camel_case_from("aDbc"), 1); + assert_eq!(from("abcDef"), 3); + assert_eq!(from("aDbc"), 1); } #[test] fn from_not() { - assert_eq!(camel_case_from("AbcDef_"), 7); - assert_eq!(camel_case_from("AbcDD"), 5); + assert_eq!(from("AbcDef_"), 7); + assert_eq!(from("AbcDD"), 5); } #[test] fn from_caps() { - assert_eq!(camel_case_from("ABCD"), 4); + assert_eq!(from("ABCD"), 4); } #[test] fn until_full() { - assert_eq!(camel_case_until("AbcDef"), 6); - assert_eq!(camel_case_until("Abc"), 3); + assert_eq!(until("AbcDef"), 6); + assert_eq!(until("Abc"), 3); } #[test] fn until_not() { - assert_eq!(camel_case_until("abcDef"), 0); - assert_eq!(camel_case_until("aDbc"), 0); + assert_eq!(until("abcDef"), 0); + assert_eq!(until("aDbc"), 0); } #[test] fn until_partial() { - assert_eq!(camel_case_until("AbcDef_"), 6); - assert_eq!(camel_case_until("CallTypeC"), 8); - assert_eq!(camel_case_until("AbcDD"), 3); + assert_eq!(until("AbcDef_"), 6); + assert_eq!(until("CallTypeC"), 8); + assert_eq!(until("AbcDD"), 3); } #[test] fn until_caps() { - assert_eq!(camel_case_until("ABCD"), 0); + assert_eq!(until("ABCD"), 0); } -} \ No newline at end of file +} diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 2a9b1cb0a..05356f8d3 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -33,8 +33,7 @@ use crate::syntax::source_map::{Span, DUMMY_SP}; use crate::syntax::errors::DiagnosticBuilder; use crate::syntax::symbol::keywords; -mod camel_case; -pub use self::camel_case::{camel_case_from, camel_case_until}; +pub mod camel_case; pub mod comparisons; pub mod conf;