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] Rule crashes on TSAbstractMethodDefinition #307

Closed
epmatsw opened this issue Feb 21, 2019 · 4 comments · Fixed by #304
Closed

[member-ordering] Rule crashes on TSAbstractMethodDefinition #307

epmatsw opened this issue Feb 21, 2019 · 4 comments · Fixed by #304
Labels
bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@epmatsw
Copy link

epmatsw commented Feb 21, 2019

Repro

{
  "rules": {
    "@typescript-eslint/member-ordering": 2
  }
}
export abstract class ASDF {
    protected abstract blah() {

    }

    public asdf() {

    }
}

Expected Result

No crash, maybe an error.

Actual Result

TypeError: Cannot read property 'replace' of undefined
    at getLowestRank (/node_modules/@typescript-eslint/eslint-plugin/dist/rules/member-ordering.js:271:34)
    at members.forEach.member (/node_modules/@typescript-eslint/eslint-plugin/dist/rules/member-ordering.js:293:43)
    at Array.forEach (<anonymous>)
    at validateMembers (/node_modules/@typescript-eslint/eslint-plugin/dist/rules/member-ordering.js:282:25)
    at ClassDeclaration (/node_modules/@typescript-eslint/eslint-plugin/dist/rules/member-ordering.js:306:17)
    at listeners.(anonymous function).forEach.listener (/node_modules/eslint/lib/util/safe-emitter.js:45:58)
    at Array.forEach (<anonymous>)
    at Object.emit (/node_modules/eslint/lib/util/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/node_modules/eslint/lib/util/node-event-generator.js:251:26)
    at NodeEventGenerator.applySelectors (/node_modules/eslint/lib/util/node-event-generator.js:280:22)

Additional Info

It seems like what's happening is that it's hitting the Number.MAX_SAFE_INTEGER case in member-ordering's getRank (which has the comment // shouldn't happen but just in case, put it on the end). That's because getNodeType doesn't handle TSAbstractMethodDefinition and returns null (it also seems to be missing at least TSIndexSignature).

Once the rank is set to Number.MAX_SAFE_INTEGER, if an error is triggered, that rank gets passed to getLowestRank, which ends up looking at order[Number.MAX_SAFE_INTEGER], which is undefined, and then calls undefined.replace and crashes.

Versions

package version
@typescript-eslint/eslint-plugin 1.4.0
@typescript-eslint/parser 1.4.0
TypeScript 3.3.3
ESLint 5.14.1
node 10.15.0
npm 6.7.0
@epmatsw epmatsw added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Feb 21, 2019
@milesj
Copy link
Contributor

milesj commented Feb 22, 2019

Same problem here. I threw this console log in,console.log({ ranks, target, order, lowest });, and this is the result. Seems like the ranks number is way off.

{ ranks: [ 9007199254740991 ],
  target: 11,
  order:
   [ 'public-static-field',
     'protected-static-field',
     'private-static-field',
     'public-instance-field',
     'protected-instance-field',
     'private-instance-field',
     'public-field',
     'protected-field',
     'private-field',
     'static-field',
     'instance-field',
     'field',
     'constructor',
     'public-static-method',
     'protected-static-method',
     'private-static-method',
     'public-instance-method',
     'protected-instance-method',
     'private-instance-method',
     'public-method',
     'protected-method',
     'private-method',
     'static-method',
     'instance-method',
     'method' ],
  lowest: 9007199254740991 }

@epmatsw
Copy link
Author

epmatsw commented Feb 22, 2019

It looks like this would at least not crash after #304.

@bradzacher bradzacher added bug Something isn't working and removed triage Waiting for maintainers to take a look labels Feb 23, 2019
@novemberborn
Copy link

I'm still seeing this with 1.4.1. I added console.error(ranks, target, order, lowest) before

return order[lowest].replace(/-/g, ' ');

[ 9007199254740991 ] 11 [ 'public-static-field',
  'protected-static-field',
  'private-static-field',
  'public-instance-field',
  'protected-instance-field',
  'private-instance-field',
  'public-field',
  'protected-field',
  'private-field',
  'static-field',
  'instance-field',
  'field',
  'constructor',
  'public-static-method',
  'protected-static-method',
  'private-static-method',
  'public-instance-method',
  'protected-instance-method',
  'private-instance-method',
  'public-method',
  'protected-method',
  'private-method',
  'static-method',
  'instance-method',
  'method' ] 9007199254740991

I'm not sure what particular source file is being linted here, if you let me know how I can log that from the plugin I can share its rough shape.

@novemberborn
Copy link

Actually looks like 1.4.1 was a bad publish: #317

@typescript-eslint typescript-eslint locked as resolved and limited conversation to collaborators Feb 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants