Skip to content
Search

Typescript-eslint

lastmod 2022-04-11created 2022-04-078 edits

Monorepo for all the tooling which enables ESLint to support TypeScript

@typescript-eslint/parser

Used to parse Typescript. Must be put in the parser entry when configuring eslint.

@typescript-eslint/eslint-plugin

Plugin that configures Typescript-related linting rules.

Installation

yarn add -D eslint typescript @typescript-eslint/parser @typescript-eslint/eslint-plugin

Add the following to .eslintrc:

module.exports = {
  root: true,
  parser: '@typescript-eslint/parser',
  plugins: [
    '@typescript-eslint',
  ],
  extends: [
    'eslint:recommended',
    'plugin:@typescript-eslint/recommended',
  ],
  env: {
    browser: true,
  }
};
  • root: Set this, because if it is not set to true, ESLint searches up into parent folders of the file system.
  • parser: Applies the parser installed above.
  • plugin: Applies the plugin installed above.
  • extends
    • Applying eslint:recommended lets you use ESLint's built-in recommended settings.
    • @typescript-eslint/recommended is similar to eslint:recommended. Applying it gives you additional TypeScript-specific rules.
  • env: Sets the environment to lint in. Defines predefined global variables.
    • browser: true: Browser environment.

Run:

yarn eslint . --ext .js,.jsx,.ts,.tsx

See also

Favorite site

author Zer0 sitemap