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

fix(eslint-plugin): out-of-bounds access in member-ordering rule #304

Merged
merged 2 commits into from Feb 23, 2019
Merged

fix(eslint-plugin): out-of-bounds access in member-ordering rule #304

merged 2 commits into from Feb 23, 2019

Conversation

jhnns
Copy link
Contributor

@jhnns jhnns commented Feb 21, 2019

Fixes Cannot read property 'replace' of undefined error when
unknown node types are used in the source code.
Also adds TODO comments for missing node types.


Some background information:

There are several node types that are not implemented yet, like:

  • TSCallSignatureDeclaration
  • TSIndexSignature
  • TSAbstractClassProperty
  • TSAbstractMethodDefinition
  • ...?

In that case, the current implementation returns Number.MAX_SAFE_INTEGER to increase the order ranking. In getLowestRank, however, this number is used as index for order which will obviously fail in some cases.

In my case, the rank in getLowestRank was an array that looked like this [ 3, 3, 16, 9007199254740991 ]. This threw:

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

Fixes #307

Fixes Cannot read property 'replace' of undefined error when
unknown node types are used in the source code.
Also adds TODO comments for missing node types.
@bradzacher bradzacher changed the title fix: out-of-bounds access in member-ordering rule fix(eslint-plugin): out-of-bounds access in member-ordering rule Feb 23, 2019
@codecov
Copy link

codecov bot commented Feb 23, 2019

Codecov Report

Merging #304 into master will increase coverage by 0.12%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master     #304      +/-   ##
==========================================
+ Coverage   97.14%   97.26%   +0.12%     
==========================================
  Files          67       67              
  Lines        2344     2344              
  Branches      334      334              
==========================================
+ Hits         2277     2280       +3     
+ Misses         45       43       -2     
+ Partials       22       21       -1
Impacted Files Coverage Δ
...ackages/eslint-plugin/src/rules/member-ordering.ts 96.66% <100%> (+5%) ⬆️

@JamesHenry
Copy link
Member

Danke dir!

@JamesHenry JamesHenry merged commit 4526f27 into typescript-eslint:master Feb 23, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2020
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.

[member-ordering] Rule crashes on TSAbstractMethodDefinition
4 participants