mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
perf(linter): use cow_to_ascii_lowercase/uppercase (#5637)
part of #5586 In addition, can a similar situation in the [formatter](https://github.com/oxc-project/oxc/blob/main/crates/oxc_prettier/src/format/mod.rs#L1406-L1409) be handled in this way?
This commit is contained in:
parent
0b3c1d72a3
commit
e3ae5dbb02
4 changed files with 10 additions and 4 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use cow_utils::CowUtils;
|
||||||
use oxc_ast::{ast::MemberExpression, AstKind};
|
use oxc_ast::{ast::MemberExpression, AstKind};
|
||||||
use oxc_diagnostics::OxcDiagnostic;
|
use oxc_diagnostics::OxcDiagnostic;
|
||||||
use oxc_macros::declare_oxc_lint;
|
use oxc_macros::declare_oxc_lint;
|
||||||
|
|
@ -235,7 +236,7 @@ fn is_jest_call(name: &str) -> bool {
|
||||||
//
|
//
|
||||||
// import { jest as Jest } from "@jest/globals";
|
// import { jest as Jest } from "@jest/globals";
|
||||||
// Jest.setTimeout
|
// Jest.setTimeout
|
||||||
name.to_ascii_lowercase().eq_ignore_ascii_case("jest")
|
name.cow_to_ascii_lowercase().eq_ignore_ascii_case("jest")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
use cow_utils::CowUtils;
|
||||||
use oxc_ast::{
|
use oxc_ast::{
|
||||||
ast::{match_member_expression, Expression},
|
ast::{match_member_expression, Expression},
|
||||||
AstKind,
|
AstKind,
|
||||||
|
|
@ -231,7 +232,9 @@ fn is_not_array(expr: &Expression, ctx: &LintContext) -> bool {
|
||||||
_ => return false,
|
_ => return false,
|
||||||
};
|
};
|
||||||
|
|
||||||
if ident.starts_with(|c: char| c.is_ascii_uppercase()) && ident.to_ascii_uppercase() != ident {
|
if ident.starts_with(|c: char| c.is_ascii_uppercase())
|
||||||
|
&& ident.cow_to_ascii_uppercase() != ident
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
use cow_utils::CowUtils;
|
||||||
use oxc_ast::{
|
use oxc_ast::{
|
||||||
ast::{JSXAttributeItem, JSXAttributeName},
|
ast::{JSXAttributeItem, JSXAttributeName},
|
||||||
AstKind,
|
AstKind,
|
||||||
|
|
@ -88,7 +89,7 @@ fn get_replacement(node: &str) -> Option<&'static str> {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let node_lower = node.to_ascii_lowercase();
|
let node_lower = node.cow_to_ascii_lowercase();
|
||||||
|
|
||||||
if node_lower == "utf-8" || node_lower == "utf8" {
|
if node_lower == "utf-8" || node_lower == "utf8" {
|
||||||
return Some("utf8");
|
return Some("utf8");
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
use std::{borrow::Cow, cmp::Ordering};
|
use std::{borrow::Cow, cmp::Ordering};
|
||||||
|
|
||||||
|
use cow_utils::CowUtils;
|
||||||
use oxc_ast::{
|
use oxc_ast::{
|
||||||
ast::{
|
ast::{
|
||||||
match_member_expression, Argument, CallExpression, Expression, IdentifierName,
|
match_member_expression, Argument, CallExpression, Expression, IdentifierName,
|
||||||
|
|
@ -255,7 +256,7 @@ fn parse_jest_jest_fn_call<'a>(
|
||||||
name: &'a str,
|
name: &'a str,
|
||||||
local: &'a str,
|
local: &'a str,
|
||||||
) -> Option<ParsedJestFnCall<'a>> {
|
) -> Option<ParsedJestFnCall<'a>> {
|
||||||
let lowercase_name = name.to_ascii_lowercase();
|
let lowercase_name = name.cow_to_ascii_lowercase();
|
||||||
|
|
||||||
if !(lowercase_name == "jest" || lowercase_name == "vi") {
|
if !(lowercase_name == "jest" || lowercase_name == "vi") {
|
||||||
return None;
|
return None;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue