Fix stutter lints

This commit is contained in:
Devon Hollowood 2018-10-11 15:36:40 -07:00
parent 9afd8abbe3
commit dcef9d0795
5 changed files with 28 additions and 27 deletions

View file

@ -40,6 +40,7 @@ declare_clippy_lint! {
"unnecessary double comparisons that can be simplified"
}
#[allow(clippy::stutter)]
pub struct DoubleComparisonPass;
impl LintPass for DoubleComparisonPass {

View file

@ -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()) {

View file

@ -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;

View file

@ -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);
}
}
}

View file

@ -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;