feat(linter): promote no-this-before-super to correctness (#2313)

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!
This commit is contained in:
Boshen 2024-02-05 16:01:09 +08:00 committed by GitHub
parent d6d931cd80
commit a762d17603
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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 {
@ -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]