$ npx create-react-app [프로젝트명]
eslint
prettier
stylelint
$ yarn add --dev eslint prettier stylelint
$ npx eslint --init
? How would you like to use ESLint? To check syntax, find problems, and enforce code style
? What type of modules does your project use? JavaScript modules (import/export)
? Which framework does your project use? React
? Does your project use TypeScript? No
? Where does your code run? Browser
? How would you like to define a style for your project? Use a popular style guide
? Which style guide do you want to follow? Airbnb (https://github.com/airbnb/javascript)
? What format do you want your config file to be in? JSON
Checking peerDependencies of eslint-config-airbnb@latest
The config that you've selected requires the following dependencies:
eslint-plugin-react@^7.14.3 eslint-config-airbnb@latest eslint@^5.16.0 || ^6.1.0 eslint-plugin-import@^2.18.2 eslint-plugin-jsx-a11y@^6.2.3 eslint-plugin-react-hooks@^1.7.0
? Would you like to install them now with npm? Yes
babel-eslint
eslint-config-prettier
eslint-plugin-testing-library
$ yarn add --dev babel-eslint eslint-config-prettier eslint-plugin-testing-library
.eslintrc.json
// .eslintrc.json
{
"parser": "babel-eslint",
"env": {
"browser": true,
"es6": true,
"commonjs": true,
"node": true,
"jest": true
},
"extends": [
"airbnb",
"prettier",
"plugin:react/recommended",
"plugin:testing-library/recommended",
"plugin:testing-library/react"
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 2018,
"sourceType": "module"
},
"plugins": ["react", "react-hooks", "jsx-a11y", "import"],
"rules": {
// https://eslint.org/docs/rules/require-jsdoc
"require-jsdoc": [
0,
{
"require": {
"FunctionDeclaration": true,
"MethodDefinition": true,
"ClassDeclaration": true,
"ArrowFunctionExpression": false,
"FunctionExpression": false
}
}
],
// https://eslint.org/docs/rules/valid-jsdoc
"valid-jsdoc": [
1,
{
"requireReturn": false
}
],
"no-unused-vars": 1,
// individual
"react/jsx-filename-extension": 0,
"react/jsx-one-expression-per-line": 0,
// testing-library --- https://github.com/Belco90/eslint-plugin-testing-library
"testing-library/await-async-query": "error",
"testing-library/await-fire-event": "warn",
"testing-library/no-await-sync-query": "error",
"testing-library/no-debug": "warn",
"testing-library/no-dom-import": "warn",
"testing-library/prefer-expect-query-by": "warn",
"testing-library/prefer-explicit-assert": "warn"
}
}
package.json
"scripts": {
// start, build, test, eject ...
"format:es": "eslint src"
}
settings
열기
cmd+shift+p
=> open settings(JSON)
- eslint, stylelint 설정 추가
"prettier-eslintIntegration": true,
"prettier-stylelintIntegration": true,
// settings.json
{
// ...
"prettier-eslintIntegration": true,
"prettier-stylelintIntegration": true
}
.prettierrc.json
// .prettierrc.json
{
"singleQuote": true,
"trailingComma": "all",
"printWidth": 80,
"arrowParens": "avoid",
"tabWidth": 2,
"rules": {
"sort-imports": 2
},
"proseWrap": "preserve",
"react/jsx-wrap-multilines": [
"error",
{
"declaration": false,
"assignment": false
}
]
}
package.json
"scripts": {
// start, build, test, eject ...
"format:pre-write": "prettier --write \"src/**/*\""
}
stylelint-config-airbnb
stylelint-order
stylelint-scss
$ yarn add --dev stylelint-config-airbnb stylelint-order stylelint-scss
.stylelintrc.json
// .stylelintrc.json
{
"extends": ["stylelint-config-airbnb"],
"rules": {
"rule-empty-line-before": "always"
}
}
package.json
"scripts": {
// start, build, test, eject ...
"format:style-fix": "stylelint --fix \"src/**/*\""
}
- jsconfig.json 파일 생성 및 수정
// jsconfig.json
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"*": ["*", "src/*"]
}
}
}
styled-components
$ yarn add styled-components
- example
`
// Create a Title component that'll render an <h1> tag with some styles
const Title = styled.h1`
font-size: 1.5em;
text-align: center;
color: palevioletred;
`;
// Create a Wrapper component that'll render a <section> tag with some styles
const Wrapper = styled.section`
padding: 4em;
background: papayawhip;
`;
// Use Title and Wrapper like any other React component – except they're styled!
render(
<Wrapper>
<Title>
Hello World!
</Title>
</Wrapper>
);
`
- 패키지 설치
stylelint-processor-styled-components
stylelint-config-styled-components
stylelint-config-recommended
$ yarn add --dev stylelint-processor-styled-components stylelint-config-styled-components stylelint-config-recommended
- .stylelintrc 수정
// .stylelintrc.json
{
"processors": ["stylelint-processor-styled-components"],
"extends": [
"stylelint-config-airbnb",
"stylelint-config-recommended",
"stylelint-config-styled-components"
],
"rules": {
"rule-empty-line-before": "always"
}
}