Skip to content

Commit

Permalink
Refactor: 린트 설정 변경 (#28)
Browse files Browse the repository at this point in the history
* Fix: 백엔드 .eslintrc.js 수정

jest 관련 룰을 설정할때 settings에 jest 버전을 명시해주는 설정이 필요했는데 이 부분이 누락되어서 수정했습니다.

* Chore: yarn workspace 설정

현재 husky + lint-staged 패키지를 이용해 pre-commit hook 단계에서 formatting과 lint를 체크하는 동작이 제대로 동작하지 않는 문제가 있습니다.
직접적인 원인은 아닐 수 있는데 front와 server에서 모두 husky를 통해 pre-commit hook을 트리거하게 되는데 실제 commit은 통합적으로 이루어지니까 pre-commit hook 도 통합적으로 트리거하면 좋겠다는 생각이 들었습니다.
그래서 hook을 트리거 하는 설정은 root 디렉토리에서 가지고 있고 하위 디렉토리에서는 각각의 프로젝트에 맞는 핸들링을 설정해놓는 구조로 설정하면 좋을 것 같은데 이런 구조를 짜보려고 하니 yarn의 workspace 기능을 알게 되었고 적용해보았습니다.

**yarn을 사용할 경우 얻을 수 있는 이점**

1. npm 을 이용하는 경우 스크립트나 패키지를 설치하거나 스크립트를 실행할 때 server/front 디렉토리로 이동 후 명령어를 실행해야 하는 불편함이 있는데, yarn의 workspace를 이용하면 루트 디렉토리 상에서도 명령어 실행이 가능해집니다.

2. server/front에서 모두 사용하는 패키지 같은 경우 루트의 node_modules 에서 통합적으로 관리하게 돼서 중복 설치가 줄어듭니다.

**yarn을 사용할 경우 단점**

1. 모든 팀원들이 yarn을 설치하고 사용해야 합니다.

2. 명령어 실행시 매번 workspace를 지정해주어야 합니다.

* Style: Init code format

그동안 eslint, prettier 설정이 제대로 동작하지 않아서 코드 포맷팅이 되지 않았던 코드의 포맷을 수정했습니다.

* Fix: package.json 저장소 url 수정

fork한 개인 repository로 등록되어 있던 repository 링크를 수정하고 author 삭제

* Chore: settings.json 설정 추가

javascript.format.enable 설정 추가.
  • Loading branch information
changheedev authored Oct 28, 2020
1 parent dbc7ee0 commit c95be57
Show file tree
Hide file tree
Showing 15 changed files with 9,472 additions and 11,378 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,5 @@ dist

# TernJS port file
.tern-port

package-lock.json
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist
scripts
yarn.lock
5 changes: 3 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"eslint.validate": ["javascript"]
}
"eslint.validate": ["javascript"],
"javascript.format.enable": false,
}
23 changes: 13 additions & 10 deletions front/.babelrc
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
{
"presets": [
["@babel/preset-env",{
"targets" : ">0.25%, not dead",
"useBuiltIns":"usage",
"corejs": "3",
"modules": "auto"
}],
"@babel/preset-react"
]
}
"presets": [
[
"@babel/preset-env",
{
"targets": ">0.25%, not dead",
"useBuiltIns": "usage",
"corejs": "3",
"modules": "auto"
}
],
"@babel/preset-react"
]
}
6 changes: 5 additions & 1 deletion front/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ module.exports = {
es2021: true,
node: true,
},
extends: ['plugin:react/recommended', 'airbnb', 'plugin:prettier/recommended'],
extends: [
'plugin:react/recommended',
'airbnb',
'plugin:prettier/recommended',
],
parserOptions: {
ecmaFeatures: {
jsx: true,
Expand Down
17 changes: 6 additions & 11 deletions front/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,19 @@
"description": "",
"main": "index.js",
"scripts": {
"precommit": "lint-staged",
"test": "echo \"Error: no test specified\" && exit 1",
"start": "webpack-dev-server --open",
"build" : "webpack"
},
"husky": {
"hooks": {
"pre-commit": "npx lint-staged"
}
"build": "webpack"
},
"lint-staged": {
"*.js": [
"*.{json,md,html}": [
"prettier --write",
"eslint --fix",
"git add"
],
"*.md": [
"*.{js,jsx}": [
"prettier --write",
"eslint --fix",
"git add"
]
},
Expand All @@ -44,8 +40,7 @@
"eslint-plugin-react-hooks": "^4.2.0",
"html-loader": "^1.3.2",
"html-webpack-plugin": "^4.5.0",
"husky": "3.1.0",
"lint-staged": "^9.5.0",
"lint-staged": "^10.5.0",
"prettier": "^2.1.2",
"webpack": "^4.44.2",
"webpack-cli": "^3.3.12",
Expand Down
12 changes: 5 additions & 7 deletions front/public/index.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<!DOCTYPE html>

<html>
<head></head>
<body>
<div id ='root'>

</div>
</body>
</html>
<head></head>
<body>
<div id="root"></div>
</body>
</html>
9 changes: 5 additions & 4 deletions front/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path')
const path = require('path');

module.exports = {
mode: 'development',
entry: './src/index.js',
Expand Down Expand Up @@ -43,9 +44,9 @@ module.exports = {
minify:
process.env.NODE_ENV === 'production'
? {
collapseWhitespace: true,
removeComments: true,
}
collapseWhitespace: true,
removeComments: true,
}
: false,
}),
],
Expand Down
5 changes: 5 additions & 0 deletions husky.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
hooks: {
'pre-commit': 'yarn precommit',
},
};
26 changes: 26 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "issue-tracker-25",
"version": "1.0.0",
"private": true,
"main": "index.js",
"repository": "https://github.com/boostcamp-2020/IssueTracker-25.git",
"license": "MIT",
"workspaces": [
"front",
"server"
],
"scripts": {
"test": "run-s test:server test:front",
"test:server": "yarn workspace server test",
"test:front": "yarn workspace front test",
"precommit:server": "yarn workspace server precommit",
"precommit:front": "yarn workspace front precommit",
"precommit": "run-p precommit:server precommit:front",
"format": "prettier --write ."
},
"devDependencies": {
"husky": "^4.3.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.1.2"
}
}
5 changes: 5 additions & 0 deletions server/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@ module.exports = {
'jest/prefer-to-have-length': 'warn',
'jest/valid-expect': 'error',
},
settings: {
jest: {
version: 26,
},
},
};
Loading

0 comments on commit c95be57

Please sign in to comment.