Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(eslint-plugin): no-base-to-string boolean expression detect #1969

Merged
merged 2 commits into from May 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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