mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
perf(linter): Replace ToString::to_string with CompactStr in remaining rules (#6407)
This commit is contained in:
parent
c5c69d6359
commit
a1a2721b1e
7 changed files with 26 additions and 40 deletions
|
|
@ -4,7 +4,7 @@ use oxc_ast::{
|
|||
};
|
||||
use oxc_diagnostics::OxcDiagnostic;
|
||||
use oxc_macros::declare_oxc_lint;
|
||||
use oxc_span::Span;
|
||||
use oxc_span::{CompactStr, Span};
|
||||
|
||||
use crate::{
|
||||
context::LintContext,
|
||||
|
|
@ -71,10 +71,10 @@ pub struct AltText(Box<AltTextConfig>);
|
|||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct AltTextConfig {
|
||||
img: Option<Vec<String>>,
|
||||
object: Option<Vec<String>>,
|
||||
area: Option<Vec<String>>,
|
||||
input_type_image: Option<Vec<String>>,
|
||||
img: Option<Vec<CompactStr>>,
|
||||
object: Option<Vec<CompactStr>>,
|
||||
area: Option<Vec<CompactStr>>,
|
||||
input_type_image: Option<Vec<CompactStr>>,
|
||||
}
|
||||
|
||||
impl std::ops::Deref for AltText {
|
||||
|
|
@ -160,9 +160,7 @@ impl Rule for AltText {
|
|||
if let (Some(tags), Some(elements)) =
|
||||
(tags, config.get(field).and_then(|v| v.as_array()))
|
||||
{
|
||||
tags.extend(
|
||||
elements.iter().filter_map(|v| v.as_str().map(ToString::to_string)),
|
||||
);
|
||||
tags.extend(elements.iter().filter_map(|v| v.as_str().map(CompactStr::from)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use oxc_ast::AstKind;
|
||||
use oxc_diagnostics::OxcDiagnostic;
|
||||
use oxc_macros::declare_oxc_lint;
|
||||
use oxc_span::Span;
|
||||
use oxc_span::{CompactStr, Span};
|
||||
|
||||
use crate::{
|
||||
context::LintContext,
|
||||
|
|
@ -23,7 +23,7 @@ pub struct HeadingHasContent(Box<HeadingHasContentConfig>);
|
|||
|
||||
#[derive(Debug, Default, Clone, PartialEq, Eq)]
|
||||
pub struct HeadingHasContentConfig {
|
||||
components: Option<Vec<String>>,
|
||||
components: Option<Vec<CompactStr>>,
|
||||
}
|
||||
|
||||
impl std::ops::Deref for HeadingHasContent {
|
||||
|
|
@ -74,10 +74,7 @@ impl Rule for HeadingHasContent {
|
|||
.and_then(|v| v.get("components"))
|
||||
.and_then(serde_json::Value::as_array)
|
||||
.map(|v| {
|
||||
v.iter()
|
||||
.filter_map(serde_json::Value::as_str)
|
||||
.map(ToString::to_string)
|
||||
.collect()
|
||||
v.iter().filter_map(serde_json::Value::as_str).map(CompactStr::from).collect()
|
||||
}),
|
||||
}))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use oxc_ast::{ast::JSXAttributeValue, AstKind};
|
||||
use oxc_diagnostics::OxcDiagnostic;
|
||||
use oxc_macros::declare_oxc_lint;
|
||||
use oxc_span::{GetSpan, Span};
|
||||
use oxc_span::{CompactStr, GetSpan, Span};
|
||||
|
||||
use crate::{
|
||||
context::LintContext,
|
||||
|
|
@ -28,15 +28,15 @@ pub struct MouseEventsHaveKeyEvents(Box<MouseEventsHaveKeyEventsConfig>);
|
|||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct MouseEventsHaveKeyEventsConfig {
|
||||
hover_in_handlers: Vec<String>,
|
||||
hover_out_handlers: Vec<String>,
|
||||
hover_in_handlers: Vec<CompactStr>,
|
||||
hover_out_handlers: Vec<CompactStr>,
|
||||
}
|
||||
|
||||
impl Default for MouseEventsHaveKeyEventsConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
hover_in_handlers: vec!["onMouseOver".to_string()],
|
||||
hover_out_handlers: vec!["onMouseOut".to_string()],
|
||||
hover_in_handlers: vec!["onMouseOver".into()],
|
||||
hover_out_handlers: vec!["onMouseOut".into()],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -78,7 +78,7 @@ impl Rule for MouseEventsHaveKeyEvents {
|
|||
config.hover_in_handlers = hover_in_handlers_config
|
||||
.iter()
|
||||
.filter_map(serde_json::Value::as_str)
|
||||
.map(ToString::to_string)
|
||||
.map(CompactStr::from)
|
||||
.collect();
|
||||
}
|
||||
|
||||
|
|
@ -90,7 +90,7 @@ impl Rule for MouseEventsHaveKeyEvents {
|
|||
config.hover_out_handlers = hover_out_handlers_config
|
||||
.iter()
|
||||
.filter_map(serde_json::Value::as_str)
|
||||
.map(ToString::to_string)
|
||||
.map(CompactStr::from)
|
||||
.collect();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -67,11 +67,7 @@ impl Rule for NoRedundantRoles {
|
|||
|
||||
if let Some(JSXAttributeItem::Attribute(attr)) = has_jsx_prop_ignore_case(jsx_el, "role") {
|
||||
if let Some(JSXAttributeValue::StringLiteral(role_values)) = &attr.value {
|
||||
let roles: Vec<String> = role_values
|
||||
.value
|
||||
.split_whitespace()
|
||||
.map(std::string::ToString::to_string)
|
||||
.collect();
|
||||
let roles = role_values.value.split_whitespace().collect::<Vec<_>>();
|
||||
for role in &roles {
|
||||
let exceptions = DEFAULT_ROLE_EXCEPTIONS.get(&component);
|
||||
if exceptions.map_or(false, |set| set.contains(role)) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use oxc_ast::AstKind;
|
||||
use oxc_diagnostics::OxcDiagnostic;
|
||||
use oxc_macros::declare_oxc_lint;
|
||||
use oxc_span::{GetSpan, Span};
|
||||
use oxc_span::{CompactStr, GetSpan, Span};
|
||||
use rustc_hash::FxHashSet;
|
||||
|
||||
use crate::{context::LintContext, rule::Rule, utils::PROMISE_STATIC_METHODS, AstNode};
|
||||
|
|
@ -16,7 +16,7 @@ pub struct SpecOnly(Box<SpecOnlyConfig>);
|
|||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct SpecOnlyConfig {
|
||||
allowed_methods: Option<FxHashSet<String>>,
|
||||
allowed_methods: Option<FxHashSet<CompactStr>>,
|
||||
}
|
||||
|
||||
impl std::ops::Deref for SpecOnly {
|
||||
|
|
@ -58,7 +58,7 @@ impl Rule for SpecOnly {
|
|||
.and_then(|v| v.get("allowedMethods"))
|
||||
.and_then(serde_json::Value::as_array)
|
||||
.map(|v| {
|
||||
v.iter().filter_map(serde_json::Value::as_str).map(ToString::to_string).collect()
|
||||
v.iter().filter_map(serde_json::Value::as_str).map(CompactStr::from).collect()
|
||||
});
|
||||
|
||||
Self(Box::new(SpecOnlyConfig { allowed_methods }))
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use oxc_ast::{
|
|||
};
|
||||
use oxc_diagnostics::OxcDiagnostic;
|
||||
use oxc_macros::declare_oxc_lint;
|
||||
use oxc_span::Span;
|
||||
use oxc_span::{CompactStr, Span};
|
||||
use rustc_hash::FxHashSet;
|
||||
|
||||
use crate::{
|
||||
|
|
@ -42,7 +42,7 @@ pub enum EnforceBooleanAttribute {
|
|||
#[derive(Debug, Default, Clone)]
|
||||
pub struct JsxBooleanValueConfig {
|
||||
pub enforce_boolean_attribute: EnforceBooleanAttribute,
|
||||
pub exceptions: FxHashSet<String>,
|
||||
pub exceptions: FxHashSet<CompactStr>,
|
||||
pub assume_undefined_is_false: bool,
|
||||
}
|
||||
|
||||
|
|
@ -94,9 +94,7 @@ impl Rule for JsxBooleanValue {
|
|||
let exceptions = config
|
||||
.and_then(|c| c.get(attribute_name))
|
||||
.and_then(serde_json::Value::as_array)
|
||||
.map(|v| {
|
||||
v.iter().filter_map(serde_json::Value::as_str).map(ToString::to_string).collect()
|
||||
})
|
||||
.map(|v| v.iter().filter_map(serde_json::Value::as_str).map(CompactStr::from).collect())
|
||||
.unwrap_or_default();
|
||||
|
||||
Self(Box::new(JsxBooleanValueConfig {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use oxc_ast::{
|
|||
};
|
||||
use oxc_diagnostics::OxcDiagnostic;
|
||||
use oxc_macros::declare_oxc_lint;
|
||||
use oxc_span::Span;
|
||||
use oxc_span::{CompactStr, Span};
|
||||
use oxc_syntax::operator::UnaryOperator;
|
||||
use rustc_hash::FxHashSet;
|
||||
|
||||
|
|
@ -31,7 +31,7 @@ pub struct ExplicitFunctionReturnTypeConfig {
|
|||
allow_direct_const_assertion_in_arrow_functions: bool,
|
||||
allow_concise_arrow_function_expressions_starting_with_void: bool,
|
||||
allow_functions_without_type_parameters: bool,
|
||||
allowed_names: FxHashSet<String>,
|
||||
allowed_names: FxHashSet<CompactStr>,
|
||||
allow_higher_order_functions: bool,
|
||||
allow_iifes: bool,
|
||||
}
|
||||
|
|
@ -143,10 +143,7 @@ impl Rule for ExplicitFunctionReturnType {
|
|||
.and_then(|x| x.get("allowedNames"))
|
||||
.and_then(serde_json::Value::as_array)
|
||||
.map(|v| {
|
||||
v.iter()
|
||||
.filter_map(serde_json::Value::as_str)
|
||||
.map(ToString::to_string)
|
||||
.collect()
|
||||
v.iter().filter_map(serde_json::Value::as_str).map(CompactStr::from).collect()
|
||||
})
|
||||
.unwrap_or_default(),
|
||||
allow_higher_order_functions: options
|
||||
|
|
|
|||
Loading…
Reference in a new issue