Typescript (Angular) member ordering arrangement
I'm currently trying to setup Webstorm's typescript arrangement to follow along with Angular's style guide.
Here is the tslint.json config for member-order:
"member-ordering": [
true,
{
"order": ["static-field", "instance-field", "static-method", "instance-method"]
}
]
The issue is that it does not put instance methods where they need to be, nor can I differentiate them from normal class properties.
Something like this:
export class TestClass {
publicProperty: string;
private privateProperty: string;
constructor() {}
publicInstanceMethod = () => {};
publicClassMethod() {}
private privateInstanceMethod = () => {};
private privateClassMethod() {}
}
gets formatted to this:
export class TestClass {
publicProperty: string;
publicInstanceMethod = () => {
};
private privateProperty: string;
private privateInstanceMethod = () => {
};
constructor() {
}
publicClassMethod() {
}
private privateClassMethod() {
}
}
...then tslint yells:
Declaration of instance field not allowed after declaration of instance method. Instead, this should come at the beginning of the class/interface.
Any idea idea on how to handle the rearranging of code so that it will put the instance methods where they are supposed to? I can't figure out if there is a way in Preferences -> Editor -> Code Style -> Typescript -> Arrangement to handle this.
Please sign in to leave a comment.
Lambda fields are currently treated as fields on re-arranging, that's why your 'instance methods' are grouped with fields. TSlint, however, treats them as methods, not fields - thius the issue.
Please follow https://youtrack.jetbrains.com/issue/WEB-28679 for updates