Skip to content

Commit e5b32df

Browse files
committed
refactor(linter): refactor large arrays to reduce binary size
This is not successful but still a good change. ``` just oxlint ls -l ./target/release/oxlint ``` 6794656 bytes -> 6794592 bytes
1 parent 26249cf commit e5b32df

File tree

3 files changed

+19
-17
lines changed

3 files changed

+19
-17
lines changed

crates/oxc_linter/src/rules/jsx_a11y/role_has_required_aria_props.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use oxc_ast::{
55
use oxc_diagnostics::OxcDiagnostic;
66
use oxc_macros::declare_oxc_lint;
77
use oxc_span::Span;
8-
use phf::{phf_map, phf_set};
98

109
use crate::{AstNode, context::LintContext, rule::Rule, utils::has_jsx_prop_ignore_case};
1110

@@ -44,18 +43,21 @@ declare_oxc_lint!(
4443
correctness
4544
);
4645

47-
static ROLE_TO_REQUIRED_ARIA_PROPS: phf::Map<&'static str, phf::Set<&'static str>> = phf_map! {
48-
"checkbox" => phf_set!{"aria-checked"},
49-
"radio" => phf_set!{"aria-checked"},
50-
"menuitemcheckbox" => phf_set!{"aria-checked"},
51-
"menuitemradio" => phf_set!{"aria-checked"},
52-
"combobox" => phf_set!{"aria-controls", "aria-expanded"},
53-
"tab" => phf_set!{"aria-selected"},
54-
"slider" => phf_set!{"aria-valuemax", "aria-valuemin", "aria-valuenow"},
55-
"scrollbar" => phf_set!{"aria-valuemax", "aria-valuemin", "aria-valuenow", "aria-orientation", "aria-controls"},
56-
"heading" => phf_set!{"aria-level"},
57-
"option" => phf_set!{"aria-selected"},
58-
};
46+
static ROLE_TO_REQUIRED_ARIA_PROPS: &[(&str, &[&str])] = &[
47+
("checkbox", &["aria-checked"]),
48+
("radio", &["aria-checked"]),
49+
("menuitemcheckbox", &["aria-checked"]),
50+
("menuitemradio", &["aria-checked"]),
51+
("combobox", &["aria-controls", "aria-expanded"]),
52+
("tab", &["aria-selected"]),
53+
("slider", &["aria-valuemax", "aria-valuemin", "aria-valuenow"]),
54+
(
55+
"scrollbar",
56+
&["aria-valuemax", "aria-valuemin", "aria-valuenow", "aria-orientation", "aria-controls"],
57+
),
58+
("heading", &["aria-level"]),
59+
("option", &["aria-selected"]),
60+
];
5961

6062
impl Rule for RoleHasRequiredAriaProps {
6163
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
@@ -71,8 +73,8 @@ impl Rule for RoleHasRequiredAriaProps {
7173
};
7274
let roles = role_values.value.split_whitespace();
7375
for role in roles {
74-
if let Some(props) = ROLE_TO_REQUIRED_ARIA_PROPS.get(role) {
75-
for prop in props {
76+
if let Some(props) = ROLE_TO_REQUIRED_ARIA_PROPS.iter().find(|r| r.0 == role) {
77+
for prop in props.1 {
7678
if has_jsx_prop_ignore_case(jsx_el, prop).is_none() {
7779
ctx.diagnostic(role_has_required_aria_props_diagnostic(
7880
attr.span, role, prop,

crates/oxc_linter/src/rules/unicorn/no_useless_undefined.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ declare_oxc_lint!(
5858
);
5959

6060
// Create a static set for all function names
61-
static FUNCTION_NAMES: [&str; 27] = [
61+
static FUNCTION_NAMES: &[&str] = &[
6262
"add",
6363
// `React.createContext(undefined)`
6464
"createContext",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ fn recurse_extend_node_chain<'a>(
570570
}
571571

572572
// sorted list for binary search.
573-
const VALID_JEST_FN_CALL_CHAINS: [[&str; 4]; 52] = [
573+
static VALID_JEST_FN_CALL_CHAINS: &[[&str; 4]] = &[
574574
["afterAll", "", "", ""],
575575
["afterEach", "", "", ""],
576576
["beforeAll", "", "", ""],

0 commit comments

Comments
 (0)