Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: no-useless-constructor #4785

Closed
allenmanning opened this Issue Dec 22, 2015 · 3 comments

Comments

Projects
None yet
3 participants
@allenmanning
Copy link

allenmanning commented Dec 22, 2015

Rule Proposal: Empty or Useless ES6 Constructor

When the rules will warn. Include a description as well as sample code.

constructor (args...) {
  super(args...);
}

or

constructor () {
}

In ES6 classes both of the above forms are redundant, as they are the default constructor if none is specified. As such they can be considered Dead Code as they aren't doing anything.

Many times if code is here it is because implied constructors are not known well by the developer or they are left-overs after some other relevant non-redundant code has been removed.

This proposal is to provide and eslint rule to warn against this type of redundant dead code so it can be removed. This rule is similar to empty method, unused method types of eslint rules.

Whether the rule prevents an error or is stylistic.

It is mostly stylistic, but it could prevent an error if the developer feels that this code is doing something different than the default constructor.

Why the rule should be in the core instead of creating a custom rule.

This seems pretty core to removing dead or redundant code.

Are you willing to create the rule yourself?

Not at this time no.

@nzakas

This comment has been minimized.

Copy link
Member

nzakas commented Dec 22, 2015

I'm sorry, I don't understand what you're requesting. Please see our guide for proposing new rules: http://eslint.org/docs/1.10.3/developer-guide/contributing/new-rules

@allenmanning

This comment has been minimized.

Copy link
Author

allenmanning commented Dec 23, 2015

Apologies, I will update the description.

@nzakas

This comment has been minimized.

Copy link
Member

nzakas commented Dec 23, 2015

Thanks. This could be useful, I'd call it no-useless-constructor.

Unfortunately, we don't have enough people to implement all rules suggestions, so this will be left open to see if someone in the community will contribute it.

alberto added a commit that referenced this issue Dec 24, 2015

@allenmanning allenmanning changed the title Proposal: Empty Constructor Proposal: no-useless-constructor Dec 24, 2015

alberto added a commit that referenced this issue Dec 24, 2015

alberto added a commit that referenced this issue Dec 26, 2015

alberto added a commit that referenced this issue Dec 26, 2015

alberto added a commit that referenced this issue Dec 26, 2015

@alberto alberto closed this in 97cdb95 Dec 27, 2015

nzakas added a commit that referenced this issue Dec 27, 2015

Merge pull request #4797 from eslint/issue4785
New: Add no-useless-constructor rule (fixes #4785)

@eslint eslint bot locked and limited conversation to collaborators Feb 6, 2018

@eslint eslint bot added the archived due to age label Feb 6, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.