Skip to content

Typescript-eslint

Monorepo for all the tooling which enables ESLint to support TypeScript

@typescript-eslint/parser

Typescript 를 파싱하기 위해 사용. eslint 설정시 파서 항목에 넣어야 한다.

@typescript-eslint/eslint-plugin

Typescript 관련 린팅규칙을 설정하는 플러그인.

Installation

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

.eslintrc에 다음 내용을 추가:

module.exports = {
  root: true,
  parser: '@typescript-eslint/parser',
  plugins: [
    '@typescript-eslint',
  ],
  extends: [
    'eslint:recommended',
    'plugin:@typescript-eslint/recommended',
  ],
  env: {
    browser: true,
  }
};
  • root: true로 설정하지 않으면 파일 시스템의 상위 폴더까지 탐색하기 때문에 설정해준다.
  • parser: 위에서 설치한 parser를 적용한다.
  • plugin: 위에서 설치한 plugin을 적용한다.
  • extends
    • eslint:recommended을 적용하면 ESLint의 내장되어있는 추천 설정을 사용할 수 있다.
    • @typescript-eslint/recommendedeslint:recommended 와 비슷하다. 이걸 적용하면 타입스크립트 전용 규칙을 추가적으로 사용할 수 있다.
  • env: lint 돌릴 환경을 설정. 미리 정의된 전역 변수를 정의해준다.
    • browser: true: 브라우저 환경.

실행:

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

See also

Favorite site