Get rid of regex and lazy_static dependencies

This commit is contained in:
flip1995 2021-01-30 17:43:00 +01:00
parent 4db76a6bcc
commit 797cf6554d
No known key found for this signature in database
GPG key ID: 2CEFCDB27ED0BE79
2 changed files with 4 additions and 8 deletions

View file

@ -34,8 +34,6 @@ rustc-semver="1.1.0"
url = { version = "2.1.0", features = ["serde"] } url = { version = "2.1.0", features = ["serde"] }
quote = "1" quote = "1"
syn = { version = "1", features = ["full"] } syn = { version = "1", features = ["full"] }
regex = "1.4"
lazy_static = "1.4"
[features] [features]
deny-warnings = [] deny-warnings = []

View file

@ -1,8 +1,6 @@
use crate::utils::paths::STRING; use crate::utils::paths::STRING;
use crate::utils::{match_def_path, span_lint_and_help}; use crate::utils::{match_def_path, span_lint_and_help};
use if_chain::if_chain; use if_chain::if_chain;
use lazy_static::lazy_static;
use regex::Regex;
use rustc_ast::ast::LitKind; use rustc_ast::ast::LitKind;
use rustc_hir::{Expr, ExprKind, PathSegment}; use rustc_hir::{Expr, ExprKind, PathSegment};
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
@ -41,14 +39,14 @@ declare_clippy_lint! {
declare_lint_pass!(CaseSensitiveFileExtensionComparisons => [CASE_SENSITIVE_FILE_EXTENSION_COMPARISONS]); declare_lint_pass!(CaseSensitiveFileExtensionComparisons => [CASE_SENSITIVE_FILE_EXTENSION_COMPARISONS]);
fn check_case_sensitive_file_extension_comparison(ctx: &LateContext<'_>, expr: &Expr<'_>) -> Option<Span> { fn check_case_sensitive_file_extension_comparison(ctx: &LateContext<'_>, expr: &Expr<'_>) -> Option<Span> {
lazy_static! {
static ref RE: Regex = Regex::new(r"^\.([a-z0-9]{1,5}|[A-Z0-9]{1,5})$").unwrap();
}
if_chain! { if_chain! {
if let ExprKind::MethodCall(PathSegment { ident, .. }, _, [obj, extension, ..], span) = expr.kind; if let ExprKind::MethodCall(PathSegment { ident, .. }, _, [obj, extension, ..], span) = expr.kind;
if ident.as_str() == "ends_with"; if ident.as_str() == "ends_with";
if let ExprKind::Lit(Spanned { node: LitKind::Str(ext_literal, ..), ..}) = extension.kind; if let ExprKind::Lit(Spanned { node: LitKind::Str(ext_literal, ..), ..}) = extension.kind;
if RE.is_match(&ext_literal.as_str()); if (2..=6).contains(&ext_literal.as_str().len());
if ext_literal.as_str().starts_with('.');
if ext_literal.as_str().chars().skip(1).all(|c| c.is_uppercase() || c.is_digit(10))
|| ext_literal.as_str().chars().skip(1).all(|c| c.is_lowercase() || c.is_digit(10));
then { then {
let mut ty = ctx.typeck_results().expr_ty(obj); let mut ty = ctx.typeck_results().expr_ty(obj);
ty = match ty.kind() { ty = match ty.kind() {