Skip to content

Commit a75dc10

Browse files
committed
perf(linter): refactor class-methods-use-this to be analyzed
1 parent 9b21901 commit a75dc10

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

crates/oxc_linter/src/generated/rule_runner_impls.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ impl RuleRunner for crate::rules::eslint::block_scoped_var::BlockScopedVar {
2727
}
2828

2929
impl RuleRunner for crate::rules::eslint::class_methods_use_this::ClassMethodsUseThis {
30-
const NODE_TYPES: Option<&AstTypesBitset> = None;
30+
const NODE_TYPES: Option<&AstTypesBitset> = Some(&AstTypesBitset::from_types(&[
31+
AstType::AccessorProperty,
32+
AstType::MethodDefinition,
33+
AstType::PropertyDefinition,
34+
]));
3135
const RUN_FUNCTIONS: RuleRunFunctionsImplemented = RuleRunFunctionsImplemented::Run;
3236
}
3337

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

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::borrow::Cow;
1+
use std::{borrow::Cow, ops::Deref};
22

33
use itertools::Itertools;
44
use oxc_ast::{
@@ -42,6 +42,14 @@ impl Default for ClassMethodsUseThisConfig {
4242
#[derive(Debug, Clone, Default)]
4343
pub struct ClassMethodsUseThis(Box<ClassMethodsUseThisConfig>);
4444

45+
impl Deref for ClassMethodsUseThis {
46+
type Target = ClassMethodsUseThisConfig;
47+
48+
fn deref(&self) -> &Self::Target {
49+
&self.0
50+
}
51+
}
52+
4553
#[derive(Debug, Clone)]
4654
struct MethodException {
4755
name: CompactStr,
@@ -136,12 +144,11 @@ impl Rule for ClassMethodsUseThis {
136144
}
137145

138146
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
139-
let config = &self.0;
140147
let function_pair = match node.kind() {
141148
AstKind::AccessorProperty(accessor) => {
142149
if accessor.r#static
143-
|| !config.enforce_for_class_fields
144-
|| (config.ignore_override_methods && accessor.r#override)
150+
|| !self.enforce_for_class_fields
151+
|| (self.ignore_override_methods && accessor.r#override)
145152
|| self.check_ignore_classes_with_implements(
146153
node,
147154
ctx,
@@ -164,7 +171,7 @@ impl Rule for ClassMethodsUseThis {
164171
AstKind::MethodDefinition(method_definition) => {
165172
if method_definition.r#static
166173
|| method_definition.kind.is_constructor()
167-
|| (config.ignore_override_methods && method_definition.r#override)
174+
|| (self.ignore_override_methods && method_definition.r#override)
168175
|| self.check_ignore_classes_with_implements(
169176
node,
170177
ctx,
@@ -179,8 +186,8 @@ impl Rule for ClassMethodsUseThis {
179186
}
180187
AstKind::PropertyDefinition(property_definition) => {
181188
if property_definition.r#static
182-
|| !config.enforce_for_class_fields
183-
|| (config.ignore_override_methods && property_definition.r#override)
189+
|| !self.enforce_for_class_fields
190+
|| (self.ignore_override_methods && property_definition.r#override)
184191
|| self.check_ignore_classes_with_implements(
185192
node,
186193
ctx,
@@ -200,11 +207,11 @@ impl Rule for ClassMethodsUseThis {
200207
_ => None,
201208
})
202209
}
203-
_ => None,
210+
_ => return,
204211
};
205212
let Some((function_body, name)) = function_pair else { return };
206213
if let Some(name_str) = name.name()
207-
&& config.except_methods.iter().any(|method| {
214+
&& self.except_methods.iter().any(|method| {
208215
method.name == name_str && method.private == name.is_private_identifier()
209216
})
210217
{

0 commit comments

Comments
 (0)