question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

New Rule: `no-useless-override`

See original GitHub issue

Rule details

same as no-useless-constructor but with overridden methods

Related ECMAScript feature

how new? es6 classes?

What type of rule is this?

Warns about a potential problem

Example code

// fail
class Foo {
    bar() {}
}

class Bar extends Foo {
    bar() {
        super.bar()
    }
}


// pass
class Foo {
    bar() {}
}

class Bar extends Foo {
    bar() {
        console.log("doing something else")
        super.bar()
    }
}

Why should this rule be in the core instead of a plugin?

because no-useless-constructor is already a core rule and i see no reason why it shouldn’t also check for useless method overrides

Participation

  • I am willing to submit a pull request to implement this rule.

Additional comments

originally raised here https://github.com/typescript-eslint/typescript-eslint/issues/4747

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:3
  • Comments:12 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
mdjermanoviccommented, Mar 29, 2022
class Foo {
    bar = () => {}
}

class Bar extends Foo {
    bar = () => {
        super.bar()
    }
}

This code actually has a bug - if you call (new Bar()).bar() it will throw an error because there is no super.bar. Arrow function instance fields are not methods.

1reaction
mdjermanoviccommented, Mar 29, 2022

bar = () => { super.bar() } does not have to be useless. Consider the following example:

class A {
    x = 5;
    bar() {
        console.log(this.x);
    }
}

class B extends A {
    bar = () => {
        super.bar()
    }
}

class C extends A {
}

(0, new B().bar)(); // logs 5
(0, new C().bar)(); // throws TypeError: Cannot read property 'x' of undefined


Read more comments on GitHub >

github_iconTop Results From Across the Web

New no-useless-override rule #3423 - palantir/tslint - GitHub
It would be great to have a new rule "no-useless-override" which triggers a warning or error when you use an override to disable...
Read more >
Proposed Rules - GovInfo
The proposed rule would rescind certain regulatory changes made effective on November. 16, 2020 and implements new statutory.
Read more >
State Enforcement of Inland Navigation Rules - Federal Register
This interim rule will not impose any new costs on vessel operators, or on State and local governments. State and local governments were...
Read more >
Employment Law Update 2023: New Compliance Obligations ...
Littler Workplace Policy Institute (WPI) has been tracking a host of new employment laws as they have been debated over the past few...
Read more >
Latest Updates | 2023 Federal Rules of Civil Procedure
The following rules were updated: Rules 5, 23, 62, and 65.1. The changes are listed below. New text is underlined while deleted text...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found