Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(eslint-plugin): out-of-bounds access in member-ordering rule (#304)
  • Loading branch information
jhnns authored and JamesHenry committed Feb 23, 2019
1 parent b29cad9 commit 4526f27
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/eslint-plugin/src/rules/member-ordering.ts
Expand Up @@ -182,6 +182,9 @@ export default util.createRule<Options, MessageIds>({
node: TSESTree.ClassElement | TSESTree.TypeElement,
): string | null {
// TODO: add missing TSCallSignatureDeclaration
// TODO: add missing TSIndexSignature
// TODO: add missing TSAbstractClassProperty
// TODO: add missing TSAbstractMethodDefinition
switch (node.type) {
case AST_NODE_TYPES.MethodDefinition:
return node.kind;
Expand Down Expand Up @@ -258,7 +261,7 @@ export default util.createRule<Options, MessageIds>({
const type = getNodeType(node);
if (type === null) {
// shouldn't happen but just in case, put it on the end
return Number.MAX_SAFE_INTEGER;
return order.length - 1;
}

const scope = 'static' in node && node.static ? 'static' : 'instance';
Expand Down
25 changes: 25 additions & 0 deletions packages/eslint-plugin/tests/rules/member-ordering.test.ts
Expand Up @@ -1211,6 +1211,12 @@ type Foo = {
`,
options: [{ default: ['method', 'constructor', 'field'] }],
},
`
abstract class Foo {
B: string;
abstract A: () => {}
}
`,
],
invalid: [
{
Expand Down Expand Up @@ -3310,5 +3316,24 @@ type Foo = {
},
],
},
{
code: `
abstract class Foo {
abstract A: () => {}
B: string;
}
`,
errors: [
{
messageId: 'incorrectOrder',
data: {
name: 'B',
rank: 'method',
},
line: 4,
column: 5,
},
],
},
],
});

0 comments on commit 4526f27

Please sign in to comment.