프로젝트 생성
yarn create react-app my-app --template typescript
eslint, prettier 설치 (airbnb-eslint, trivago-prettier 플러그인)
yarn add -D eslint prettier eslint-config-airbnb eslint-config-airbnb-typescript eslint-config-prettier eslint-plugin-react @typescript-eslint/eslint-plugin @typescript-eslint/parser @trivago/prettier-plugin-sort-imports
.eslintrc.js 설정
module.exports = {
env: {
browser: true,
es2021: true,
},
extends: [
'eslint:recommended',
'plugin:react/recommended',
'plugin:@typescript-eslint/recommended',
'airbnb',
'airbnb-typescript',
'prettier',
],
overrides: [],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
project: ['./tsconfig.json'],
},
plugins: ['react', '@typescript-eslint'],
rules: {},
};
.eslintignore 설정
.eslintrc.js
.prettierrc.js 설정
module.exports = {
singleQuote: true,
semi: true,
tabWidth: 2,
trailingComma: 'all',
quoteProps: 'consistent',
printWidth: 100,
arrowParens: 'always',
importOrderParserPlugins: ['typescript', 'jsx'],
importOrder: ['^(react/(.*)$)|^(react$)|^(next/(.*)$)|^(next$)', '<THIRD_PARTY_MODULES>', '^(@/(.*)$)', '^~'],
importOrderSeparation: true,
importOrderSortSpecifiers: true,
plugins: ['@trivago/prettier-plugin-sort-imports'],
};
husky 설치
yarn add -D husky
npx husky install
husky 설정
// package.json
"scripts": {
...
"prepare": "husky install",
..
}
lint-staged 설치
yarn add -D lint-staged
lint-staged 설정
npx husky add .husky/pre-commit 'npx lint-staged'
//package.json
"lint-staged": {
"src/**/*.{js,jsx,ts,tsx}": [
"eslint --cache --fix",
"prettier --cache --write"
]
}
// .eslintcahe => .gitignore에 넣어주기
commitlint 설치
yarn add -D @commitlint/config-conventional @commitlint/cli
commitlint 설정
//commitlint.config.js
module.exports = { extends: ['@commitlint/config-conventional'] };
.eslintignore 설정
//.eslintignore
commitlint.config.js
.eslintrc.js
npx husky add .husky/commit-msg 'npx --no-install commitlint --edit "$1"’
commitlint 커스텀
module.exports = {
extends: ["@commitlint/config-conventional"],
rules: {
"type-enum": [
2,
"always",
[
"Feat",
"Fix",
"Style",
"Design",
"Refactor",
"Docs",
"Chore",
"Rename",
"Remove",
],
],
"type-case": [2, "always", "pascal-case"],
},
};