Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f78f13a

Browse files
authored
fix(eslint-plugin): no-base-to-string boolean expression detect (typescript-eslint#1969)
1 parent b35070e commit f78f13a

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

packages/eslint-plugin/docs/rules/no-base-to-string.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ const defaultOptions: Options = {
6464
};
6565
```
6666

67-
### `ignoreTypeNames`
67+
### `ignoredTypeNames`
6868

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

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

7474
```ts
7575
`${/regex/}`;

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@ export default util.createRule<Options, MessageIds>({
9999
}
100100

101101
// Patch for old version TypeScript, the Boolean type definition missing toString()
102-
if (type.flags & ts.TypeFlags.BooleanLiteral) {
102+
if (
103+
type.flags & ts.TypeFlags.Boolean ||
104+
type.flags & ts.TypeFlags.BooleanLiteral
105+
) {
103106
return Usefulness.Always;
104107
}
105108

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const literalListBasic: string[] = [
2323
];
2424

2525
const literalListNeedParen: string[] = [
26+
"__dirname === 'foobar'",
2627
'{}.constructor()',
2728
'() => {}',
2829
'function() {}',

0 commit comments

Comments
 (0)