mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
refactor(linter): remove unnecessary usages of CompactStr
This commit is contained in:
parent
f6f7adc07f
commit
6e90f67c47
5 changed files with 22 additions and 22 deletions
|
|
@ -1,9 +1,11 @@
|
|||
pub mod return_checker;
|
||||
|
||||
use std::borrow::Cow;
|
||||
|
||||
use oxc_ast::{ast::Expression, AstKind};
|
||||
use oxc_diagnostics::OxcDiagnostic;
|
||||
use oxc_macros::declare_oxc_lint;
|
||||
use oxc_span::{CompactStr, GetSpan, Span};
|
||||
use oxc_span::{GetSpan, Span};
|
||||
use phf::phf_set;
|
||||
use serde_json::Value;
|
||||
|
||||
|
|
@ -230,10 +232,10 @@ const TARGET_METHODS: phf::Set<&'static str> = phf_set! {
|
|||
"toSorted",
|
||||
};
|
||||
|
||||
fn full_array_method_name(array_method: &'static str) -> CompactStr {
|
||||
fn full_array_method_name(array_method: &'static str) -> Cow<'static, str> {
|
||||
match array_method {
|
||||
"from" => CompactStr::from("Array.from"),
|
||||
s => CompactStr::from(format!("Array.prototype.{s}")),
|
||||
"from" => Cow::Borrowed("Array.from"),
|
||||
s => Cow::Owned(format!("Array.prototype.{s}")),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -57,8 +57,8 @@ impl Rule for NoGlobalAssign {
|
|||
.unwrap_or(&vec![])
|
||||
.iter()
|
||||
.map(serde_json::Value::as_str)
|
||||
.filter(std::option::Option::is_some)
|
||||
.map(|x| CompactStr::from(x.unwrap()))
|
||||
.filter(Option::is_some)
|
||||
.map(|x| x.unwrap().into())
|
||||
.collect::<Vec<CompactStr>>(),
|
||||
}))
|
||||
}
|
||||
|
|
@ -70,7 +70,6 @@ impl Rule for NoGlobalAssign {
|
|||
let reference = symbol_table.get_reference(reference_id);
|
||||
if reference.is_write() && symbol_table.is_global_reference(reference_id) {
|
||||
let name = reference.name();
|
||||
|
||||
if !self.excludes.contains(name) && ctx.env_contains_var(name) {
|
||||
ctx.diagnostic(no_global_assign_diagnostic(name, reference.span()));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ fn no_redeclare_as_builti_in_diagnostic(x0: &str, span1: Span) -> OxcDiagnostic
|
|||
// #[error("eslint(no-redeclare): '{0}' is already defined by a variable declaration.")]
|
||||
// #[diagnostic(severity(warning))]
|
||||
// struct NoRedeclareBySyntaxDiagnostic(
|
||||
// CompactStr,
|
||||
// String,
|
||||
// #[label("'{0}' is already defined by a variable declaration.")] pub Span,
|
||||
// #[label("It cannot be redeclared here.")] pub Span,
|
||||
// );
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use oxc_ast::{
|
|||
use oxc_diagnostics::OxcDiagnostic;
|
||||
use oxc_macros::declare_oxc_lint;
|
||||
use oxc_semantic::{AstNode, ModuleRecord};
|
||||
use oxc_span::{CompactStr, GetSpan, Span};
|
||||
use oxc_span::{GetSpan, Span};
|
||||
use oxc_syntax::module_record::{ExportExportName, ExportImportName, ImportImportName};
|
||||
|
||||
use crate::{context::LintContext, rule::Rule};
|
||||
|
|
@ -85,8 +85,7 @@ impl Rule for Namespace {
|
|||
return;
|
||||
};
|
||||
|
||||
let Some(loaded_module) =
|
||||
&loaded_module.loaded_modules.get(&CompactStr::from(source.clone()))
|
||||
let Some(loaded_module) = &loaded_module.loaded_modules.get(source.as_str())
|
||||
else {
|
||||
return;
|
||||
};
|
||||
|
|
@ -129,7 +128,7 @@ impl Rule for Namespace {
|
|||
check_deep_namespace_for_node(
|
||||
node,
|
||||
&source,
|
||||
vec![entry.local_name.name().clone()].as_slice(),
|
||||
vec![entry.local_name.name().to_string()].as_slice(),
|
||||
&module,
|
||||
ctx,
|
||||
);
|
||||
|
|
@ -154,7 +153,7 @@ impl Rule for Namespace {
|
|||
check_deep_namespace_for_object_pattern(
|
||||
pattern,
|
||||
&source,
|
||||
vec![entry.local_name.name().clone()].as_slice(),
|
||||
&[entry.local_name.name().to_string()],
|
||||
&module,
|
||||
ctx,
|
||||
);
|
||||
|
|
@ -214,7 +213,7 @@ fn get_module_request_name(name: &str, module_record: &ModuleRecord) -> Option<S
|
|||
fn check_deep_namespace_for_node(
|
||||
node: &AstNode,
|
||||
source: &str,
|
||||
namespaces: &[CompactStr],
|
||||
namespaces: &[String],
|
||||
module: &Arc<ModuleRecord>,
|
||||
ctx: &LintContext<'_>,
|
||||
) {
|
||||
|
|
@ -234,7 +233,7 @@ fn check_deep_namespace_for_node(
|
|||
parent_node,
|
||||
source,
|
||||
namespaces.as_slice(),
|
||||
module.loaded_modules.get(&CompactStr::from(module_source)).unwrap().value(),
|
||||
module.loaded_modules.get(module_source.as_str()).unwrap().value(),
|
||||
ctx,
|
||||
);
|
||||
} else {
|
||||
|
|
@ -257,7 +256,7 @@ fn check_deep_namespace_for_node(
|
|||
fn check_deep_namespace_for_object_pattern(
|
||||
pattern: &ObjectPattern,
|
||||
source: &str,
|
||||
namespaces: &[CompactStr],
|
||||
namespaces: &[String],
|
||||
module: &Arc<ModuleRecord>,
|
||||
ctx: &LintContext<'_>,
|
||||
) {
|
||||
|
|
@ -269,12 +268,12 @@ fn check_deep_namespace_for_object_pattern(
|
|||
if let BindingPatternKind::ObjectPattern(pattern) = &property.value.kind {
|
||||
if let Some(module_source) = get_module_request_name(&name, module) {
|
||||
let mut next_namespaces = namespaces.to_owned();
|
||||
next_namespaces.push(name.clone());
|
||||
next_namespaces.push(name.to_string());
|
||||
check_deep_namespace_for_object_pattern(
|
||||
pattern,
|
||||
source,
|
||||
next_namespaces.as_slice(),
|
||||
module.loaded_modules.get(&CompactStr::from(module_source)).unwrap().value(),
|
||||
module.loaded_modules.get(module_source.as_str()).unwrap().value(),
|
||||
ctx,
|
||||
);
|
||||
continue;
|
||||
|
|
@ -311,7 +310,7 @@ fn check_binding_exported(
|
|||
|| module
|
||||
.exported_bindings_from_star_export
|
||||
.iter()
|
||||
.any(|entry| entry.value().contains(&CompactStr::from(name)))
|
||||
.any(|entry| entry.value().iter().any(|s| s.as_str() == name))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -143,21 +143,21 @@ impl GetMethod for TSSignature<'_> {
|
|||
fn get_method(&self) -> Option<Method> {
|
||||
match self {
|
||||
TSSignature::TSMethodSignature(sig) => sig.key.static_name().map(|name| Method {
|
||||
name,
|
||||
name: name.clone(),
|
||||
r#static: false,
|
||||
call_signature: false,
|
||||
kind: get_kind_from_key(&sig.key),
|
||||
span: sig.key.span(),
|
||||
}),
|
||||
TSSignature::TSCallSignatureDeclaration(sig) => Some(Method {
|
||||
name: CompactStr::from("call"),
|
||||
name: "call".into(),
|
||||
r#static: false,
|
||||
call_signature: true,
|
||||
kind: MethodKind::Normal,
|
||||
span: sig.span,
|
||||
}),
|
||||
TSSignature::TSConstructSignatureDeclaration(decl) => Some(Method {
|
||||
name: CompactStr::from("new"),
|
||||
name: "new".into(),
|
||||
r#static: false,
|
||||
call_signature: false,
|
||||
kind: MethodKind::Normal,
|
||||
|
|
|
|||
Loading…
Reference in a new issue