Skip to content

Commit e9576c3

Browse files
authored
Merge branch 'typescript-eslint:main' into main
2 parents d9604f3 + 0b5b08c commit e9576c3

40 files changed

+874
-207
lines changed

docs/contributing/Local_Development.mdx

-17
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,6 @@ You can run `yarn test` in any package to run its tests.
6161

6262
> [VS Code launch tasks](https://code.visualstudio.com/docs/editor/tasks) tasks are provided that allow [visual debugging](https://code.visualstudio.com/docs/editor/debugging) tests.
6363
64-
#### Code Coverage
65-
66-
We aim for 100% code coverage in all PRs when possible, except in the `website/` package.
67-
Coverage reports are generated locally whenever `yarn test` is run.
68-
69-
The `codecov` bot should also comment on your PR with the percentage, as well as links to the line-by-line coverage of each file touched by your PR.
70-
71-
#### Granular Unit Tests
72-
73-
Most tests in most packages are set up as small, self-contained unit tests.
74-
We generally prefer that to keep tests and their failure reports granular.
75-
76-
For rule tests we recommend, when reasonable:
77-
78-
- Including both `valid` and `invalid` code changes in most PRs that affect rule behavior
79-
- Limiting to one error per `invalid` case
80-
8164
### Type Checking
8265

8366
All code should pass TypeScript type checking.

docs/contributing/Pull_Requests.mdx

+28-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,26 @@ Please don't:
2525
- Comment on a closed PR
2626
- Reasoning: It is much easier for maintainers to not lose track of things if they are posted as issues. If you think there's a bug in typescript-eslint, the right way to ask is to [file a new issue](https://github.com/typescript-eslint/typescript-eslint/issues/new/choose). The issue templates include helpful & necessary practices such as making sure you're on the latest version of all our packages. You can provide the link to the relevant PR to add more context.
2727

28-
### Raising a PR
28+
### Testing Changes
29+
30+
#### Code Coverage
31+
32+
We aim for 100% code coverage in all PRs when possible, except in the `website/` package.
33+
Coverage reports are generated locally whenever `yarn test` is run.
34+
35+
The `codecov` bot also comments on each PR with its percentage, as well as links to the line-by-line coverage of each file touched by the PR.
36+
37+
#### Granular Unit Tests
38+
39+
Most tests in most packages are set up as small, self-contained unit tests.
40+
We generally prefer that to keep tests and their failure reports granular.
41+
42+
For rule tests we recommend, when reasonable:
43+
44+
- Including both `valid` and `invalid` code changes in most PRs that affect rule behavior
45+
- Limiting to one error per `invalid` case
46+
47+
### Raising the PR
2948

3049
Once your changes are ready, you can raise a PR! 🙌
3150
The title of your PR should match the following format:
@@ -84,6 +103,14 @@ Once you've addressed all our feedback by making code changes and/or started a f
84103

85104
Once the feedback is addressed, and the PR is approved, we'll ensure the branch is up to date with `main`, and merge it for you.
86105

106+
#### Updating Over Time
107+
108+
You generally don't need to keep merging commits from `main` into your PR branch.
109+
If you see merge conflicts or other intersections that worry you, then you can preemptively - but that's optional.
110+
111+
If we think merge conflicts need to be resolved in order to merge and/or review a PR, we might do that for you as a courtesy _if_ we have time.
112+
If not, we may ask you to.
113+
87114
### Asking Questions
88115

89116
If you need help and/or have a question, posting a comment in the PR is a great way to do so.

docs/maintenance/Contributor_Tiers.mdx

+16-4
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ We treat both the creation and review of issues and PRs along the rough scale of
9595
<a href="https://github.com/typescript-eslint/typescript-eslint/pull/6976">
9696
#6976
9797
</a>
98-
, <a href="https://github.com/typescript-eslint/typescript-eslint/issues/6992">#6992</a>
98+
,{' '}
99+
<a href="https://github.com/typescript-eslint/typescript-eslint/issues/6992">
100+
#6992
101+
</a>
99102
</td>
100103
</tr>
101104
<tr>
@@ -106,7 +109,10 @@ We treat both the creation and review of issues and PRs along the rough scale of
106109
<a href="https://github.com/typescript-eslint/typescript-eslint/pull/6780">
107110
#6780
108111
</a>
109-
, <a href="https://github.com/typescript-eslint/typescript-eslint/pull/6910">#6910</a>
112+
,{' '}
113+
<a href="https://github.com/typescript-eslint/typescript-eslint/pull/6910">
114+
#6910
115+
</a>
110116
</td>
111117
</tr>
112118
<tr>
@@ -117,7 +123,10 @@ We treat both the creation and review of issues and PRs along the rough scale of
117123
<a href="https://github.com/typescript-eslint/typescript-eslint/pull/6107">
118124
#6107
119125
</a>
120-
, <a href="https://github.com/typescript-eslint/typescript-eslint/pull/6907">#6907</a>
126+
,{' '}
127+
<a href="https://github.com/typescript-eslint/typescript-eslint/pull/6907">
128+
#6907
129+
</a>
121130
</td>
122131
</tr>
123132
<tr>
@@ -128,7 +137,10 @@ We treat both the creation and review of issues and PRs along the rough scale of
128137
<a href="https://github.com/typescript-eslint/typescript-eslint/pull/6084">
129138
#6084
130139
</a>
131-
, <a href="https://github.com/typescript-eslint/typescript-eslint/pull/6777">#6777</a>
140+
,{' '}
141+
<a href="https://github.com/typescript-eslint/typescript-eslint/pull/6777">
142+
#6777
143+
</a>
132144
</td>
133145
</tr>
134146
</tbody>

docs/maintenance/Releases.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ In parallel to the general PR flow of the major version:
5050

5151
In parallel to the shared config changes work, make sure to test out the beta version on popular community projects willing to try it out.
5252

53-
1. Create a pinned issue offering to try out the new version's beta for consumers [example: [Try out v6 beta on various important community repos](https://github.com/typescript-eslint/typescript-eslint/issues/6760)]
53+
1. Create a pinned issue offering to try out the new version's beta for consumers [example: [Try out v8 beta on various influential community repos](https://github.com/typescript-eslint/typescript-eslint/issues/9141)]
5454
- Ask each community project if they'd be interested in trying out the new version, such as in their Discord or on their issue tracker.
5555
- Each community project that's indicated willingness to receive a PR should have one.
5656
1. Once the proposed _Shared Config Changes_ are merged into the `v${major}` branch, send a draft PR to each project with the new beta version.

docs/packages/Parser.mdx

+28
Original file line numberDiff line numberDiff line change
@@ -402,3 +402,31 @@ module.exports = {
402402

403403
</TabItem>
404404
</Tabs>
405+
406+
### `withoutProjectParserOptions(parserOptions)`
407+
408+
Removes options that prompt the parser to parse the project with type information.
409+
In other words, you can use this if you are invoking the parser directly, to ensure that one file will be parsed in isolation, which is much faster.
410+
411+
This is useful in cases where you invoke the parser directly, such as in an ESLint plugin context.
412+
413+
```ts
414+
declare function withoutProjectParserOptions(
415+
options: TSESTreeOptions,
416+
): TSESTreeOptions;
417+
```
418+
419+
Example usage:
420+
421+
```js title="somePlugin.js"
422+
const parser = require('@typescript-eslint/parser');
423+
424+
function parse(path, content, context) {
425+
const contextParserOptions = context.languageOptions?.parserOptions ?? {};
426+
const parserOptions =
427+
parser.withoutProjectParserOptions(contextParserOptions);
428+
429+
// Do something with the cleaned-up options eventually, such as invoking the parser
430+
parser.parseForESLint(content, parserOptions);
431+
}
432+
```

docs/troubleshooting/FAQ.mdx

+3-3
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ These errors are caused by an ESLint config requesting type information be gener
115115
- If you **do** want to lint the file with [type-aware linting](../getting-started/Typed_Linting.mdx):
116116
- Check the `include` option of each of the TSConfigs that you provide to `parserOptions.project` - you must ensure that all files match an `include` glob, or else our tooling will not be able to find it.
117117
- If the file is a `.cjs`, `.js`, or `.mjs` file, make sure [`allowJs`](https://www.typescriptlang.org/tsconfig#allowJs) is enabled.
118-
- If your file shouldn't be a part of one of your existing tsconfigs (for example, it is a script/tool local to the repo), then consider creating a new tsconfig (we advise calling it `tsconfig.eslint.json`) in your project root which lists this file in its `include`. For an example of this, you can check out the configuration we use in this repo:
119-
- [`tsconfig.eslint.json`](https://github.com/typescript-eslint/typescript-eslint/blob/main/tsconfig.eslint.json)
120-
- [`eslint.config.mjs`](https://github.com/typescript-eslint/typescript-eslint/blob/main/eslint.config.mjs)
118+
- If your file shouldn't be a part of one of your existing tsconfigs (for example, it is a script/tool local to the repo), then consider creating a new tsconfig (we advise calling it `tsconfig.eslint.json`) in your project root which lists this file in its `include`. For an example of this, you can check out the configuration we previously used in this repo:
119+
- [`tsconfig.eslint.json`](https://github.com/typescript-eslint/typescript-eslint/blob/958fecaef10a26792dc00e936e98cb19fd26d05f/tsconfig.eslint.json)
120+
- [`eslint.config.mjs`](https://github.com/typescript-eslint/typescript-eslint/blob/958fecaef10a26792dc00e936e98cb19fd26d05f/.eslintrc.js)
121121

122122
<!-- prettier-ignore-end -->
123123

docs/troubleshooting/Formatting.mdx

+5
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ Per [ESLint's 2020 Changes to Rule Policies blog post](https://eslint.org/blog/2
114114
We mirror the ESLint team's move away from _formatting_ and _stylistic_ rules.
115115
With the exception of bug fixes, no new formatting- or stylistic-related pull requests will be accepted into typescript-eslint.
116116

117+
:::note
118+
The [`stylistic` configurations](../users/Shared_Configurations.mdx#stylistic) are not deprecated or recommended-against.
119+
We'll continue to include those configs and their rules to help enforce TypeScript-related stylistic consistency for the foreseeable future.
120+
:::
121+
117122
## `eslint-stylistic`
118123

119124
The downside of using a comprehensive formatter for formatting is that it will strictly apply opinions to code.

docs/users/Shared_Configurations.mdx

+27-2
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,15 @@ module.exports = {
184184
Some rules also enabled in `recommended` default to more strict settings in this configuration.
185185
See [`configs/strict.ts`](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/strict.ts) for the exact contents of this config.
186186

187-
:::caution
187+
:::tip
188188
We recommend a TypeScript project extend from `plugin:@typescript-eslint/strict` only if a nontrivial percentage of its developers are highly proficient in TypeScript.
189189
:::
190190

191+
:::warning
192+
This configuration is not considered "stable" under Semantic Versioning (semver).
193+
Its enabled rules and/or their options may change outside of major version updates.
194+
:::
195+
191196
### `strict-type-checked`
192197

193198
Contains all of `recommended`, `recommended-type-checked`, and `strict`, along with additional strict rules that require type information.
@@ -215,10 +220,15 @@ module.exports = {
215220
Some rules also enabled in `recommended-type-checked` default to more strict settings in this configuration.
216221
See [`configs/strict-type-checked.ts`](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/strict-type-checked.ts) for the exact contents of this config.
217222

218-
:::caution
223+
:::tip
219224
We recommend a TypeScript project extend from `plugin:@typescript-eslint/strict-type-checked` only if a nontrivial percentage of its developers are highly proficient in TypeScript.
220225
:::
221226

227+
:::warning
228+
This configuration is not considered "stable" under Semantic Versioning (semver).
229+
Its enabled rules and/or their options may change outside of major version updates.
230+
:::
231+
222232
### `stylistic`
223233

224234
Rules considered to be best practice for modern TypeScript codebases, but that do not impact program logic.
@@ -293,6 +303,11 @@ We do not recommend TypeScript projects extend from `plugin:@typescript-eslint/a
293303
Many rules conflict with each other and/or are intended to be configured per-project.
294304
:::
295305

306+
:::warning
307+
This configuration is not considered "stable" under Semantic Versioning (semver).
308+
Its enabled rules and/or their options may change outside of major version updates.
309+
:::
310+
296311
### `base`
297312

298313
A minimal ruleset that sets only the required parser and plugin options needed to run typescript-eslint.
@@ -366,6 +381,11 @@ module.exports = {
366381
</TabItem>
367382
</Tabs>
368383

384+
:::warning
385+
This configuration is not considered "stable" under Semantic Versioning (semver).
386+
Its enabled rules and/or their options may change outside of major version updates.
387+
:::
388+
369389
### `eslint-recommended`
370390

371391
This ruleset is meant to be used after extending `eslint:recommended`.
@@ -427,6 +447,11 @@ module.exports = {
427447

428448
See [`configs/strict-type-checked-only.ts`](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/strict-type-checked-only.ts) for the exact contents of this config.
429449

450+
:::warning
451+
This configuration is not considered "stable" under Semantic Versioning (semver).
452+
Its enabled rules and/or their options may change outside of major version updates.
453+
:::
454+
430455
### `stylistic-type-checked-only`
431456

432457
A version of `stylistic` that _only_ contains type-checked rules and disables of any corresponding core ESLint rules.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
"ncp": "^2.0.0",
113113
"netlify": "^13.1.14",
114114
"nx": "18.3.5",
115-
"prettier": "3.2.5",
115+
"prettier": "3.3.0",
116116
"pretty-format": "^29.7.0",
117117
"rimraf": "^5.0.5",
118118
"tmp": "^0.2.1",

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import TabItem from '@theme/TabItem';
1010
> See **https://typescript-eslint.io/rules/no-base-to-string** for documentation.
1111
1212
JavaScript will call `toString()` on an object when it is converted to a string, such as when `+` adding to a string or in `${}` template literals.
13-
The default Object `.toString()` returns `"[object Object]"`, which is often not what was intended.
13+
The default Object `.toString()` uses the format `"[object Object]"`, which is often not what was intended.
1414
This rule reports on stringified values that aren't primitives and don't define a more useful `.toString()` method.
1515

1616
> Note that `Function` provides its own `.toString()` that returns the function's code.

packages/eslint-plugin/docs/rules/no-misused-promises.mdx

+18-20
Original file line numberDiff line numberDiff line change
@@ -127,19 +127,18 @@ Examples of code for this rule with `checksVoidReturn: true`:
127127

128128
```ts option='{ "checksVoidReturn": true }'
129129
[1, 2, 3].forEach(async value => {
130-
await doSomething(value);
130+
await fetch(`/${value}`);
131131
});
132132

133-
new Promise(async (resolve, reject) => {
134-
await doSomething();
133+
new Promise<void>(async (resolve, reject) => {
134+
await fetch('/');
135135
resolve();
136136
});
137137

138-
const eventEmitter = new EventEmitter();
139-
eventEmitter.on('some-event', async () => {
140-
synchronousCall();
141-
await doSomething();
142-
otherSynchronousCall();
138+
document.addEventListener('click', async () => {
139+
console.log('synchronous call');
140+
await fetch('/');
141+
console.log('synchronous call');
143142
});
144143
```
145144

@@ -169,8 +168,7 @@ new Promise((resolve, reject) => {
169168
});
170169

171170
// Name the async wrapper to call it later
172-
const eventEmitter = new EventEmitter();
173-
eventEmitter.on('some-event', () => {
171+
document.addEventListener('click', () => {
174172
const handler = async () => {
175173
await doSomething();
176174
otherSynchronousCall();
@@ -210,30 +208,30 @@ Examples of code for this rule with `checksSpreads: true`:
210208
<TabItem value="❌ Incorrect">
211209

212210
```ts option='{ "checksSpreads": true }'
213-
const getData = () => someAsyncOperation({ myArg: 'foo' });
211+
const getData = () => fetch('/');
214212

215-
return { foo: 42, ...getData() };
213+
console.log({ foo: 42, ...getData() });
216214

217-
const getData2 = async () => {
218-
await someAsyncOperation({ myArg: 'foo' });
215+
const awaitData = async () => {
216+
await fetch('/');
219217
};
220218

221-
return { foo: 42, ...getData2() };
219+
console.log({ foo: 42, ...awaitData() });
222220
```
223221

224222
</TabItem>
225223
<TabItem value="✅ Correct">
226224

227225
```ts option='{ "checksSpreads": true }'
228-
const getData = () => someAsyncOperation({ myArg: 'foo' });
226+
const getData = () => fetch('/');
229227

230-
return { foo: 42, ...(await getData()) };
228+
console.log({ foo: 42, ...(await getData()) });
231229

232-
const getData2 = async () => {
233-
await someAsyncOperation({ myArg: 'foo' });
230+
const awaitData = async () => {
231+
await fetch('/');
234232
};
235233

236-
return { foo: 42, ...(await getData2()) };
234+
console.log({ foo: 42, ...(await awaitData()) });
237235
```
238236

239237
</TabItem>

packages/eslint-plugin/docs/rules/prefer-readonly-parameter-types.mdx

+5
Original file line numberDiff line numberDiff line change
@@ -402,3 +402,8 @@ function foo(arg: MyType) {}
402402
## When Not To Use It
403403

404404
If your project does not attempt to enforce strong immutability guarantees of parameters, you can avoid this rule.
405+
406+
This rule is very strict on what it considers mutable.
407+
Many types that describe themselves as readonly are considered mutable because they have mutable properties such as arrays or tuples.
408+
To work around these limitations, you might need to use the rule's options.
409+
In particular, the [`allow` option](#allow) can explicitly mark a type as readonly.

packages/eslint-plugin/docs/rules/restrict-template-expressions.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import TabItem from '@theme/TabItem';
1010
> See **https://typescript-eslint.io/rules/restrict-template-expressions** for documentation.
1111
1212
JavaScript automatically [converts an object to a string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#string_coercion) in a string context, such as when concatenating it with a string using `+` or embedding it in a template literal using `${}`.
13-
The default `toString()` method of objects returns `"[object Object]"`, which is often not what was intended.
13+
The default `toString()` method of objects uses the format `"[object Object]"`, which is often not what was intended.
1414
This rule reports on values used in a template literal string that aren't strings, optionally allowing other data types that provide useful stringification results.
1515

1616
:::note

packages/eslint-plugin/docs/rules/sort-type-constituents.mdx

+6-9
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ import TabItem from '@theme/TabItem';
99
>
1010
> See **https://typescript-eslint.io/rules/sort-type-constituents** for documentation.
1111
12+
:::danger Deprecated
13+
This rule has been deprecated in favor of the [`perfectionist/sort-intersection-types`](https://eslint-plugin-perfectionist.azat.io/rules/sort-intersection-types) and [`perfectionist/sort-union-types`](https://eslint-plugin-perfectionist.azat.io/rules/sort-union-types) rules.
14+
15+
See [Docs: Deprecate sort-type-constituents in favor of eslint-plugin-perfectionist](https://github.com/typescript-eslint/typescript-eslint/issues/8915) and [eslint-plugin: Feature freeze naming and sorting stylistic rules](https://github.com/typescript-eslint/typescript-eslint/issues/8792) for more information.
16+
:::
17+
1218
Sorting union (`|`) and intersection (`&`) types can help:
1319

1420
- keep your codebase standardized
@@ -19,15 +25,6 @@ This rule reports on any types that aren't sorted alphabetically.
1925

2026
> Types are sorted case-insensitively and treating numbers like a human would, falling back to character code sorting in case of ties.
2127
22-
:::note
23-
This rule is _feature frozen_: it will no longer receive new features such as new options.
24-
It still will accept bug and documentation fixes for its existing area of features.
25-
26-
Stylistic rules that enforce naming and/or sorting conventions tend to grow incomprehensibly complex as increasingly obscure features are requested.
27-
This rule has reached the limit of what is reasonable for the typescript-eslint project to maintain.
28-
See [eslint-plugin: Feature freeze naming and sorting stylistic rules](https://github.com/typescript-eslint/typescript-eslint/issues/8792) for more information.
29-
:::
30-
3128
## Examples
3229

3330
<Tabs>

0 commit comments

Comments
 (0)