Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

docs: updated Getting Started and related docs for flat config#8423

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Show file tree
Hide file tree
Changes fromall 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
46 changes: 24 additions & 22 deletionsdocs/Getting_Started.mdx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,31 +7,34 @@ title: Getting Started

These steps will get you running ESLint with our recommended rules on your TypeScript code as quickly as possible.

:::note
This page is for [ESLint's new "flat" config format](https://eslint.org/docs/latest/use/configure/configuration-files-new).
See [Legacy ESLint Setup](./linting/Legacy_ESLint_Setup.mdx) for [ESLint's legacy format](https://eslint.org/docs/latest/use/configure/configuration-files).
:::

### Step 1: Installation

First, install the required packages for [ESLint](https://eslint.org), [TypeScript](https://typescriptlang.org), and this plugin:

```bash npm2yarn
npm install --save-dev@typescript-eslint/parser @typescript-eslint/eslint-plugin eslinttypescript
npm install --save-dev eslinttypescripttypescript-eslint
```

### Step 2: Configuration

Next, create a `.eslintrc.cjs` config file in the root of your project, and populate it with the following:
Next, create a `eslint.config.js` config file in the root of your project, and populate it with the following:

```js title=".eslintrc.cjs"
/* eslint-env node */
module.exports = {
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
root: true,
};
```
```js title="eslint.config.js"
// @ts-check

:::info
If your project doesn't use ESM, naming the file as `.eslintrc.js` is fine. See [ESLint's Configuration Files docs](https://eslint.org/docs/user-guide/configuring/configuration-files) for more info.
:::
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';

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

### Step 3: Running ESLint

Expand DownExpand Up@@ -65,14 +68,13 @@ ESLint will lint all TypeScript compatible files within the current folder, and

## Details

- `parser: '@typescript-eslint/parser'` tells ESLint to use the [`@typescript-eslint/parser`](./packages/Parser.mdx) package you installed to parse your source files.
- This is required, or else ESLint will throw errors as it tries to parse TypeScript code as if it were regular JavaScript.
- `plugins: ['@typescript-eslint']` tells ESLint to load the [`@typescript-eslint/eslint-plugin`](./packages/ESLint_Plugin.mdx) package as a plugin.
- This allows you to use typescript-eslint's rules within your codebase.
- `extends: [ ... ]` tells ESLint that your config extends the given configurations.
- `eslint:recommended` is ESLint's inbuilt "recommended" config - it turns on a small, sensible set of rules which lint for well-known best-practices.
- `plugin:@typescript-eslint/recommended` is our "recommended" config - it's similar to `eslint:recommended`, except it turns on TypeScript-specific rules from our plugin.
- `root: true` is a generally good ESLint practice to indicate this file is the root-level one used by the project and ESLint should not search beyond this directory for config files.
The [`config`](./packages/TypeScript_ESLint.mdx) helper sets three parts of ESLint:

- [Parser](https://eslint.org/docs/latest/use/configure/parser): set to [`@typescript-eslint/parser`](./packages/Parser.mdx) so ESLint knows how to parse the new pieces of TypeScript syntax.
- [Plugins](https://eslint.org/docs/latest/use/configure/plugins): set to [`@typescript-eslint/eslint-plugin`](./packages/ESLint_Plugin.mdx) to load [rules listed in our _Rules_ page](./Rules).
- [Rules](https://eslint.org/docs/latest/use/configure/rules): extends from our [recommended configuration](http://localhost:3000/linting/configs#recommended) to enable our most commonly useful lint rules.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

dangit


See [ESLint's Configuration Files docs](https://eslint.org/docs/user-guide/configuring/configuration-files) for more details on configuring ESLint.

## Next Steps

Expand Down
171 changes: 170 additions & 1 deletiondocs/linting/Configurations.mdx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,9 @@ id: configs
title: Configurations
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

[ESLint shareable configurations](https://eslint.org/docs/latest/developer-guide/shareable-configs) exist to provide a comprehensive list of rules settings that you can start with.
`@typescript-eslint/eslint-plugin` includes built-in configurations you can extend from to pull in the recommended starting rules.

Expand All@@ -15,6 +18,20 @@ title: Configurations

If your project does not enable [typed linting](./Typed_Linting.mdx), we suggest enabling the [`recommended`](#recommended) and [`stylistic`](#stylistic) configurations to start:

<Tabs groupId="eslint-config">
<TabItem value="Flat Config">

```js title="eslint.config.js"
export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
...tseslint.configs.stylistic,
);
```

</TabItem>
<TabItem value="Legacy Config">

```js title=".eslintrc.js"
module.exports = {
extends: [
Expand All@@ -25,12 +42,29 @@ module.exports = {
};
```

</TabItem>
</Tabs>

> If a majority of developers working on your project are comfortable with TypeScript and typescript-eslint, consider replacing `recommended` with `strict`.

### Projects With Type Checking

If your project enables [typed linting](./Typed_Linting.mdx), we suggest enabling the [`recommended-type-checked`](#recommended-type-checked) and [`stylistic-type-checked`](#stylistic-type-checked) configurations to start:

<Tabs groupId="eslint-config">
<TabItem value="Flat Config">

```js title="eslint.config.js"
export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
...tseslint.configs.stylisticTypeChecked,
);
```

</TabItem>
<TabItem value="Legacy Config">

```js title=".eslintrc.js"
module.exports = {
extends: [
Expand All@@ -41,6 +75,9 @@ module.exports = {
};
```

</TabItem>
</Tabs>

> If a majority of developers working on your project are comfortable with TypeScript and typescript-eslint, consider replacing `recommended-type-checked` with `strict-type-checked`.

## Recommended Configurations
Expand DownExpand Up@@ -70,38 +107,77 @@ Recommended rules for code correctness that you can drop in without additional c
These rules are those whose reports are almost always for a bad practice and/or likely bug.
`recommended` also disables core ESLint rules known to conflict with typescript-eslint rules or cause issues in TypeScript codebases.

<Tabs groupId="eslint-config">
<TabItem value="Flat Config">

```js title="eslint.config.js"
export default tseslint.config(...tseslint.configs.recommended);
```

</TabItem>
<TabItem value="Legacy Config">

```js title=".eslintrc.js"
module.exports = {
extends: ['plugin:@typescript-eslint/recommended'],
};
```

</TabItem>
</Tabs>

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

### `recommended-type-checked`

Contains all of `recommended` along with additional recommended rules that require type information.
Rules newly added in this configuration are similarly useful to those in `recommended`.

<Tabs groupId="eslint-config">
<TabItem value="Flat Config">

```js title="eslint.config.js"
export default tseslint.config(...tseslint.configs.recommendedTypeChecked);
```

</TabItem>
<TabItem value="Legacy Config">

```js title=".eslintrc.js"
module.exports = {
extends: ['plugin:@typescript-eslint/recommended-type-checked'],
};
```

</TabItem>
</Tabs>

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

### `strict`

Contains all of `recommended`, as well as additional strict rules that can also catch bugs.
Rules added in `strict` are more opinionated than recommended rules and might not apply to all projects.

<Tabs groupId="eslint-config">
<TabItem value="Flat Config">

```js title="eslint.config.js"
export default tseslint.config(...tseslint.configs.strict);
```

</TabItem>
<TabItem value="Legacy Config">

```js title=".eslintrc.js"
module.exports = {
extends: ['plugin:@typescript-eslint/strict'],
};
```

</TabItem>
</Tabs>

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.

:::caution
Expand All@@ -113,12 +189,25 @@ We recommend a TypeScript project extend from `plugin:@typescript-eslint/strict`
Contains all of `recommended`, `recommended-type-checked`, and `strict`, along with additional strict rules that require type information.
Rules newly added in this configuration are similarly useful (and opinionated) to those in `strict`.

<Tabs groupId="eslint-config">
<TabItem value="Flat Config">

```js title="eslint.config.js"
export default tseslint.config(...tseslint.configs.strictTypeChecked);
```

</TabItem>
<TabItem value="Legacy Config">

```js title=".eslintrc.js"
module.exports = {
extends: ['plugin:@typescript-eslint/strict-type-checked'],
};
```

</TabItem>
</Tabs>

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.

:::caution
Expand All@@ -130,25 +219,51 @@ We recommend a TypeScript project extend from `plugin:@typescript-eslint/strict-
Rules considered to be best practice for modern TypeScript codebases, but that do not impact program logic.
These rules are generally opinionated about enforcing simpler code patterns.

<Tabs groupId="eslint-config">
<TabItem value="Flat Config">

```js title="eslint.config.js"
export default tseslint.config(...tseslint.configs.stylistic);
```

</TabItem>
<TabItem value="Legacy Config">

```js title=".eslintrc.js"
module.exports = {
extends: ['plugin:@typescript-eslint/stylistic'],
};
```

</TabItem>
</Tabs>

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

### `stylistic-type-checked`

Contains all of `stylistic`, along with additional stylistic rules that require type information.
Rules newly added in this configuration are similarly opinionated to those in `stylistic`.

<Tabs groupId="eslint-config">
<TabItem value="Flat Config">

```js title="eslint.config.js"
export default tseslint.config(...tseslint.configs.stylisticTypeChecked);
```

</TabItem>
<TabItem value="Legacy Config">

```js title=".eslintrc.js"
module.exports = {
extends: ['plugin:@typescript-eslint/stylistic-type-checked'],
};
```

</TabItem>
</Tabs>

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

## Other Configurations
Expand DownExpand Up@@ -187,27 +302,78 @@ See [`configs/disable-type-checked.ts`](https://github.com/typescript-eslint/typ
If you use type-aware rules from other plugins, you will need to manually disable these rules or use a premade config they provide to disable them.
:::

<Tabs groupId="eslint-config">
<TabItem value="Flat Config">

```js title="eslint.config.js"
export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
{
languageOptions: {
parserOptions: {
project: true,
tsconfigDirName: import.meta.dirname,
},
},
},
// Added lines start
{
files: ['*.js'],
...tseslint.configs.disableTypeChecked,
},
// Added lines end
);
```

</TabItem>
<TabItem value="Legacy Config">

```js title=".eslintrc.js"
module.exports = {
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended-type-checked',
],
parser: '@typescript-eslint',
parserOptions: {
project: true,
__tsconfigRootDir: __dirname,
},
root: true,
// Added lines start
overrides: [
{
files: ['*.js'],
extends: ['plugin:@typescript-eslint/disable-type-checked'],
},
],
// Added lines end
};
```

</TabItem>
</Tabs>

### `eslint-recommended`

This ruleset is meant to be used after extending `eslint:recommended`.
It disables core ESLint rules that are already checked by the TypeScript compiler.
Additionally, it enables rules that promote using the more modern constructs TypeScript allows for.

<Tabs groupId="eslint-config">
<TabItem value="Flat Config">

```js title="eslint.config.js"
export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.eslintRecommended,
);
```

</TabItem>
<TabItem value="Legacy Config">

```js title=".eslintrc.js"
module.exports = {
extends: [
Expand All@@ -217,6 +383,9 @@ module.exports = {
};
```

</TabItem>
</Tabs>

This config is automatically included if you use any of the recommended configurations.

See [`configs/eslint-recommended.ts`](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/eslint-recommended.ts) for the exact contents of this config.
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp