//typescript ์ฌ์ฉ ์
npx create-react-app [ํ๋ก์ ํธ๋ช
] --template=typescript
//Typescript๋ฅผ ๋ฏธ์ฌ์ฉ
npx create-react-app [ํ๋ก์ ํธ ๋ช
]
npm install --save-dev eslint @typescript-eslint/parser@^5.0.0 @typescript-eslint/eslint-plugin@^5.0.0
์ต์ ๋ฒ์ ์ผ๋ก ๋ค์ด์ ๋ฐ๊ฒ ๋๋ฉด ์์กด์ฑ ์ถฉ๋์ด ์ผ์ด๋ ์๋ฌ๊ฐ ๋ฐ์ํ๋ค.
npm info "eslint-config-airbnb@latest" peerDependencies
๋ฅผ ์
๋ ฅํ๋ฉด ์ค์นํด์ผํ๋ ๋ฆฌ์คํธ๋ค์ด ๋์ต๋๋ค.
๊ฐ์ ์ค์น๋ฅผ ํด์ฃผ๋๋ก ํฉ๋๋ค.
๋ง์ฝ npm์ด v5์ด์ ์ด๋ฉด ๋ค์ ์ปค๋งจํธ๋ฅผ ์
๋ ฅํด์ค๋๋ค.
npx install-peerdeps --dev eslint-config-airbnb
์๋์ผ๋ก ํ๋ฌ๊ทธ์ธ ๋ฐ ์ค์ ๋ค์ ์ค์นํด์ค๋๋ค.
npx eslint --init
์ ๋ช
๋ น์ด๋ฅผ ์ฌ์ฉํ๋ฉด ๊ฐํธํ๊ฒ eslintrc.json
ํ์ผ์ ์์ฑํ ์ ์์ต๋๋ค.
package.json ํ์ผ์ script ๋ด ์์ ์ถ๊ฐ
"lint": "eslint \"./src/**/*.{ts,tsx,js,jsx}\"",
"lint:fix": "eslint --fix \"./src/**/*.{ts,tsx,js,jsx}\""
์ค์ ํ lint ์คํ ์ eslint ๋ฌธ๋ฒ์ ์ด๊ธ๋ ์ฝ๋๋ฅผ ์๋ ค์ค๋ค.
npm i --save-dev eslint-config-airbnb-typescript
Typescript๋ฅผ ์ฌ์ฉํด์ผํ๋ ๊ฒฝ์ฐ eslint-config-airbnb-typescript ๋ฅผ ์ค์นํ ํ .eslintrc.js์ extends ๋ด airbnb, airbnb-typescript๋ฅผ ์ถ๊ฐํ๋ค.
{
"env": {
"browser": true,
"es2021": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"plugin:@typescript-eslint/recommended",
"airbnb",
"airbnb/hooks",
"airbnb-typescript"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": "latest",
"sourceType": "module",
"project": "./tsconfig.json"
},
"plugins": ["react", "@typescript-eslint"],
"rules": {}
}
npm run lint ๋ช ๋ น์ด๋ฅผ ์ ๋ ฅํด๋ณด๋ฉด airbnb ๊ฐ ์ ์ฉ๋๋ค.
npm install --save-dev prettier eslint-config-prettier eslint-plugin-prettier
prettier ํ์ผ์ ์ ํ ํด์ค๋๋ค.
{
"singleQuote": true,
"semi": true,
"useTabs": false,
"tabWidth": 2,
"trailingComma": "all",
"printWidth": 120
}
.eslintrc.jsonํ์ผ๋ ์์ ํด์ค๋๋ค.
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"plugin:@typescript-eslint/recommended",
"airbnb",
"airbnb/hooks",
"airbnb-typescript",
"prettier"
]
package.jsonํ์ผ์ scripts์ prettier๋ฅผ ์ถ๊ฐํฉ๋๋ค.
"scripts": {
//...
"prettier": "prettier --write --config ./.prettierrc './src/**/*.{ts,tsx}'",
//...
}