Skip to content
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

[member-ordering] Index signature is considered a method in interface #1186

Closed
sveyret opened this issue Nov 8, 2019 · 5 comments
Closed
Labels
enhancement: plugin rule option New rule option for an existing eslint-plugin rule good first issue Good for newcomers has pr there is a PR raised to close this package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@sveyret
Copy link
Contributor

sveyret commented Nov 8, 2019

Repro

{
  "rules": {
   "'@typescript-eslint/member-ordering": ["error"]
  }
}
interface Extra {
  [key: string]: any
  req: Request
  res: Response
}

Expected Result

No error.

Actual Result

Member req should be declared before all method definitions. eslint(@typescript-eslint/member-ordering)
Member res should be declared before all method definitions. eslint(@typescript-eslint/member-ordering)

Additional Info

If I remove the index signature, or put it after the interface members, there is no error.

Versions

package version
@typescript-eslint/eslint-plugin 2.6.1
@typescript-eslint/parser 2.6.1
TypeScript 3.6.4
ESLint 6.6.0
node 12.13.0
npm 6.12.0
@sveyret sveyret added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Nov 8, 2019
@bradzacher bradzacher added enhancement: plugin rule option New rule option for an existing eslint-plugin rule and removed triage Waiting for maintainers to take a look labels Nov 8, 2019
@bradzacher
Copy link
Member

Index signature support was never added to the rule.

@sveyret
Copy link
Contributor Author

sveyret commented Nov 8, 2019

Even without adding an option to support position of index signature, the rule should be corrected to, at least, ignore index signature when checking order. The tslint replaced rule was not failing in this situation.

@bradzacher bradzacher added the good first issue Good for newcomers label Nov 8, 2019
@bradzacher
Copy link
Member

The tslint replaced rule was not failing in this situation.

We don't aim for 1:1 replacements with tslint when adding a rule. TSLint rules in many cases have options added that aren't used, or have options that should be on by default, etc.
When adding a rule that is analogous to one in TSLint, it's built for the use case.

The rule was built by a community member (as has been pretty much every rule).
At the time, they didn't have a use case for sorting index signatures, so they didn't add it.
None of the reviewers had an active use case for it either, so it was merged without it.

Either nobody has had a use case for this since the rule was implemented, or users have worked around it.

Happy to accept a PR to add support, if this functionality is important to you.

// TODO: add missing TSIndexSignature

@sveyret
Copy link
Contributor Author

sveyret commented Nov 8, 2019

I'll try to see if I have time to create a PR. Unfortunately, I'm not sure I'll have time.

Just to be clear again: I'm not expecting the rule to allow to sort the index signature, but to at least ignore it.

EDIT: I take it, I'll try to add the signature to the list of items to order.

@bradzacher bradzacher added the has pr there is a PR raised to close this label Nov 10, 2019
@armano2
Copy link
Member

armano2 commented Jan 1, 2020

fixed in #1190

@armano2 armano2 closed this as completed Jan 1, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement: plugin rule option New rule option for an existing eslint-plugin rule good first issue Good for newcomers has pr there is a PR raised to close this package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

No branches or pull requests

3 participants