Skip to content

Commit 4526f27

Browse files
jhnnsJamesHenry
authored andcommitted
fix(eslint-plugin): out-of-bounds access in member-ordering rule (typescript-eslint#304)
1 parent b29cad9 commit 4526f27

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

packages/eslint-plugin/src/rules/member-ordering.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ export default util.createRule<Options, MessageIds>({
182182
node: TSESTree.ClassElement | TSESTree.TypeElement,
183183
): string | null {
184184
// TODO: add missing TSCallSignatureDeclaration
185+
// TODO: add missing TSIndexSignature
186+
// TODO: add missing TSAbstractClassProperty
187+
// TODO: add missing TSAbstractMethodDefinition
185188
switch (node.type) {
186189
case AST_NODE_TYPES.MethodDefinition:
187190
return node.kind;
@@ -258,7 +261,7 @@ export default util.createRule<Options, MessageIds>({
258261
const type = getNodeType(node);
259262
if (type === null) {
260263
// shouldn't happen but just in case, put it on the end
261-
return Number.MAX_SAFE_INTEGER;
264+
return order.length - 1;
262265
}
263266

264267
const scope = 'static' in node && node.static ? 'static' : 'instance';

packages/eslint-plugin/tests/rules/member-ordering.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,12 @@ type Foo = {
12111211
`,
12121212
options: [{ default: ['method', 'constructor', 'field'] }],
12131213
},
1214+
`
1215+
abstract class Foo {
1216+
B: string;
1217+
abstract A: () => {}
1218+
}
1219+
`,
12141220
],
12151221
invalid: [
12161222
{
@@ -3310,5 +3316,24 @@ type Foo = {
33103316
},
33113317
],
33123318
},
3319+
{
3320+
code: `
3321+
abstract class Foo {
3322+
abstract A: () => {}
3323+
B: string;
3324+
}
3325+
`,
3326+
errors: [
3327+
{
3328+
messageId: 'incorrectOrder',
3329+
data: {
3330+
name: 'B',
3331+
rank: 'method',
3332+
},
3333+
line: 4,
3334+
column: 5,
3335+
},
3336+
],
3337+
},
33133338
],
33143339
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy