๐ฎESLint + Prettier์์ํ๊ธฐ
// npmํ๊ฒฝ์ด ์กด์ฌํ๋ cra๊ฐ์ ๊ฒฝ์ฐ์๋ ์ฌ์ฉํ ํ์ ์์
$ npm init -y
// eslint ์ค์น
$ npm install eslint prettier --save-dev
// or
$ yarn add -D eslint prettier
// eslint ์์ ์ค์
$ npx eslint --init
//or
$ yarn eslint --init
eslint --init์ ํด์ฃผ๋ฉด ์ง๋ฌธ์ด ์ฌ๋ฌ๊ฐ์ง๊ฐ ๋์ค๋๋ฐ
์ธํ ํ๋ ค๋ ํ๊ฒฝ์ ๋ง์ถฐ์ ๋ต๋ณํ๋ฉด ๊ทธ์ ๋ง๊ฒ ์ธํ ํ๊ฒ ๋๋ค.
$ yarn eslint --init
yarn run v1.22.10
$ /home/identity/hanghae99/redux-toolkit-tutorial/node_modules/.bin/eslint --init
You can also run this command directly using 'npm init @eslint/config'.
Need to install the following packages:
@eslint/create-config
Ok to proceed? (y) y
โ How would you like to use ESLint? · problems
โ What type of modules does your project use? · esm
โ Which framework does your project use? · react
โ Does your project use TypeScript? · No / Yes
โ Where does your code run? · browser
โ What format do you want your config file to be in? · JavaScript
Local ESLint installation not found.
The config that you've selected requires the following dependencies:
eslint-plugin-react@latest eslint@latest
โ Would you like to install them now with npm? · No / Yes
Installing eslint-plugin-react@latest, eslint@latest
vscode extension
๋งํฌ : https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint
์ถ์ฒ : https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode
ESLint config ์ต์ ์ดํด๋ณด๊ธฐ
ESLint ์์ธ ์ค์ ๊ฐ์ด๋
Engineering Blog by Dale Seo
www.daleseo.com
airbnb ์ฝ๋ ์คํ์ผ ์ ์ฉํ๊ธฐ
airbnb ์ฝ๋ ์คํ์ผ์ ์ ์ฉํ๋ ค๋ฉด airbnb์์ ์ฌ์ฉํ๋ eslint-plugin์ด ์ค์น๋์ด ์์ด์ผ ํฉ๋๋ค.
๋ค์ ๋ช ๋ น์ด๋ก ํ์ํ ํจํค์ง์ ๋ฒ์ ๋ค์ ํ์ธํ ์ ์์ต๋๋ค.
$ npm info "eslint-config-airbnb@latest" peerDependencies
{
eslint: '^7.32.0 || ^8.2.0',
'eslint-plugin-import': '^2.25.3',
'eslint-plugin-jsx-a11y': '^6.5.1',
'eslint-plugin-react': '^7.28.0',
'eslint-plugin-react-hooks': '^4.3.0'
}
์ค์น๋์ด ์์ง ์๋ค๋ฉด ๋ค์ ๋ช ๋ น์ด๋ก ํ์ํ ํจํค์ง๋ค์ ํ๋ฒ์ ์ค์นํ ์ ์์ต๋๋ค.
$ npx install-peerdeps --dev eslint-config-airbnb
eslint-config-airbnb์ eslint-config-airbnb-base์ ์ฐจ์ด์
eslint-config-airbnb์ ๊ท์น์๋ react ๊ท์น์ด ์์ผ๋ฉฐ, eslint-config-airbnb-base๊ท์น์๋ react ๊ท์น์ด ์กด์ฌํ์ง ์๋ค๋ ์ฐจ์ด์ ์ด ์์ต๋๋ค. react ๊ท์น์ด ํ์์๋ค๋ฉด eslint-config-airbnb-base๋ฅผ ์ด์ฉํ๋ฉด ๋ฉ๋๋ค.
๐ESLint document
์ธํฐ๋ท์ ๋์๋ค๋๊ณ ๋ง์ด๋ค ์ฐ๋ eslint ํ ํ๋ฆฟ์ ์ธ๋ ์ฐ๋๋ผ๋ ๋ญ๊ฐ ๋ญ์ง๋ ์๊ณ ์จ์ผํ๋๋ฐ
eslint ๊ท์น๋ค์ด ๋๋ฌด ํํธํ๋์ด ์์ด์ ์ฐพ๊ธฐ๊ฐ ๋๋ฌด ํ๋ญ๋๋ค.
๊ฒ๋ค๊ฐ ์๋ ์ ๋ง๋ค์ด์ง ํ ํ๋ฆฟ์ด๋ผ๋ฉด deprecated rule์ด ์กด์ฌํ ์๋ ์์ต๋๋ค.
plugin๋ ๋๋ฌด ๋ง๊ณ ๊ท์น๋ค๋ ๋๋ฌด ๋ง์์ ๋ ํผ๋ฐ์ค๋ฅผ ํ๋ฒ ์ ๋ฆฌํด๋ณด์์ต๋๋ค.
๊ท์น๋ค์ readmeํ์ผ์ด๋ ๊ณต์๋ฌธ์์ ๋์์์ผ๋ plugin์ ๋ง๊ฒ ๊ท์น์ ์ฐพ์๋ณด๋ ๊ฒ ์ข์ต๋๋ค.
ESLint ๊ณต์๋ฌธ์
eslint rule์ ๋ํด์ ๋์์๋ eslint ๊ณต์๋ฌธ์
Rules - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
eslint.org
airbnb
๊ฐ์ฅ ์ ๋ช ํ ๋ฆฐํธ ์ค์ ์ธ airbnb.
GitHub - airbnb/javascript: JavaScript Style Guide
JavaScript Style Guide. Contribute to airbnb/javascript development by creating an account on GitHub.
github.com
eslint-config-airbnb
Airbnb's ESLint config, following our styleguide. Latest version: 19.0.4, last published: a year ago. Start using eslint-config-airbnb in your project by running `npm i eslint-config-airbnb`. There are 4419 other projects in the npm registry using eslint-c
www.npmjs.com
eslint-plugin-import
GitHub - import-js/eslint-plugin-import: ESLint plugin with rules that help validate proper imports.
ESLint plugin with rules that help validate proper imports. - GitHub - import-js/eslint-plugin-import: ESLint plugin with rules that help validate proper imports.
github.com
eslint-plugin-react
GitHub - jsx-eslint/eslint-plugin-react: React-specific linting rules for ESLint
React-specific linting rules for ESLint. Contribute to jsx-eslint/eslint-plugin-react development by creating an account on GitHub.
github.com
eslint-plugin-jsx-a11y
GitHub - jsx-eslint/eslint-plugin-jsx-a11y: Static AST checker for a11y rules on JSX elements.
Static AST checker for a11y rules on JSX elements. - GitHub - jsx-eslint/eslint-plugin-jsx-a11y: Static AST checker for a11y rules on JSX elements.
github.com
๐Prettier document
prettier option ๋ฌธ์
Prettier · Opinionated Code Formatter
Opinionated Code Formatter
prettier.io
.prettierrc์ ์ ๋ ฅํ๊ฒ ๋ ์ต์ ๋ค์ ๋ํ ์ ๋ณด๋ prettier ๊ณต์๋ฌธ์์ ์ ๋ถ ๋์ ์์ต๋๋ค.
eslint-plugin-prettier
Prettier์ ๊ท์น์ eslint์ ์ ์ฉ์ํฌ ์ ์๊ฒ๋ ํด์ฃผ๋ plugin์ ๋๋ค.
GitHub - prettier/eslint-plugin-prettier: ESLint plugin for Prettier formatting
ESLint plugin for Prettier formatting. Contribute to prettier/eslint-plugin-prettier development by creating an account on GitHub.
github.com
eslint-config-prettier
prettier ์ ์ค์ ์ค eslint ์ ์ค์ ๊ณผ ์ถฉ๋์ด ๋๋ ์ค์ ๋ค์ ๋นํ์ฑํ ํด์ฃผ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ๋๋ค.
GitHub - prettier/eslint-config-prettier: Turns off all rules that are unnecessary or might conflict with Prettier.
Turns off all rules that are unnecessary or might conflict with Prettier. - GitHub - prettier/eslint-config-prettier: Turns off all rules that are unnecessary or might conflict with Prettier.
github.com
โถReference
eslint --init ์ผ๋ก ์ฝ๊ฒ eslint ์ธํ ํ๊ธฐ
์ด์ ์ react eslint ๊ด๋ จํด์ ์ฌ๋ฌ ๊ธ์ ์์ฑํ๋ค (๋ค ์์ฒญ๋ ์ฝ์ง์ด์๋ค…) terminal1npx eslint --init ์ ๋ช ๋ น์ผ๋ก ํ ๋ฒ์ ํด๊ฒฐ ๋ฐฉํฅํค๋ก ์ ํ ์ ํ ๋์ด๊ฐ๋ฉด, ์์์ ํ๊ฒฝ์ ์ธํ ํด์ค๋ค CRA์ eslint –in
chinsun9.github.io
๋ฆฌ์กํธ ํ๋ก์ ํธ์ ESLint ์ Prettier ๋ผ์น๊ธฐ
ESLint ์ Prettier ๋ฅผ ๋ฆฌ์กํธ ํ๋ก์ ํธ์์ ์ ๋๋ก ์ ์ฉํ์ฌ ์ฝ๋๋ฅผ ๊น-๋-ํ๊ฒ ๊ด๋ฆฌํด๋ณด๋ ๋ฐฉ๋ฒ์ ๋ฐฐ์๋ด ์๋ค.
velog.io
Eslint & Prettier ์ค์ ๋ฐฉ๋ฒ (feat. VS Code)
settings.json ์ค์ ๋ฐฉ๋ฒ์ด ๋ณ๊ฒฝ ๋์ด์ ์์ ํ์ eslint-config-prettier ๋ eslint๊ฐ Prettier๊ณผ์ ์ถฉ๋ ๋๋ ๋ถ๋ถ์ ๋นํ์ฑํํด์ฃผ๋ config์ด๋ค. .eslintrc.json eslint-plugin-prettier๋ Prett
velog.io
'javascript' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Javascript] ๋ชจ๋ ๊ธฐ๋ฅ์ผ๋ก ์ดํด๋ณด๋ ์๋ฐ์คํฌ๋ฆฝํธ (0) | 2022.12.19 |
---|---|
์๋ฐ์คํฌ๋ฆฝํธ ๊ฐ์ฒด ๋ถ์๊ธฐ (0) | 2022.12.04 |
[Javascript] ์ด๋ฒ์์ผ๋ง๋ก regex๋ฅผ ์จ๋ณด์ (0) | 2022.12.03 |
[Javascript] Array filter ๋ง๊น๋๊ฒ ์จ๋ณด๊ธฐ (0) | 2022.11.13 |