From 2077ff9269c9f1274fecaf5be9f68a8ca998ff54 Mon Sep 17 00:00:00 2001 From: Boshen <1430279+Boshen@users.noreply.github.com> Date: Wed, 27 Nov 2024 13:28:13 +0000 Subject: [PATCH] refactor(linter): remove `once_cell` (#7510) --- Cargo.lock | 1 - Cargo.toml | 1 - crates/oxc_linter/Cargo.toml | 1 - .../src/rules/jsx_a11y/prefer_tag_over_role.rs | 13 +++++++------ .../src/rules/react/no_unknown_property.rs | 10 +++++----- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c27aeae87..0a8690882 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1712,7 +1712,6 @@ dependencies = [ "memchr", "mime_guess", "nonmax", - "once_cell", "oxc_allocator", "oxc_ast", "oxc_cfg", diff --git a/Cargo.toml b/Cargo.toml index 352da0349..5e5727c47 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -165,7 +165,6 @@ mime_guess = "2.0.5" nonmax = "0.5.5" num-bigint = "0.4.6" num-traits = "0.2.19" -once_cell = "1.20.2" oxc-browserslist = "1.1.0" oxc_index = "1.0.0" oxc_resolver = "2.0.0" diff --git a/crates/oxc_linter/Cargo.toml b/crates/oxc_linter/Cargo.toml index 736656e2d..082c5e94b 100644 --- a/crates/oxc_linter/Cargo.toml +++ b/crates/oxc_linter/Cargo.toml @@ -49,7 +49,6 @@ lazy_static = { workspace = true } memchr = { workspace = true } mime_guess = { workspace = true } nonmax = { workspace = true } -once_cell = { workspace = true } phf = { workspace = true, features = ["macros"] } rayon = { workspace = true } regex = { workspace = true } diff --git a/crates/oxc_linter/src/rules/jsx_a11y/prefer_tag_over_role.rs b/crates/oxc_linter/src/rules/jsx_a11y/prefer_tag_over_role.rs index e2c1a94a7..1566bd185 100644 --- a/crates/oxc_linter/src/rules/jsx_a11y/prefer_tag_over_role.rs +++ b/crates/oxc_linter/src/rules/jsx_a11y/prefer_tag_over_role.rs @@ -1,4 +1,6 @@ -use once_cell::sync::Lazy; +use lazy_static::lazy_static; +use phf::phf_map; + use oxc_ast::{ ast::{JSXAttributeItem, JSXAttributeValue}, AstKind, @@ -6,7 +8,6 @@ use oxc_ast::{ use oxc_diagnostics::OxcDiagnostic; use oxc_macros::declare_oxc_lint; use oxc_span::Span; -use phf::phf_map; use crate::{ context::LintContext, @@ -78,16 +79,16 @@ impl PreferTagOverRole { } } -static ROLE_TO_TAG_MAP: Lazy> = Lazy::new(|| { - phf_map! { +lazy_static! { + static ref ROLE_TO_TAG_MAP: phf::Map<&'static str, &'static str> = phf_map! { "checkbox" => "input", "button" => "button", "heading" => "h1,h2,h3,h4,h5,h6", "link" => "a,area", "rowgroup" => "tbody,tfoot,thead", "banner" => "header", - } -}); + }; +} impl Rule for PreferTagOverRole { fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) { diff --git a/crates/oxc_linter/src/rules/react/no_unknown_property.rs b/crates/oxc_linter/src/rules/react/no_unknown_property.rs index 3f8ffadfa..049486862 100644 --- a/crates/oxc_linter/src/rules/react/no_unknown_property.rs +++ b/crates/oxc_linter/src/rules/react/no_unknown_property.rs @@ -2,7 +2,7 @@ use std::borrow::Cow; use cow_utils::CowUtils; use itertools::Itertools; -use once_cell::sync::Lazy; +use lazy_static::lazy_static; use oxc_ast::{ ast::{JSXAttributeItem, JSXAttributeName, JSXElementName}, AstKind, @@ -425,12 +425,12 @@ const DOM_PROPERTIES_IGNORE_CASE: [&str; 5] = [ "webkitDirectory", ]; -static DOM_PROPERTIES_LOWER_MAP: Lazy> = Lazy::new(|| { - DOM_PROPERTIES_NAMES +lazy_static! { + static ref DOM_PROPERTIES_LOWER_MAP: FxHashMap = DOM_PROPERTIES_NAMES .iter() .map(|it| (it.cow_to_lowercase().into_owned(), *it)) - .collect::>() -}); + .collect::>(); +} /// Checks if an attribute name is a valid `data-*` attribute: /// - Name starts with "data-" and has alphanumeric words (browsers require lowercase, but React and TS lowercase them),