Skip to content

Commit 314d371

Browse files
committed
reviews
1 parent 68a3db2 commit 314d371

File tree

2 files changed

+43
-12
lines changed

2 files changed

+43
-12
lines changed

Diff for: packages/eslint-plugin/src/rules/no-base-to-string.ts

+2-12
Original file line numberDiff line numberDiff line change
@@ -240,18 +240,8 @@ export default createRule<Options, MessageIds>({
240240
return;
241241
}
242242

243-
for (const part of typeParts) {
244-
const typeArg = checker.getTypeArguments(
245-
part as ts.TypeReference,
246-
)[0];
247-
248-
const certainty = getToStringCertainty(node, typeArg);
249-
250-
if (certainty !== Usefulness.Always) {
251-
checkExpression(memberExpr.object, typeArg, 'baseArrayJoin');
252-
return;
253-
}
254-
}
243+
const typeArg = type.getNumberIndexType();
244+
checkExpression(memberExpr.object, typeArg, 'baseArrayJoin');
255245
},
256246
}
257247
: undefined),

Diff for: packages/eslint-plugin/tests/rules/no-base-to-string.test.ts

+41
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,23 @@ String(...objects);
455455
],
456456
options: [{ checkArrayJoin: true }],
457457
},
458+
{
459+
code: `
460+
class Foo {}
461+
const tuple: [string, Foo] = ['string', new Foo()];
462+
tuple.join('');
463+
`,
464+
errors: [
465+
{
466+
data: {
467+
certainty: 'will',
468+
name: 'tuple',
469+
},
470+
messageId: 'baseArrayJoin',
471+
},
472+
],
473+
options: [{ checkArrayJoin: true }],
474+
},
458475
{
459476
code: `
460477
class Foo {}
@@ -472,5 +489,29 @@ String(...objects);
472489
],
473490
options: [{ checkArrayJoin: true }],
474491
},
492+
{
493+
code: `
494+
class Foo {}
495+
const tuple: [string, Foo] = ['string', new Foo()];
496+
tuple.join('');
497+
`,
498+
errors: [
499+
{
500+
data: {
501+
certainty: 'will',
502+
name: 'tuple',
503+
},
504+
messageId: 'baseArrayJoin',
505+
},
506+
],
507+
languageOptions: {
508+
parserOptions: {
509+
project: './tsconfig.noUncheckedIndexedAccess.json',
510+
projectService: false,
511+
tsconfigRootDir: rootDir,
512+
},
513+
},
514+
options: [{ checkArrayJoin: true }],
515+
},
475516
],
476517
});

0 commit comments

Comments
 (0)