📌 ESLint, Prettier란?
ESLint는 vscode에서 코드를 작성하다가 문법적으로 오류가 발생한 곳을 사전에 미리 알려주는 도구이며, prettier는 ESLint가 알려준 오류를 즉각 고쳐주는 도구이다.
🔨 Prettier 사용 방법
프리티어 패키지를 설치한다.
프리티어 구성 파일
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| module.exports = { arrowParens: "always", htmlWhitespaceSensitivity: "css", bracketSameLine: false, bracketSpacing: true, printWidth: 80, proseWrap: "preserve", quoteProps: "as-needed", semi: true, singleQuote: true, tabWidth: 2, trailingComma: "es5", useTabs: false, };
|
프리티어 제외 파일
🔨 ESLint 사용방법
ESLint 설치 및 초기화
ESLint 구성 파일
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| module.exports = { extends: [ "eslint:recommended", "plugin:react/recommended", "plugin:react/jsx-runtime", "plugin:@typescript-eslint/recommended", ], settings: { react: { version: require("react/package.json").version }, }, rules: { "@typescript-eslint/no-var-requires": "off", }, };
|
ESLint 플러그인
1
| npm i -D eslint-plugin-react-hooks eslint-plugin-jsx-a11y eslint-plugin-prettier eslint-config-prettier
|
React 개발에 필요한 패키지와 프리티어 구성 통합을 위한 패키지를 설치한다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| module.exports = { extends: [ "eslint:recommended", "plugin:react/recommended", "plugin:react/jsx-runtime", "plugin:@typescript-eslint/recommended", "plugin:jsx-a11y/recommended", "plugin:prettier/recommended", "prettier", ], plugins: ["react", "@typescript-eslint", "jsx-a11y"], };
|
역시 ESLint 제외파일도 지정할 수 있다.
📌 저장할 때, prettier 자동으로 조절해주기
vscode에서 Code - Preferences - settings - default formatter - prettier로 설정