Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

member-ordering: doesn't check constructor #1158

Closed
abierbaum opened this issue Apr 22, 2016 · 2 comments · Fixed by #1173
Closed

member-ordering: doesn't check constructor #1158

abierbaum opened this issue Apr 22, 2016 · 2 comments · Fixed by #1173

Comments

@abierbaum
Copy link
Contributor

Bug Report

  • TSLint version: 3.8.0
  • TypeScript version: 1.8.10
  • Running TSLint via: CLI

TypeScript code being linted

with tslint.json:

{
   "member-ordering": [
           true,
           "public-before-private",
           "static-before-instance",
           "variables-before-functions"
        ]
}

When checking this code:

class MyClass {
       foo() {}
       blah: number = 0;
}

I get the expected warning:

[30, 10]: Declaration of public instance member variable not allowed to appear after declaration of public instance member function

But when checking this code it passes. (renamed 'foo' to 'constructor')

class MyClass {
       constructor() {}
       blah: number = 0;
}

Expected behavior

I would expect the constructor case to have the same warning because there is a method before property definition.

@adidahiya
Copy link
Contributor

Thanks for the bug report @abierbaum! Should be a relatively easy fix if anyone wants to send a PR.

@lowkay
Copy link
Contributor

lowkay commented May 4, 2016

Hmm, now this includes checks against static methods too... I prefer constructors as the first thing after members and then methods after that. So that's an ordering that doesn't seem to be supported now, but it used to be accidentally because of this bug e.g.

class MyClass {
    private static staticMember: number = 7;

    private member: number;

    constructor(value) {
        this.member = value;
    }

    public static publicStaticMethod(): number { ... }

    private static privateStaticMethod(): number { ... }

    public publicMemberMethod(): number { ... }

    private privateMemberMethod(): number { ... }
}

Is there any plan to support this ordering style, which is a common C# style i.e. fields, constructors then methods while maintaining static/instance ordering within those sections?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants