? How would you like to use ESLint? To check syntax only To check syntax and find problems ❯ To check syntax, find problems, and enforce code style
? What type of modules does your project use? JavaScript modules (import/export) CommonJS (require/exports) ❯ None of these
? Which framework does your project use? React Vue.js ❯ None of these
? Does your project use TypeScript? (y/N) y
? Where does your code run? (Press <space> to select, <a> to toggle all, <i> to invert selection) ❯◯ Browser ◉ Node
? How would you like to define a style for your project? ❯ Use a popular style guide Answer questions about your style Inspect your JavaScript file(s)
? Which style guide do you want to follow? ❯ Airbnb: https://github.com/airbnb/javascript Standard: https://github.com/standard/standard Google: https://github.com/google/eslint-config-google
? What format do you want your config file to be in? JavaScript YAML ❯ JSON
@typescript-eslint/eslint-plugin@latest eslint-config-airbnb-base@latest eslint@^5.16.0 || ^6.8.0 eslint-plugin-import@^2.20.1 @typescript-eslint/parser@latest ? Would you like to install them now with npm? (Y/n) Y
$ npx eslint 'src/**/*.ts'# 단순히 문법 검사만 함 $ npx eslint 'src/**/*.{ts,tsx}'# tsx 파일도 검사함 $ npx eslint 'src/**/*.ts' --fix # 고칠수 있는 부분은 고치고 고칠 수 없는 부분은 출력함
2. Typescript용 airbnb 스타일 설치하기
실제로 eslint 명령어를 수행하면 Type을 import한 부분에 대해서는 사용하지 않았다는 아래와 같은 에러를 출력합니다.
1 2 3
import { SomeType } from'some-package';
const something: SomeType | null = null;
1
error 'SomeType' is defined but never used no-unused-vars
이러한 에러가 발생하는 이유는 .eslintrc.json를 생성할 때 설치된 airbnb 스타일이 Typescript용이 아니기 때문입니다.
따라서 Typescript용 airbnb 스타일을 설치 해야 합니다.