Skip to content

Commit e3ae5db

Browse files
authoredSep 9, 2024··
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?
1 parent 0b3c1d7 commit e3ae5db

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed
 

‎crates/oxc_linter/src/rules/jest/no_confusing_set_timeout.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::collections::HashMap;
22

3+
use cow_utils::CowUtils;
34
use oxc_ast::{ast::MemberExpression, AstKind};
45
use oxc_diagnostics::OxcDiagnostic;
56
use oxc_macros::declare_oxc_lint;
@@ -235,7 +236,7 @@ fn is_jest_call(name: &str) -> bool {
235236
//
236237
// import { jest as Jest } from "@jest/globals";
237238
// Jest.setTimeout
238-
name.to_ascii_lowercase().eq_ignore_ascii_case("jest")
239+
name.cow_to_ascii_lowercase().eq_ignore_ascii_case("jest")
239240
}
240241

241242
#[test]

‎crates/oxc_linter/src/rules/unicorn/prefer_spread.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use cow_utils::CowUtils;
12
use oxc_ast::{
23
ast::{match_member_expression, Expression},
34
AstKind,
@@ -231,7 +232,9 @@ fn is_not_array(expr: &Expression, ctx: &LintContext) -> bool {
231232
_ => return false,
232233
};
233234

234-
if ident.starts_with(|c: char| c.is_ascii_uppercase()) && ident.to_ascii_uppercase() != ident {
235+
if ident.starts_with(|c: char| c.is_ascii_uppercase())
236+
&& ident.cow_to_ascii_uppercase() != ident
237+
{
235238
return true;
236239
}
237240

‎crates/oxc_linter/src/rules/unicorn/text_encoding_identifier_case.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use cow_utils::CowUtils;
12
use oxc_ast::{
23
ast::{JSXAttributeItem, JSXAttributeName},
34
AstKind,
@@ -88,7 +89,7 @@ fn get_replacement(node: &str) -> Option<&'static str> {
8889
return None;
8990
}
9091

91-
let node_lower = node.to_ascii_lowercase();
92+
let node_lower = node.cow_to_ascii_lowercase();
9293

9394
if node_lower == "utf-8" || node_lower == "utf8" {
9495
return Some("utf8");

‎crates/oxc_linter/src/utils/jest/parse_jest_fn.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::{borrow::Cow, cmp::Ordering};
22

3+
use cow_utils::CowUtils;
34
use oxc_ast::{
45
ast::{
56
match_member_expression, Argument, CallExpression, Expression, IdentifierName,
@@ -255,7 +256,7 @@ fn parse_jest_jest_fn_call<'a>(
255256
name: &'a str,
256257
local: &'a str,
257258
) -> Option<ParsedJestFnCall<'a>> {
258-
let lowercase_name = name.to_ascii_lowercase();
259+
let lowercase_name = name.cow_to_ascii_lowercase();
259260

260261
if !(lowercase_name == "jest" || lowercase_name == "vi") {
261262
return None;

0 commit comments

Comments
 (0)
Please sign in to comment.