Skip to content

Commit fa670da

Browse files
authored
Merge branch 'main' into fix-token-type-of-property-name
2 parents 274dd01 + 9dc91aa commit fa670da

40 files changed

+2218
-493
lines changed

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
## 8.35.0 (2025-06-23)
2+
3+
### 🚀 Features
4+
5+
- **eslint-plugin:** [no-base-to-string] add checkUnknown Option ([#11128](https://github.com/typescript-eslint/typescript-eslint/pull/11128))
6+
7+
### 🩹 Fixes
8+
9+
- **website:** acquired types are shown in the editor but not reflected in linting ([#11198](https://github.com/typescript-eslint/typescript-eslint/pull/11198))
10+
11+
### ❤️ Thank You
12+
13+
- Kim Sang Du @developer-bandi
14+
- mdm317
15+
16+
You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.
17+
118
## 8.34.1 (2025-06-16)
219

320
### 🩹 Fixes

docs/getting-started/Typed_Linting.mdx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@ export default tseslint.config(
4040
);
4141
```
4242

43-
:::note
44-
[`import.meta.dirname`](https://nodejs.org/api/esm.html#importmetadirname) is only present for ESM files in Node.js >=20.11.0 / >= 21.2.0.<br />
45-
For CommonJS modules and/or older versions of Node.js, [use `__dirname` or an alternative](https://stackoverflow.com/questions/46745014/alternative-for-dirname-in-node-js-when-using-es6-modules).
46-
:::
47-
4843
In more detail:
4944

5045
- `tseslint.configs.recommendedTypeChecked` is a [shared configuration](../users/Shared_Configurations.mdx). It contains recommended rules that additionally require type information.

packages/ast-spec/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 8.35.0 (2025-06-23)
2+
3+
This was a version bump only for ast-spec to align it with other projects, there were no code changes.
4+
5+
You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.
6+
17
## 8.34.1 (2025-06-16)
28

39
### 🩹 Fixes

packages/ast-spec/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@typescript-eslint/ast-spec",
3-
"version": "8.34.1",
3+
"version": "8.35.0",
44
"description": "Complete specification for the TypeScript-ESTree AST",
55
"private": true,
66
"keywords": [

packages/eslint-plugin/CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
## 8.35.0 (2025-06-23)
2+
3+
### 🚀 Features
4+
5+
- **eslint-plugin:** [no-base-to-string] add checkUnknown Option ([#11128](https://github.com/typescript-eslint/typescript-eslint/pull/11128))
6+
7+
### ❤️ Thank You
8+
9+
- Kim Sang Du @developer-bandi
10+
11+
You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.
12+
113
## 8.34.1 (2025-06-16)
214

315
This was a version bump only for eslint-plugin to align it with other projects, there were no code changes.

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,17 @@ let text = `${value}`;
9999
String(/regex/);
100100
```
101101

102+
### `checkUnknown`
103+
104+
{/* insert option description */}
105+
106+
The following patterns are considered incorrect with the options `{ checkUnknown: true }`:
107+
108+
```ts option='{ "checkUnknown": true }' showPlaygroundButton
109+
declare const x: unknown;
110+
String(x);
111+
```
112+
102113
## When Not To Use It
103114

104115
If you don't mind a risk of `"[object Object]"` or incorrect type coercions in your values, then you will not need this rule.

packages/eslint-plugin/package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@typescript-eslint/eslint-plugin",
3-
"version": "8.34.1",
3+
"version": "8.35.0",
44
"description": "TypeScript plugin for ESLint",
55
"files": [
66
"dist",
@@ -60,10 +60,10 @@
6060
},
6161
"dependencies": {
6262
"@eslint-community/regexpp": "^4.10.0",
63-
"@typescript-eslint/scope-manager": "8.34.1",
64-
"@typescript-eslint/type-utils": "8.34.1",
65-
"@typescript-eslint/utils": "8.34.1",
66-
"@typescript-eslint/visitor-keys": "8.34.1",
63+
"@typescript-eslint/scope-manager": "8.35.0",
64+
"@typescript-eslint/type-utils": "8.35.0",
65+
"@typescript-eslint/utils": "8.35.0",
66+
"@typescript-eslint/visitor-keys": "8.35.0",
6767
"graphemer": "^1.4.0",
6868
"ignore": "^7.0.0",
6969
"natural-compare": "^1.4.0",
@@ -72,8 +72,8 @@
7272
"devDependencies": {
7373
"@types/mdast": "^4.0.3",
7474
"@types/natural-compare": "*",
75-
"@typescript-eslint/rule-schema-to-typescript-types": "8.34.1",
76-
"@typescript-eslint/rule-tester": "8.34.1",
75+
"@typescript-eslint/rule-schema-to-typescript-types": "8.35.0",
76+
"@typescript-eslint/rule-tester": "8.35.0",
7777
"@vitest/coverage-v8": "^3.1.3",
7878
"ajv": "^6.12.6",
7979
"cross-fetch": "*",
@@ -93,7 +93,7 @@
9393
"vitest": "^3.1.3"
9494
},
9595
"peerDependencies": {
96-
"@typescript-eslint/parser": "^8.34.1",
96+
"@typescript-eslint/parser": "^8.35.0",
9797
"eslint": "^8.57.0 || ^9.0.0",
9898
"typescript": ">=4.8.4 <5.9.0"
9999
},

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ enum Usefulness {
2121
export type Options = [
2222
{
2323
ignoredTypeNames?: string[];
24+
checkUnknown?: boolean;
2425
},
2526
];
2627
export type MessageIds = 'baseArrayJoin' | 'baseToString';
@@ -46,6 +47,10 @@ export default createRule<Options, MessageIds>({
4647
type: 'object',
4748
additionalProperties: false,
4849
properties: {
50+
checkUnknown: {
51+
type: 'boolean',
52+
description: 'Whether to also check values of type `unknown`',
53+
},
4954
ignoredTypeNames: {
5055
type: 'array',
5156
description:
@@ -60,6 +65,7 @@ export default createRule<Options, MessageIds>({
6065
},
6166
defaultOptions: [
6267
{
68+
checkUnknown: false,
6369
ignoredTypeNames: ['Error', 'RegExp', 'URL', 'URLSearchParams'],
6470
},
6571
],
@@ -76,6 +82,7 @@ export default createRule<Options, MessageIds>({
7682
type ?? services.getTypeAtLocation(node),
7783
new Set(),
7884
);
85+
7986
if (certainty === Usefulness.Always) {
8087
return;
8188
}
@@ -213,7 +220,7 @@ export default createRule<Options, MessageIds>({
213220
return collectToStringCertainty(constraint, visited);
214221
}
215222
// unconstrained generic means `unknown`
216-
return Usefulness.Always;
223+
return option.checkUnknown ? Usefulness.Sometimes : Usefulness.Always;
217224
}
218225

219226
// the Boolean type definition missing toString()
@@ -251,8 +258,13 @@ export default createRule<Options, MessageIds>({
251258
const toString =
252259
checker.getPropertyOfType(type, 'toString') ??
253260
checker.getPropertyOfType(type, 'toLocaleString');
261+
254262
if (!toString) {
255-
// e.g. any/unknown
263+
// unknown
264+
if (option.checkUnknown && type.flags === ts.TypeFlags.Unknown) {
265+
return Usefulness.Sometimes;
266+
}
267+
// e.g. any
256268
return Usefulness.Always;
257269
}
258270

packages/eslint-plugin/tests/docs-eslint-output-snapshots/no-base-to-string.shot

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/eslint-plugin/tests/rules/ban-tslint-comment.test.ts

Lines changed: 115 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,6 @@ import { RuleTester } from '@typescript-eslint/rule-tester';
22

33
import rule from '../../src/rules/ban-tslint-comment';
44

5-
interface Testable {
6-
code: string;
7-
column?: number;
8-
line?: number;
9-
output?: string;
10-
text?: string;
11-
}
12-
13-
const PALANTIR_EXAMPLES: Testable[] = [
14-
{ code: '/* tslint:disable */' }, // Disable all rules for the rest of the file
15-
{ code: '/* tslint:enable */' }, // Enable all rules for the rest of the file
16-
{
17-
code: '/* tslint:disable:rule1 rule2 rule3... */',
18-
}, // Disable the listed rules for the rest of the file
19-
{
20-
code: '/* tslint:enable:rule1 rule2 rule3... */',
21-
}, // Enable the listed rules for the rest of the file
22-
{ code: '// tslint:disable-next-line' }, // Disables all rules for the following line
23-
{
24-
code: 'someCode(); // tslint:disable-line',
25-
column: 13,
26-
output: 'someCode();',
27-
text: '// tslint:disable-line',
28-
}, // Disables all rules for the current line
29-
{
30-
code: '// tslint:disable-next-line:rule1 rule2 rule3...',
31-
}, // Disables the listed rules for the next line
32-
];
33-
34-
// prettier-ignore
35-
const MORE_EXAMPLES: Testable[] = [
36-
{
37-
code: `const woah = doSomeStuff();
38-
// tslint:disable-line
39-
console.log(woah);
40-
`,
41-
line: 2,
42-
output: `const woah = doSomeStuff();
43-
console.log(woah);
44-
`,
45-
text: '// tslint:disable-line',
46-
},
47-
]
48-
495
const ruleTester = new RuleTester();
506

517
ruleTester.run('ban-tslint-comment', rule, {
@@ -66,18 +22,123 @@ ruleTester.run('ban-tslint-comment', rule, {
6622
code: '/* another comment that mentions tslint */',
6723
},
6824
],
69-
invalid: [...PALANTIR_EXAMPLES, ...MORE_EXAMPLES].map(
70-
({ code, column, line, output, text }) => ({
71-
code,
25+
invalid: [
26+
{
27+
code: '/* tslint:disable */',
28+
errors: [
29+
{
30+
column: 1,
31+
data: {
32+
text: '/* tslint:disable */',
33+
},
34+
line: 1,
35+
messageId: 'commentDetected',
36+
},
37+
],
38+
output: '',
39+
},
40+
{
41+
code: '/* tslint:enable */',
42+
errors: [
43+
{
44+
column: 1,
45+
data: {
46+
text: '/* tslint:enable */',
47+
},
48+
line: 1,
49+
messageId: 'commentDetected',
50+
},
51+
],
52+
output: '',
53+
},
54+
{
55+
code: '/* tslint:disable:rule1 rule2 rule3... */',
56+
errors: [
57+
{
58+
column: 1,
59+
data: {
60+
text: '/* tslint:disable:rule1 rule2 rule3... */',
61+
},
62+
line: 1,
63+
messageId: 'commentDetected',
64+
},
65+
],
66+
output: '',
67+
},
68+
{
69+
code: '/* tslint:enable:rule1 rule2 rule3... */',
70+
errors: [
71+
{
72+
column: 1,
73+
data: {
74+
text: '/* tslint:enable:rule1 rule2 rule3... */',
75+
},
76+
line: 1,
77+
messageId: 'commentDetected',
78+
},
79+
],
80+
output: '',
81+
},
82+
{
83+
code: '// tslint:disable-next-line',
84+
errors: [
85+
{
86+
column: 1,
87+
data: {
88+
text: '// tslint:disable-next-line',
89+
},
90+
line: 1,
91+
messageId: 'commentDetected',
92+
},
93+
],
94+
output: '',
95+
},
96+
{
97+
code: 'someCode(); // tslint:disable-line',
7298
errors: [
7399
{
74-
column: column ?? 1,
75-
data: { text: text ?? code },
76-
line: line ?? 1,
77-
messageId: 'commentDetected' as const,
100+
column: 13,
101+
data: {
102+
text: '// tslint:disable-line',
103+
},
104+
line: 1,
105+
messageId: 'commentDetected',
78106
},
79107
],
80-
output: output ?? '',
81-
}),
82-
),
108+
output: 'someCode();',
109+
},
110+
{
111+
code: '// tslint:disable-next-line:rule1 rule2 rule3...',
112+
errors: [
113+
{
114+
column: 1,
115+
data: { text: '// tslint:disable-next-line:rule1 rule2 rule3...' },
116+
line: 1,
117+
messageId: 'commentDetected',
118+
},
119+
],
120+
output: '',
121+
},
122+
{
123+
code: `
124+
const woah = doSomeStuff();
125+
// tslint:disable-line
126+
console.log(woah);
127+
`,
128+
errors: [
129+
{
130+
column: 1,
131+
data: {
132+
text: '// tslint:disable-line',
133+
},
134+
line: 3,
135+
messageId: 'commentDetected',
136+
},
137+
],
138+
output: `
139+
const woah = doSomeStuff();
140+
console.log(woah);
141+
`,
142+
},
143+
],
83144
});

0 commit comments

Comments
 (0)