Eslint: bug: 'no-useless-constructor recognizes the required constructor of subclass as the error.

Created on 12 Jan 2016  路  3Comments  路  Source: eslint/eslint

env

  • 2.0.0-beta.1

    steps to reproduce

  1. Enable no-useless-constructor as warning/error
  2. Lint this code
// filename: test.jsx

import * as React from 'react';

export class TestComponent extends React.Component {

    constructor(props) {
        super(props);
    }

    render() {
        return (
            <div></div>
        );
    }
}

result

  • the error message is:

    • 7:5 error Useless constructor no-useless-constructor

  • In this case, TestComponent's constructor must be called, so it should not be the error.
archived due to age question

Most helpful comment

JavaScript will provide a default constructor that will call super by default. So you don't need constructor in this case. I think this is correct behavior.

All 3 comments

@saneyuki Thanks for the issue! If you're reporting a bug, please be sure to include:

  1. The version of ESLint you are using (run eslint -v)
  2. What you did (the source code and ESLint configuration)
  3. The actual ESLint output complete with numbers
  4. What you expected to happen instead

Requesting a new rule? Please see Proposing a New Rule for instructions.

JavaScript will provide a default constructor that will call super by default. So you don't need constructor in this case. I think this is correct behavior.

Yep, looks like the rule is working fine.

Was this page helpful?
0 / 5 - 0 ratings