Skip to content

missing "class-memebers" in "order" for typescript-eslint-parser #2066

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

Closed
dudiharush opened this issue Dec 2, 2018 · 6 comments
Closed

missing "class-memebers" in "order" for typescript-eslint-parser #2066

dudiharush opened this issue Dec 2, 2018 · 6 comments

Comments

@dudiharush
Copy link

dudiharush commented Dec 2, 2018

When I use a tsx file (typescript) with typescript-eslint-parser, and I write a class member, it always errors me for placing it before lifecycle methods. ex:

class MyComp extends React.Component<any, any> {
private _someMember; // error: should be placed before componentWillMount eslint(react/sort-comp)

componentWillMount() {
this._someMemeber = 1;
}
render...
}

Can you please add "class-members" to the "order" category, or support "everything-else" in multiple places?

Thanks!

@ljharb
Copy link
Member

ljharb commented Dec 2, 2018

If you mean the sort-comp rule, you can configure it with “instance-variables” per the docs.

@dudiharush
Copy link
Author

I tried it, but it didn't work.
Can you send me the values in "order"?
Maybe i'm missing something...

@ljharb
Copy link
Member

ljharb commented Dec 2, 2018

It’s possible it doesn’t work with typescript, of course. What is your exact config?

@dudiharush
Copy link
Author

dudiharush commented Dec 3, 2018

 "rules": {
                "react/sort-comp": [2, {
                      "order": [
                        "static-methods",
                        "instance-variables",
                        "lifecycle",
                        "everything-else",
                        "render"
                      ],
                      "groups": {
                        "lifecycle": [
                          "displayName",
                          "propTypes",
                          "contextTypes",
                          "childContextTypes",
                          "mixins",
                          "statics",
                          "defaultProps",
                          "constructor",
                          "getDefaultProps",
                          "state",
                          "getInitialState",
                          "getChildContext",
                          "getDerivedStateFromProps",
                          "componentWillMount",
                          "UNSAFE_componentWillMount",
                          "componentDidMount",
                          "componentWillReceiveProps",
                          "UNSAFE_componentWillReceiveProps",
                          "shouldComponentUpdate",
                          "componentWillUpdate",
                          "UNSAFE_componentWillUpdate",
                          "getSnapshotBeforeUpdate",
                          "componentDidUpdate",
                          "componentDidCatch",
                          "componentWillUnmount"
                        ]
                      }
                    }]
            }

I think there is already an open issue about this problem: #1664

@ljharb
Copy link
Member

ljharb commented Dec 3, 2018

That issue is closed.

I think this is typescript specific - JS doesn’t use the private keyword. Separately, instance variables refers to public properties.

I’m not sure we support JS private fields, let alone TS ones.

@ljharb
Copy link
Member

ljharb commented Feb 15, 2022

We now support JS private fields and methods. If there's any issue with TS's private declaration, please file a new issue.

@ljharb ljharb closed this as completed Feb 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants