Getting Started
Quickstart
This page is a quick-start for ESLint's new "flat" config format to go from zero to linting with our recommended rules on your TypeScript code as quickly as possible.
- For the same guide but for ESLint's legacy format — see Legacy ESLint Setup.
- For quickstart information on linting with type information — see Typed Linting.
Step 1: Installation
First, install the required packages for ESLint, TypeScript, and our tooling:
- npm
- Yarn
- pnpm
npm install --save-dev eslint @eslint/js @types/eslint__js typescript typescript-eslint
yarn add --dev eslint @eslint/js @types/eslint__js typescript typescript-eslint
pnpm add --save-dev eslint @eslint/js @types/eslint__js typescript typescript-eslint
Step 2: Configuration
Next, create an eslint.config.js
config file in the root of your project, and populate it with the following:
// @ts-check
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
);
This code will enable our recommended configuration for linting.
Step 3: Running ESLint
Open a terminal to the root of your project and run the following command:
- npm
- Yarn
- pnpm
npx eslint .
yarn eslint .
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.'@eslint/js'
/eslint.configs.recommended
turns on eslint's recommended config....tseslint.configs.recommended
turns on our recommended config.
Next Steps
If you're having problems getting this working, please have a look at our Troubleshooting & FAQs.
Additional Configs
We recommend you consider enabling the following two configs:
strict
: a superset ofrecommended
that includes more opinionated rules which may also catch bugs.stylistic
: additional rules that enforce consistent styling without significantly catching bugs or changing logic.
export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
...tseslint.configs.strict,
...tseslint.configs.stylistic,
);
You can read more about these in our shared configurations docs.
Typed Linting
We also provide a plethora of powerful rules that utilize the power of TypeScript's type information. Visit the next page for a typed rules setup guide.
Documentation Resources
- You can read more about configuring ESLint in their documentation on configuration.
- You can read more about the rules provided by ESLint in their documentation on their rules.
- You can read more about the rules provided by typescript-eslint in our rules documentation.