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

Treat member variables initialized to a function as a function for ordering purposes #969

Merged
merged 1 commit into from
Feb 18, 2016

Conversation

jkillian
Copy link
Contributor

Fixes #226

super.visitPropertyDeclaration(node);
}

public visitPropertySignature(node: ts.Node) {
this.checkModifiersAndSetPrevious(node, getModifiers(false, node.modifiers));
public visitPropertySignature(node: ts.PropertyDeclaration) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's debatable if ts.PropertyDeclaration is the right type here. However, this is what we use in other places for this method signature so I went with it here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it is discussed here: microsoft/TypeScript#3833

PropertySignature nodes will be visited when linting interfaces. But looking at that code snippet from the parser, ts.PropertyDeclaration is probably safe enough to use as the typedef here. I guess we'll rely on testing :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, nice find. We really only use this to access common fields like node.type so shouldn't be a problem

@adidahiya
Copy link
Contributor

Exciting! What a long standing issue. Will take a look today.

@jkillian jkillian changed the title Treat member variables initialized to a function a function for ordering purposes Treat member variables initialized to a function as a function for ordering purposes Feb 12, 2016
@adidahiya adidahiya added this to the TSLint 3.4 milestone Feb 16, 2016
@adidahiya adidahiya self-assigned this Feb 16, 2016
@@ -171,7 +171,8 @@ A sample configuration file with all options is available [here](https://github.
* `member-ordering` enforces member ordering. Rule options:
* `public-before-private` All public members must be declared before private members.
* `static-before-instance` All static members must be declared before instance members.
* `variables-before-functions` All variables needs to be declared before functions.
* `variables-before-functions` All member variables need to be declared before member functions.
Member variables initialized to a function literal are treated as member functions.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In retrospect, this doesn't seem like the right option name... shouldn't it be properties-before-methods? If you agree I'll file an issue as a breaking change for v4.x.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh, it's not perfect because functions assigned with = are properties really but we treat them as methods. (I don't think you'd call functions on the prototype "properties" but not sure.) Let me think about this, but I'm inclined just to leave it as it is because I don't see a big clarity benefit worth making a breaking change

@jkillian
Copy link
Contributor Author

Updated (via an amended commit)

@adidahiya
Copy link
Contributor

👍

adidahiya added a commit that referenced this pull request Feb 18, 2016
Treat member variables initialized to a function as a function for ordering purposes
@adidahiya adidahiya merged commit 4aabfa9 into master Feb 18, 2016
@adidahiya adidahiya deleted the arrow-func-order branch February 18, 2016 15:56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants