Skip to content

feat(typescript-eslint): allow infinitely deep array nesting in config function and extends #10333

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

Merged
merged 3 commits into from
Nov 16, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions docs/getting-started/Quickstart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import tseslint from 'typescript-eslint';

export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
tseslint.configs.recommended,
);
```

Expand All @@ -52,6 +52,12 @@ The `.mjs` extension makes the file use the [ES modules (ESM)](https://developer

</details>

#### Details

- `tseslint.config(...)` is an **_optional_** helper function — [read more about it here](../packages/TypeScript_ESLint.mdx#config).
- `'@eslint/js'` / `eslint.configs.recommended` turns on [eslint's recommended config](https://www.npmjs.com/package/@eslint/js).
- `tseslint.configs.recommended` turns on [our recommended config](../users/Shared_Configurations.mdx#recommended).

### Step 3: Running ESLint

Open a terminal to the root of your project and run the following command:
Expand Down Expand Up @@ -82,12 +88,6 @@ pnpm eslint .

ESLint will lint all TypeScript compatible files within the current folder, and will output the results to your terminal.

## Details

- `tseslint.config(...)` is an _optional_ helper function — [read more about it here](../packages/TypeScript_ESLint.mdx#config).
- `'@eslint/js'` / `eslint.configs.recommended` turns on [eslint's recommended config](https://www.npmjs.com/package/@eslint/js).
- `...tseslint.configs.recommended` turns on [our recommended config](../users/Shared_Configurations.mdx#recommended).

## Next Steps

If you're having problems getting this working, please have a look at our [Troubleshooting & FAQs](../troubleshooting/faqs/General.mdx).
Expand All @@ -103,11 +103,11 @@ We recommend you consider enabling the following two configs:
export default tseslint.config(
eslint.configs.recommended,
// Remove this line
...tseslint.configs.recommended,
tseslint.configs.recommended,
// Add this line
...tseslint.configs.strict,
tseslint.configs.strict,
// Add this line
...tseslint.configs.stylistic,
tseslint.configs.stylistic,
);
```

Expand Down
18 changes: 9 additions & 9 deletions docs/getting-started/Typed_Linting.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import tseslint from 'typescript-eslint';
export default tseslint.config(
eslint.configs.recommended,
// Remove this line
...tseslint.configs.recommended,
tseslint.configs.recommended,
// Added lines start
...tseslint.configs.recommendedTypeChecked,
tseslint.configs.recommendedTypeChecked,
{
languageOptions: {
parserOptions: {
Expand Down Expand Up @@ -104,12 +104,12 @@ If you enabled the [`strict` shared config](../users/Shared_Configurations.mdx#s
export default tseslint.config(
eslint.configs.recommended,
// Removed lines start
...tseslint.configs.strict,
...tseslint.configs.stylistic,
tseslint.configs.strict,
tseslint.configs.stylistic,
// Removed lines end
// Added lines start
...tseslint.configs.strictTypeChecked,
...tseslint.configs.stylisticTypeChecked,
tseslint.configs.strictTypeChecked,
tseslint.configs.stylisticTypeChecked,
// Added lines end
// ...
);
Expand Down Expand Up @@ -205,8 +205,8 @@ You can combine ESLint's [overrides](https://eslint.org/docs/latest/use/configur
```js title="eslint.config.mjs"
export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
...tseslint.configs.stylisticTypeChecked,
tseslint.configs.recommendedTypeChecked,
tseslint.configs.stylisticTypeChecked,
{
languageOptions: {
parserOptions: {
Expand All @@ -218,7 +218,7 @@ export default tseslint.config(
// Added lines start
{
files: ['**/*.js'],
...tseslint.configs.disableTypeChecked,
extends: [tseslint.configs.disableTypeChecked],
},
// Added lines end
);
Expand Down
10 changes: 5 additions & 5 deletions docs/packages/TypeScript_ESLint.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import tseslint from 'typescript-eslint';

export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
tseslint.configs.recommended,
);
```

Expand Down Expand Up @@ -145,12 +145,12 @@ export default tseslint.config(
{
// disable type-aware linting on JS files
files: ['**/*.js'],
...tseslint.configs.disableTypeChecked,
extends: [tseslint.configs.disableTypeChecked],
},
{
// enable jest rules on test files
files: ['test/**'],
...jestPlugin.configs['flat/recommended'],
extends: [jestPlugin.configs['flat/recommended']],
},
);
```
Expand All @@ -172,7 +172,7 @@ import tseslint from 'typescript-eslint';

export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
tseslint.configs.recommended,
{
/*... */
},
Expand Down Expand Up @@ -216,7 +216,7 @@ export default tseslint.config({
files: ['**/*.ts'],
extends: [
eslint.configs.recommended,
...tseslint.configs.recommended,
tseslint.configs.recommended,
],
rules: {
'@typescript-eslint/array-type': 'error',
Expand Down
16 changes: 10 additions & 6 deletions docs/troubleshooting/faqs/General.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -239,18 +239,22 @@ For example, the following config enables only the recommended config's type-che
<Tabs groupId="eslint-config">
<TabItem value="Flat Config">

{/* prettier-ignore */}
```js title="eslint.config.mjs"
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';

export default tseslint.config(...tseslint.configs.recommendedTypeCheckedOnly, {
languageOptions: {
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
export default tseslint.config(
tseslint.configs.recommendedTypeCheckedOnly,
{
languageOptions: {
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
},
});
);
```

</TabItem>
Expand Down
4 changes: 2 additions & 2 deletions docs/troubleshooting/typed-linting/Monorepos.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ For each file being linted, the first matching project path will be used as its
```js title="eslint.config.mjs"
export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
tseslint.configs.recommendedTypeChecked,
{
languageOptions: {
parserOptions: {
Expand Down Expand Up @@ -110,7 +110,7 @@ Instead of globs that use `**` to recursively check all folders, prefer paths th
```js title="eslint.config.mjs"
export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
tseslint.configs.recommendedTypeChecked,
{
languageOptions: {
parserOptions: {
Expand Down
2 changes: 1 addition & 1 deletion docs/troubleshooting/typed-linting/Performance.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ import tseslint from 'typescript-eslint';

export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommendedRequiringTypeChecking,
tseslint.configs.recommendedRequiringTypeChecking,
{
languageOptions: {
parserOptions: {
Expand Down
44 changes: 31 additions & 13 deletions docs/users/Shared_Configurations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import tseslint from 'typescript-eslint';

export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
tseslint.configs.recommended,
);
```

Expand All @@ -39,8 +39,8 @@ If your project does not enable [typed linting](../getting-started/Typed_Linting
```js title="eslint.config.mjs"
export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
...tseslint.configs.stylistic,
tseslint.configs.recommended,
tseslint.configs.stylistic,
);
```

Expand Down Expand Up @@ -72,8 +72,8 @@ If your project enables [typed linting](../getting-started/Typed_Linting.mdx), w
```js title="eslint.config.mjs"
export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
...tseslint.configs.stylisticTypeChecked,
tseslint.configs.recommendedTypeChecked,
tseslint.configs.stylisticTypeChecked,
);
```

Expand Down Expand Up @@ -125,8 +125,11 @@ These rules are those whose reports are almost always for a bad practice and/or
<Tabs groupId="eslint-config">
<TabItem value="Flat Config">

{/* prettier-ignore */}
```js title="eslint.config.mjs"
export default tseslint.config(...tseslint.configs.recommended);
export default tseslint.config(
tseslint.configs.recommended,
);
```

</TabItem>
Expand All @@ -151,8 +154,11 @@ Rules newly added in this configuration are similarly useful to those in `recomm
<Tabs groupId="eslint-config">
<TabItem value="Flat Config">

{/* prettier-ignore */}
```js title="eslint.config.mjs"
export default tseslint.config(...tseslint.configs.recommendedTypeChecked);
export default tseslint.config(
tseslint.configs.recommendedTypeChecked,
);
```

</TabItem>
Expand All @@ -177,8 +183,11 @@ Rules added in `strict` are more opinionated than recommended rules and might no
<Tabs groupId="eslint-config">
<TabItem value="Flat Config">

{/* prettier-ignore */}
```js title="eslint.config.mjs"
export default tseslint.config(...tseslint.configs.strict);
export default tseslint.config(
tseslint.configs.strict,
);
```

</TabItem>
Expand Down Expand Up @@ -213,8 +222,11 @@ Rules newly added in this configuration are similarly useful (and opinionated) t
<Tabs groupId="eslint-config">
<TabItem value="Flat Config">

{/* prettier-ignore */}
```js title="eslint.config.mjs"
export default tseslint.config(...tseslint.configs.strictTypeChecked);
export default tseslint.config(
tseslint.configs.strictTypeChecked,
);
```

</TabItem>
Expand Down Expand Up @@ -249,8 +261,11 @@ These rules are generally opinionated about enforcing simpler code patterns.
<Tabs groupId="eslint-config">
<TabItem value="Flat Config">

{/* prettier-ignore */}
```js title="eslint.config.mjs"
export default tseslint.config(...tseslint.configs.stylistic);
export default tseslint.config(
tseslint.configs.stylistic,
);
```

</TabItem>
Expand Down Expand Up @@ -278,8 +293,11 @@ Rules newly added in this configuration are similarly opinionated to those in `s
<Tabs groupId="eslint-config">
<TabItem value="Flat Config">

{/* prettier-ignore */}
```js title="eslint.config.mjs"
export default tseslint.config(...tseslint.configs.stylisticTypeChecked);
export default tseslint.config(
tseslint.configs.stylisticTypeChecked,
);
```

</TabItem>
Expand Down Expand Up @@ -346,7 +364,7 @@ If you use type-aware rules from other plugins, you will need to manually disabl
```js title="eslint.config.mjs"
export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
tseslint.configs.recommendedTypeChecked,
{
languageOptions: {
parserOptions: {
Expand All @@ -358,7 +376,7 @@ export default tseslint.config(
// Added lines start
{
files: ['**/*.js'],
...tseslint.configs.disableTypeChecked,
extends: [tseslint.configs.disableTypeChecked],
},
// Added lines end
);
Expand Down
4 changes: 2 additions & 2 deletions docs/users/What_About_Formatting.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ import tseslint from 'typescript-eslint';

export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
...someOtherConfig,
tseslint.configs.recommended,
someOtherConfig,
// Add this line
prettierConfig,
);
Expand Down
22 changes: 11 additions & 11 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,15 @@ export default tseslint.config(
['@typescript-eslint/internal']: tseslintInternalPlugin,
['eslint-comments']: eslintCommentsPlugin,
['eslint-plugin']: eslintPluginPlugin,
// https://github.com/import-js/eslint-plugin-import/issues/2948
['import']: fixupPluginRules(importPlugin),
['import']: importPlugin,
['jest']: jestPlugin,
['jsdoc']: jsdocPlugin,
['jsx-a11y']: jsxA11yPlugin,
// @ts-expect-error -- https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/pull/1038
['jsx-a11y']: jsxA11yPlugin.flatConfigs.recommended.plugins['jsx-a11y'],
['perfectionist']: perfectionistPlugin,
// https://github.com/facebook/react/issues/28313
['react']: reactPlugin,
['react-hooks']: fixupPluginRules(reactHooksPlugin),
// https://github.com/jsx-eslint/eslint-plugin-react/issues/3699
['react']: fixupPluginRules(reactPlugin),
['regexp']: regexpPlugin,
['sonarjs']: sonarjsPlugin,
['unicorn']: unicornPlugin,
Expand Down Expand Up @@ -86,8 +85,8 @@ export default tseslint.config(

// extends ...
eslint.configs.recommended,
...tseslint.configs.strictTypeChecked,
...tseslint.configs.stylisticTypeChecked,
tseslint.configs.strictTypeChecked,
tseslint.configs.stylisticTypeChecked,
jsdocPlugin.configs['flat/recommended-typescript-error'],

// base config
Expand Down Expand Up @@ -457,7 +456,7 @@ export default tseslint.config(
//

{
extends: [...compat.config(eslintPluginPlugin.configs.recommended)],
extends: [eslintPluginPlugin.configs['flat/recommended']],
files: [
'packages/eslint-plugin-internal/**/*.{ts,tsx,cts,mts}',
'packages/eslint-plugin-tslint/**/*.{ts,tsx,cts,mts}',
Expand Down Expand Up @@ -563,9 +562,10 @@ export default tseslint.config(

{
extends: [
...compat.config(jsxA11yPlugin.configs.recommended),
...fixupConfigRules(compat.config(reactPlugin.configs.recommended)),
...fixupConfigRules(compat.config(reactHooksPlugin.configs.recommended)),
jsxA11yPlugin.flatConfigs.recommended,
reactPlugin.configs.flat.recommended,
// https://github.com/facebook/react/pull/30774
fixupConfigRules(compat.config(reactHooksPlugin.configs.recommended)),
],
files: ['packages/website/**/*.{ts,tsx,mts,cts,js,jsx}'],
rules: {
Expand Down
Loading
Loading