Skip to content

Commit 84f4e73

Browse files
committed
revert(linter): revert incorrect perf in rules (#10509)
1 parent 4fda4c5 commit 84f4e73

34 files changed

+93
-86
lines changed

crates/oxc_linter/src/globals.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ pub fn is_valid_aria_property(name: &str) -> bool {
190190
/// set of valid ARIA role definitions
191191
/// Reference: <https://www.w3.org/TR/wai-aria/#role_definitions>
192192
/// Reference: <https://github.com/A11yance/aria-query/blob/v5.3.2/src/rolesMap.js>
193-
pub const VALID_ARIA_ROLES: [&str; 125] = [
193+
pub const VALID_ARIA_ROLES: phf::Set<&'static str> = phf::phf_set![
194194
"alert",
195195
"alertdialog",
196196
"application",
@@ -318,7 +318,7 @@ pub const VALID_ARIA_ROLES: [&str; 125] = [
318318
"treeitem",
319319
];
320320

321-
pub const HTML_TAG: [&str; 149] = [
321+
pub const HTML_TAG: phf::Set<&'static str> = phf::phf_set![
322322
"a",
323323
"abbr",
324324
"acronym",

crates/oxc_linter/src/rules/eslint/array_callback_return/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ pub fn get_array_method_name<'a>(node: &AstNode<'a>, ctx: &LintContext<'a>) -> O
196196
// "methods",
197197
let array_method = callee.static_property_name()?;
198198

199-
if TARGET_METHODS.binary_search(&array_method).is_ok()
199+
if TARGET_METHODS.contains(&array_method)
200200
// Check that current node is parent's first argument
201201
&& call.arguments.len() == 1
202202
&& is_nth_argument(call, current_node_arg, 0)

crates/oxc_linter/src/rules/eslint/func_names.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ const INVALID_NAMES: [&str; 9] =
388388
["arguments", "async", "await", "constructor", "default", "eval", "null", "undefined", "yield"];
389389

390390
fn is_valid_identifier_name(name: &str) -> bool {
391-
INVALID_NAMES.binary_search(&name).is_err() && is_identifier_name(name)
391+
!INVALID_NAMES.contains(&name) && is_identifier_name(name)
392392
}
393393

394394
#[test]

crates/oxc_linter/src/rules/eslint/use_isnan.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,21 +155,21 @@ fn is_nan_identifier<'a>(expr: &'a Expression<'a>) -> bool {
155155
}
156156

157157
/// If callee is calling the `indexOf` or `lastIndexOf` function.
158-
fn is_target_callee<'a>(callee: &'a Expression<'a>) -> Option<&'static str> {
158+
fn is_target_callee<'a>(callee: &'a Expression) -> Option<&'a str> {
159159
const TARGET_METHODS: [&str; 2] = ["indexOf", "lastIndexOf"];
160160
let callee = callee.get_inner_expression();
161161

162162
if let Some(expr) = callee.as_member_expression() {
163-
return expr.static_property_name().and_then(|property| {
164-
TARGET_METHODS.iter().find(|method| **method == property).copied()
165-
});
163+
return expr
164+
.static_property_name()
165+
.and_then(|property| TARGET_METHODS.contains(&property).then_some(property));
166166
}
167167

168168
if let Expression::ChainExpression(chain) = callee {
169169
let expr = chain.expression.as_member_expression()?;
170-
return expr.static_property_name().and_then(|property| {
171-
TARGET_METHODS.iter().find(|method| **method == property).copied()
172-
});
170+
return expr
171+
.static_property_name()
172+
.and_then(|property| TARGET_METHODS.contains(&property).then_some(property));
173173
}
174174

175175
None

crates/oxc_linter/src/rules/eslint/valid_typeof.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,15 @@ impl Rule for ValidTypeof {
117117
};
118118

119119
if let Expression::StringLiteral(lit) = sibling {
120-
if VALID_TYPES.binary_search(&lit.value.as_str()).is_err() {
120+
if !VALID_TYPES.contains(&lit.value.as_str()) {
121121
ctx.diagnostic(invalid_value(None, sibling.span()));
122122
}
123123
return;
124124
}
125125

126126
if let Expression::TemplateLiteral(template) = sibling {
127127
if template.expressions.is_empty() {
128-
if template
129-
.quasi()
130-
.is_some_and(|value| VALID_TYPES.binary_search(&value.as_str()).is_err())
131-
{
128+
if template.quasi().is_some_and(|value| !VALID_TYPES.contains(&value.as_str())) {
132129
ctx.diagnostic(invalid_value(None, sibling.span()));
133130
}
134131
return;

crates/oxc_linter/src/rules/jsdoc/check_tag_names.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ struct CheckTagnamesConfig {
5858
typed: bool,
5959
}
6060

61-
const VALID_BLOCK_TAGS: [&str; 74] = [
61+
const VALID_BLOCK_TAGS: phf::Set<&'static str> = phf::phf_set![
6262
"abstract",
6363
"access",
6464
"alias",
@@ -88,12 +88,10 @@ const VALID_BLOCK_TAGS: [&str; 74] = [
8888
"hideconstructor",
8989
"ignore",
9090
"implements",
91-
"import",
9291
"inheritdoc",
9392
"inner",
9493
"instance",
9594
"interface",
96-
"internal",
9795
"kind",
9896
"lends",
9997
"license",
@@ -109,7 +107,6 @@ const VALID_BLOCK_TAGS: [&str; 74] = [
109107
"module",
110108
"name",
111109
"namespace",
112-
"overload",
113110
"override",
114111
"package",
115112
"param",
@@ -120,12 +117,10 @@ const VALID_BLOCK_TAGS: [&str; 74] = [
120117
"readonly",
121118
"requires",
122119
"returns",
123-
"satisfies",
124120
"see",
125121
"since",
126122
"static",
127123
"summary",
128-
"template",
129124
"this",
130125
"throws",
131126
"todo",
@@ -135,6 +130,12 @@ const VALID_BLOCK_TAGS: [&str; 74] = [
135130
"variation",
136131
"version",
137132
"yields",
133+
// JSDoc TS specific
134+
"import",
135+
"internal",
136+
"overload",
137+
"satisfies",
138+
"template",
138139
];
139140

140141
const JSX_TAGS: [&str; 4] = ["jsx", "jsxFrag", "jsxImportSource", "jsxRuntime"];
@@ -242,7 +243,7 @@ impl Rule for CheckTagNames {
242243

243244
// Additional check for `typed` mode
244245
if config.typed {
245-
if ALWAYS_INVALID_TAGS_IF_TYPED.binary_search(&tag_name).is_ok() {
246+
if ALWAYS_INVALID_TAGS_IF_TYPED.contains(&tag_name) {
246247
ctx.diagnostic(check_tag_names_diagnostic(
247248
tag.kind.span,
248249
&format!("`@{tag_name}` is redundant when using a type system."),
@@ -255,17 +256,15 @@ impl Rule for CheckTagNames {
255256
continue;
256257
}
257258

258-
if !is_ambient
259-
&& OUTSIDE_AMBIENT_INVALID_TAGS_IF_TYPED.binary_search(&tag_name).is_ok()
260-
{
259+
if !is_ambient && OUTSIDE_AMBIENT_INVALID_TAGS_IF_TYPED.contains(&tag_name) {
261260
ctx.diagnostic(check_tag_names_diagnostic(tag.kind.span, &format!("`@{tag_name}` is redundant outside of ambient(`declare` or `.d.ts`) contexts when using a type system.")));
262261
continue;
263262
}
264263
}
265264

266265
// If invalid or unknown, report
267266
let is_valid = (config.jsx_tags && JSX_TAGS.contains(&tag_name))
268-
|| VALID_BLOCK_TAGS.binary_search(&tag_name).is_ok();
267+
|| VALID_BLOCK_TAGS.contains(tag_name);
269268
if !is_valid {
270269
ctx.diagnostic(check_tag_names_diagnostic(
271270
tag.kind.span,

crates/oxc_linter/src/rules/jsdoc/empty_tags.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl Rule for EmptyTags {
101101
let settings = &ctx.settings().jsdoc;
102102

103103
let is_empty_tag_kind = |tag_name: &str| {
104-
if EMPTY_TAGS.binary_search(&tag_name).is_ok() {
104+
if EMPTY_TAGS.contains(&tag_name) {
105105
return true;
106106
}
107107
if !self.0.tags.is_empty() && self.0.tags.contains(&tag_name.to_string()) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl Rule for AriaActivedescendantHasTabindex {
6767

6868
let element_type = get_element_type(ctx, jsx_opening_el);
6969

70-
if HTML_TAG.binary_search(&element_type.as_ref()).is_err() {
70+
if !HTML_TAG.contains(element_type.as_ref()) {
7171
return;
7272
}
7373

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl Rule for AriaRole {
146146
if let Some(aria_role) = has_jsx_prop(&jsx_el.opening_element, "role") {
147147
let element_type = get_element_type(ctx, &jsx_el.opening_element);
148148

149-
if self.ignore_non_dom && HTML_TAG.binary_search(&element_type.as_ref()).is_err() {
149+
if self.ignore_non_dom && !HTML_TAG.contains(element_type.as_ref()) {
150150
return;
151151
}
152152

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl Rule for AriaUnsupportedElements {
5050
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
5151
if let AstKind::JSXOpeningElement(jsx_el) = node.kind() {
5252
let el_type = get_element_type(ctx, jsx_el);
53-
if RESERVED_HTML_TAG.binary_search(&el_type.as_ref()).is_ok() {
53+
if RESERVED_HTML_TAG.contains(&el_type.as_ref()) {
5454
for attr in &jsx_el.attributes {
5555
let attr = match attr {
5656
JSXAttributeItem::Attribute(attr) => attr,

0 commit comments

Comments
 (0)