Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion crates/oxc_linter/src/generated/rule_runner_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ impl RuleRunner for crate::rules::eslint::block_scoped_var::BlockScopedVar {
}

impl RuleRunner for crate::rules::eslint::class_methods_use_this::ClassMethodsUseThis {
const NODE_TYPES: Option<&AstTypesBitset> = None;
const NODE_TYPES: Option<&AstTypesBitset> = Some(&AstTypesBitset::from_types(&[
AstType::AccessorProperty,
AstType::MethodDefinition,
AstType::PropertyDefinition,
]));
const RUN_FUNCTIONS: RuleRunFunctionsImplemented = RuleRunFunctionsImplemented::Run;
}

Expand Down
25 changes: 16 additions & 9 deletions crates/oxc_linter/src/rules/eslint/class_methods_use_this.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::borrow::Cow;
use std::{borrow::Cow, ops::Deref};

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

impl Deref for ClassMethodsUseThis {
type Target = ClassMethodsUseThisConfig;

fn deref(&self) -> &Self::Target {
&self.0
}
}

#[derive(Debug, Clone)]
struct MethodException {
name: CompactStr,
Expand Down Expand Up @@ -136,12 +144,11 @@ impl Rule for ClassMethodsUseThis {
}

fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
let config = &self.0;
let function_pair = match node.kind() {
AstKind::AccessorProperty(accessor) => {
if accessor.r#static
|| !config.enforce_for_class_fields
|| (config.ignore_override_methods && accessor.r#override)
|| !self.enforce_for_class_fields
|| (self.ignore_override_methods && accessor.r#override)
|| self.check_ignore_classes_with_implements(
node,
ctx,
Expand All @@ -164,7 +171,7 @@ impl Rule for ClassMethodsUseThis {
AstKind::MethodDefinition(method_definition) => {
if method_definition.r#static
|| method_definition.kind.is_constructor()
|| (config.ignore_override_methods && method_definition.r#override)
|| (self.ignore_override_methods && method_definition.r#override)
|| self.check_ignore_classes_with_implements(
node,
ctx,
Expand All @@ -179,8 +186,8 @@ impl Rule for ClassMethodsUseThis {
}
AstKind::PropertyDefinition(property_definition) => {
if property_definition.r#static
|| !config.enforce_for_class_fields
|| (config.ignore_override_methods && property_definition.r#override)
|| !self.enforce_for_class_fields
|| (self.ignore_override_methods && property_definition.r#override)
|| self.check_ignore_classes_with_implements(
node,
ctx,
Expand All @@ -200,11 +207,11 @@ impl Rule for ClassMethodsUseThis {
_ => None,
})
}
_ => None,
_ => return,
};
let Some((function_body, name)) = function_pair else { return };
if let Some(name_str) = name.name()
&& config.except_methods.iter().any(|method| {
&& self.except_methods.iter().any(|method| {
method.name == name_str && method.private == name.is_private_identifier()
})
{
Expand Down
Loading