Skip to content

Commit

Permalink
feat(eslint-plugin): rule no-base-to-string add option ignoredTypeNames
Browse files Browse the repository at this point in the history
  • Loading branch information
duduluu committed Apr 25, 2020
1 parent a98d6d8 commit c83950c
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/eslint-plugin/src/rules/no-base-to-string.ts
Expand Up @@ -16,6 +16,7 @@ type Options = [
{
/** @deprecated This option is now ignored and treated as always true, it will be removed in 3.0 */
ignoreTaggedTemplateExpressions?: boolean;
ignoredTypeNames?: string[];
},
];
type MessageIds = 'baseToString';
Expand All @@ -42,16 +43,23 @@ export default util.createRule<Options, MessageIds>({
type: 'boolean',
default: true,
},
ignoredTypeNames: {
type: 'array',
items: {
type: 'string',
},
},
},
additionalProperties: false,
},
],
type: 'suggestion',
},
defaultOptions: [{ ignoreTaggedTemplateExpressions: true }],
create(context) {
create(context, [option]) {
const parserServices = util.getParserServices(context);
const typeChecker = parserServices.program.getTypeChecker();
const ignoredTypeNames = option.ignoredTypeNames ?? [];

function checkExpression(node: TSESTree.Expression, type?: ts.Type): void {
if (node.type === AST_NODE_TYPES.Literal) {
Expand Down Expand Up @@ -89,6 +97,10 @@ export default util.createRule<Options, MessageIds>({
return Usefulness.Always;
}

if (ignoredTypeNames.includes(util.getTypeName(typeChecker, type))) {
return Usefulness.Always;
}

if (
toString.declarations.every(
({ parent }) =>
Expand Down

0 comments on commit c83950c

Please sign in to comment.