Skip to content

Commit

Permalink
feat(linter): promote no-this-before-super to correctness (#2313)
Browse files Browse the repository at this point in the history
I've tested this in all real world test repos and found no false
positives. Thank you so much @u9g @TzviPM for making this happen!
  • Loading branch information
Boshen authored Feb 5, 2024
1 parent d6d931c commit a762d17
Showing 1 changed file with 28 additions and 32 deletions.
60 changes: 28 additions & 32 deletions crates/oxc_linter/src/rules/eslint/no_this_before_super.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,31 +43,14 @@ declare_oxc_lint!(
/// }
/// ```
NoThisBeforeSuper,
nursery
correctness
);

impl NoThisBeforeSuper {
fn is_wanted_node(node: &AstNode, ctx: &LintContext<'_>) -> bool {
if let Some(parent) = ctx.nodes().parent_node(node.id()) {
if let AstKind::MethodDefinition(mdef) = parent.kind() {
if matches!(mdef.kind, MethodDefinitionKind::Constructor) {
let parent_2 = ctx.nodes().parent_node(parent.id());
if let Some(parent_2) = parent_2 {
let parent_3 = ctx.nodes().parent_node(parent_2.id());
if let Some(parent_3) = parent_3 {
if let AstKind::Class(c) = parent_3.kind() {
if let Some(super_class) = &c.super_class {
return !matches!(super_class, Expression::NullLiteral(_));
}
}
}
}
}
}
}

false
}
#[derive(Default, Copy, Clone, Debug)]
enum DefinitelyCallsThisBeforeSuper {
#[default]
No,
Yes,
}

impl Rule for NoThisBeforeSuper {
Expand Down Expand Up @@ -159,17 +142,30 @@ impl Rule for NoThisBeforeSuper {
}
}
}

fn from_configuration(_value: serde_json::Value) -> Self {
Self
}
}

#[derive(Default, Copy, Clone, Debug)]
enum DefinitelyCallsThisBeforeSuper {
#[default]
No,
Yes,
impl NoThisBeforeSuper {
fn is_wanted_node(node: &AstNode, ctx: &LintContext<'_>) -> bool {
if let Some(parent) = ctx.nodes().parent_node(node.id()) {
if let AstKind::MethodDefinition(mdef) = parent.kind() {
if matches!(mdef.kind, MethodDefinitionKind::Constructor) {
let parent_2 = ctx.nodes().parent_node(parent.id());
if let Some(parent_2) = parent_2 {
let parent_3 = ctx.nodes().parent_node(parent_2.id());
if let Some(parent_3) = parent_3 {
if let AstKind::Class(c) = parent_3.kind() {
if let Some(super_class) = &c.super_class {
return !matches!(super_class, Expression::NullLiteral(_));
}
}
}
}
}
}
}

false
}
}

#[test]
Expand Down

0 comments on commit a762d17

Please sign in to comment.