
협업 프로젝트시에 코딩룰이 적용된 소스는 인체에 유익 하다는 전제 하에 강제하는 방법을 알아 본다.
확실히 쌩 리액트 프로젝트를 구성을 위해서는 webpack을 만저볼수 밖에 없는데 이점이 상당히 도움이 된다는 것을 몸소 체험한다.
CAR-ESLint & prettier 세팅 할때는 구성 요소중 30%정도는 남들이 하니깐 가이드에 나와 있으니깐 대충 넘어 갔던것들이 눈에 들어 온다.
MIT license를 가진 code formatter 모듈입니다. Code format이란 줄 바꿈, 줄간격, 괄호의 위치 등 여러 가지 Style을 의미하며, Prettier는 이런 code style을 자동적으로 정리해 줍니다.
javascript 정적 분석 도구
ESLint란? ECMAScript Lint의 줄임말로, javascript의 표준을 다루는 협회가 바로 ECMA입니다. Lint는 유닉스 시절에 정적코드 분석 프로그램인 'Linter"에서 따온 이름입니다.
yarn add -D prettier eslint-plugin-prettier eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-jsx-a11y eslint-config-prettier
prettier : auto code formatter module
eslint-plugin-prettier : eslint와 prettier간 충돌방지 플러그인
eslint-plugin-react : for react 구문
eslint-plugin-react-hooks : for react hooks 구문
eslint-plugin-jsx-a11y : for jsx(xml) 정적 분석
eslint-config-prettier : prettier 설정
{
"endOfLine": "auto",
"semi": true,
"singleQuote": false,
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"arrowParens": "avoid",
"bracketSpacing": true,
"htmlWhitespaceSensitivity": "css",
"jsxBracketSameLine": false,
"jsxSingleQuote": false,
"proseWrap": "preserve",
"quoteProps": "as-needed",
"trailingComma": "none",
"vueIndentScriptAndStyle": false,
"filepath": "",
"requirePragma": false,
"insertPragma": false,
"overrides": [
{
"files": "*.json",
"options": { "printWidth": 80, "trailingComma": "none" }
},
{
"files": "*.prettierrc",
"options": { "printWidth": 80, "trailingComma": "none" }
}
]
}
아래 사이트를 통해 룰 설정을 미리 체험 할 수 있다.
https://prettier.io/playground/
// .eslintrc.json
...
{
...
"extends": [
+ "prettier",
"eslint:recommended",
"plugin:react/recommended",
+ "plugin:jsx-a11y/recommended",
+ "plugin:prettier/recommended",
+ "plugin:react-hooks/recommended"
],
...
}
yarn dev
function App() {
const a = 10;
asdfasdfsafas;
...

[eslint]
src\App.js
Line 6:9: 'a' is assigned a value but never used no-unused-vars
Line 7:3: 'asdfasdfsafas' is not defined no-undef
Search for the keywords to learn more about each error.
ERROR in [eslint]
src\App.js
Line 6:9: 'a' is assigned a value but never used no-unused-vars
Line 7:3: 'asdfasdfsafas' is not defined no-undef
Search for the keywords to learn more about each error.
webpack compiled with 1 error



"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
shift + alt + f를 누르면 아래와 같이 자동으로 잡아 준다.
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
https://bitbucket.org/code7004/react-webpack/src/62904498b9b6b8132100d75f8c382a64df0abe65/