Skip to content

Commit

Permalink
fix(eslint-plugin): no-base-to-string boolean expression detect (#1969)
Browse files Browse the repository at this point in the history
  • Loading branch information
duduluu committed May 4, 2020
1 parent b35070e commit f78f13a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/eslint-plugin/docs/rules/no-base-to-string.md
Expand Up @@ -64,12 +64,12 @@ const defaultOptions: Options = {
};
```

### `ignoreTypeNames`
### `ignoredTypeNames`

A string array of type names to ignore, this is useful for types missing `toString()` (but actually has `toString()`).
There are some types missing `toString()` in old version TypeScript, like `RegExp`, `URL`, `URLSearchParams` etc.

The following patterns are considered correct with the default options `{ ignoreTypeNames: ["RegExp"] }`:
The following patterns are considered correct with the default options `{ ignoredTypeNames: ["RegExp"] }`:

```ts
`${/regex/}`;
Expand Down
5 changes: 4 additions & 1 deletion packages/eslint-plugin/src/rules/no-base-to-string.ts
Expand Up @@ -99,7 +99,10 @@ export default util.createRule<Options, MessageIds>({
}

// Patch for old version TypeScript, the Boolean type definition missing toString()
if (type.flags & ts.TypeFlags.BooleanLiteral) {
if (
type.flags & ts.TypeFlags.Boolean ||
type.flags & ts.TypeFlags.BooleanLiteral
) {
return Usefulness.Always;
}

Expand Down
Expand Up @@ -23,6 +23,7 @@ const literalListBasic: string[] = [
];

const literalListNeedParen: string[] = [
"__dirname === 'foobar'",
'{}.constructor()',
'() => {}',
'function() {}',
Expand Down

0 comments on commit f78f13a

Please sign in to comment.