ESLint
코드 스타일 통일성
$ eslint --init
Prettier
ESLint와 함께 자주 사용되며 작성된 코드를 들여쓰기나 이쁘게 정렬해주는 포맷터
마켓플레이스나 npm 또는 yarn으로 설치가능
https://www.npmjs.com/package/prettier
prettier
Prettier is an opinionated code formatter
www.npmjs.com
둘이 동시에 쓰는 경우 충돌이 날 경우
$ npm i --save-dev eslint-config-prettier eslint-plugin-prettier
.eslintrc.js
설치 완료시 프로젝트 Root에 파일 .eslintrc.js 생성
규칙을 정의하고 개발자가 어긋난 경우 에러 메시지를 띄워줌
자주 사용하는 룰(귝칙)과 설명
.eslintrc.js 파일 내 rules 객체 내 필요한 규칙을 정의
rules: {
quotes: ['error', 'single'], // 싱글 쿼터 사용
'@typescript-eslint/quotes': ['error', 'single'], // 더블 쿼터 사용
'no-unused-vars': 'off', // 사용안한 변수 경고 중복
'spaced-comment': 'off', // 주석을 뒤에 쓰지 말라는 경고
'@typescript-eslint/no-unused-vars': 'warn', // 사용안한 변수는 경고
'jsx-a11y/control-has-associated-label': 'off', // 상호작용하는 엘리먼트에 label을 넣는다
'react/no-array-index-key': 'off', // key값으로 index를 사용할수 있다.
'comma-dangle': 'off', // 마지막에 , 을 넣어주지 않는다.
'arrow-body-style': 'off', // 화살표 함수 안에 return을 사용 할 수 있다.
'react/no-unescaped-entities': 'off', // 문자열 내에서 " ' > } 허용
'react/prop-types': 'off', // proptypes를 사용하지 않는다.
'object-curly-newline': 'off', // { 다음 줄 바꿈을 강제로 사용하지 않는다.
'react/jsx-one-expression-per-line': 'off', // 한라인에 여러개의 JSX를 사용 할 수 있다.
'implicit-arrow-linebreak': 'off', // 화살표 함수 다음에 줄 바꿈을 사용할 수 있다.
'no-shadow': 'off', // 파일 내에서 중복 이름을 사용 할 수 있다.
'operator-linebreak': 'off', // 연산자 다음 줄 바꿈을 사용 할 수 있다.
'react/react-in-jsx-scope': 'off', // jsx를 사용하여도 React를 꼭 import 하지 않아도 된다.
'react/jsx-props-no-spreading': 'off', // props를 스프래드 할 수 있다.
'jsx-a11y/anchor-is-valid': 'off', // next js에서는 a에 href없이 사용
'global-require': 'off', // 함수 내에서 require 사용가능
'no-use-before-define': 'off', // 선언전에 사용하지 말라,
'import/prefer-default-export': 'off', // export default 권장
'no-param-reassign': 'off', // param assign 하지 않기
'jsx-a11y/label-has-associated-control': 'off',
'no-invalid-css': 'off',
'no-confusing-arrow': 'off',
'react/jsx-curly-newline': 'off',
indent: 'off',
'react/jsx-filename-extension': [
1,
{ extensions: ['.js', '.jsx', '.tsx'] }, // jsx사용가능한 확장자 설정
],
'import/extensions': [
'error',
'ignorePackages',
{
js: 'never',
jsx: 'never',
ts: 'never',
tsx: 'never',
}, // import 시 확장자명은 사용하지 않는다.
],
},
그 밖에 룰 또는 규칙은 공식 문서 참조
https://eslint.org/docs/rules/
List of available rules
✓no-unreachabledisallow unreachable code after `return`, `throw`, `continue`, and `break` statements
eslint.org
'개발' 카테고리의 다른 글
[AWS] 계정 해지 탈퇴 (0) | 2022.01.18 |
---|---|
[AWS] 프리티어 폭탄 요금 청구 해결 (0) | 2022.01.18 |
[설정] 리액트 + 타입스크립트 프로젝트 생성 (0) | 2022.01.15 |
[이슈] You are running `create-react-app` 4.0.3, which is behind the latest release (5.0.0). (0) | 2022.01.12 |
[이슈] Create React App requires Node 14 or higher. (0) | 2022.01.11 |