Skip to content

Commit

Permalink
reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
yeonjuan committed Nov 9, 2024
1 parent 68a3db2 commit 314d371
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 12 deletions.
14 changes: 2 additions & 12 deletions packages/eslint-plugin/src/rules/no-base-to-string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,18 +240,8 @@ export default createRule<Options, MessageIds>({
return;
}

for (const part of typeParts) {
const typeArg = checker.getTypeArguments(
part as ts.TypeReference,
)[0];

const certainty = getToStringCertainty(node, typeArg);

if (certainty !== Usefulness.Always) {
checkExpression(memberExpr.object, typeArg, 'baseArrayJoin');
return;
}
}
const typeArg = type.getNumberIndexType();
checkExpression(memberExpr.object, typeArg, 'baseArrayJoin');
},
}
: undefined),
Expand Down
41 changes: 41 additions & 0 deletions packages/eslint-plugin/tests/rules/no-base-to-string.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,23 @@ String(...objects);
],
options: [{ checkArrayJoin: true }],
},
{
code: `
class Foo {}
const tuple: [string, Foo] = ['string', new Foo()];
tuple.join('');
`,
errors: [
{
data: {
certainty: 'will',
name: 'tuple',
},
messageId: 'baseArrayJoin',
},
],
options: [{ checkArrayJoin: true }],
},
{
code: `
class Foo {}
Expand All @@ -472,5 +489,29 @@ String(...objects);
],
options: [{ checkArrayJoin: true }],
},
{
code: `
class Foo {}
const tuple: [string, Foo] = ['string', new Foo()];
tuple.join('');
`,
errors: [
{
data: {
certainty: 'will',
name: 'tuple',
},
messageId: 'baseArrayJoin',
},
],
languageOptions: {
parserOptions: {
project: './tsconfig.noUncheckedIndexedAccess.json',
projectService: false,
tsconfigRootDir: rootDir,
},
},
options: [{ checkArrayJoin: true }],
},
],
});

0 comments on commit 314d371

Please sign in to comment.