-
Notifications
You must be signed in to change notification settings - Fork 2
๐งฉ Coding convention
์ ๋๊ท edited this page Jul 27, 2023
·
11 revisions
์ฐธ๊ณ :
eslint-config-airbnb
Airbnb JavaScript Style Guide
Integrating Prettier + ESLint + Airbnb Style Guide in VSCode
์ฝ๋ฉ ์ปจ๋ฒค์ , ๊ฐ๋ ์ฑ์ด ์ข๊ณ ์ ์ง๋ณด์๊ฐ ์ฉ์ดํ ์ฝ๋๋ฅผ ์์ฑํ๊ธฐ ์ํ ์ฝ๋ฉ ์คํ์ผ ๊ท์ฝ. ์ฝ๋ฉ ์ปจ๋ฒค์ ์ ์ค์ํ๋ฉด ์ฑ๋ฅ์ ์ํฅ์ ์ฃผ๊ฑฐ๋ ์ค๋ฅ๋ฅผ ๋ฐ์์ํค๋ ์ ์ฌ์ ์ํ ์์๋ฅผ ์ค์ผ ์ ์๋ค.
Airbnb Style Guide - ๋ณธ ํ๋ก์ ํธ ์ฌ์ฉ ์ปจ๋ฒค์
JavaScript Standard Style
Idiomatic JavaScript Style Guide
Google Style Guide
- npm๊ณผ npx๋ฅผ ์ค์นํ๋ค.
- VSCode ์ต์คํ ์ ESLint, Prettier๋ฅผ ์ค์นํ๋ค.
- ESLint์ Prettier ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ํ๋ก์ ํธ์ ์ค์นํ๋ค. ํ๋ก์ ํธ์ ๋ฃจํธ ๋๋ ํ ๋ฆฌ์์ ๋ค์ ๋ช ๋ น์ด๋ฅผ ์คํํ๋ค.
> npm install -D eslint prettier- Airbnb config๋ฅผ ์ค์นํ๋ค. npm 5+๋ฅผ ์ฌ์ฉํ๋ค๋ฉด ๋ค์ ๋ช ๋ น์ด๋ฅผ ํตํด ๋ชจ๋ ํจํค์ง๋ฅผ ์ค์นํ ์ ์๋ค.
> npx install-peerdeps --dev eslint-config-airbnb- eslint-config-prettier์ eslint-plugin-prettier๋ฅผ ์ค์นํ๋ค.
> npm install -D eslint-config-prettier eslint-plugin-prettier- ํ๋ก์ ํธ์ ๋ฃจํธ ๋๋ ํ ๋ฆฌ์
.eslintrc.jsonํ์ผ์ ์์ฑํ๊ณ ๋ค์ ๋ด์ฉ์ ์์ฑํ๋ค.
{
"extends": ["airbnb", "prettier"], //์ด ์ค์ ํ์ผ์ airbnb ์คํ์ผ ๊ฐ์ด๋์ prettier์ ์คํ์ผ ๊ฐ์ด๋๋ฅผ ํ์ฅํ๋ค.
"plugins": ["prettier"], //prettier ํ๋ฌ๊ทธ์ธ์ ์ฌ์ฉํ๋ค.
"rules": {
"prettier/prettier": ["error"], //prettier์์ ๋ฐ์ํ ๋ชจ๋ ์คํ์ผ ๊ฒฝ๊ณ ๋ฅผ ์๋ฌ๋ก ์ทจ๊ธํ๋ค.
"no-unused-vars": "warn", //์ ์ธํ์ผ๋ ์ฌ์ฉ๋์ง ์์ ๋ณ์๊ฐ ์๋ค๋ฉด ๊ฒฝ๊ณ ๋ก ํ์ํ๋ค.
"no-undef": "off" //์ ์ ์๋ ๊ฐ์ ๋ํด ๊ฒฝ๊ณ ๋ฅผ ๋๋ค.
},
"env": {
"browser": true, //๋ธ๋ผ์ฐ์ ํ๊ฒฝ์์ ์๋ํ ์ง ์ฌ๋ถ๋ฅผ ์ค์ ํ๋ค.
"node": true, //Node ํ๊ฒฝ์์ ์๋ํ ์ง ์ฌ๋ถ๋ฅผ ์ค์ ํ๋ค.
"es2021": true //ECMAScript 2021 ํ์ค์ ์ง์ํ ์ง ์ฌ๋ถ๋ฅผ ์ค์ ํ๋ค.
},
"overrides": [
{
"env": {
"node": true //Node ํ๊ฒฝ์์ ์๋ํ ์ง ์ฌ๋ถ๋ฅผ ์ค์ ํ๋ค.
},
"files": [".eslintrc.{js,cjs}"], //์ด ์ค์ ์ด ์ ์ฉ๋๋ ํ์ผ๋ค์ ํจํด์ ๋ช
์ํ๋ค.
"parserOptions": {
"sourceType": "script" //์ค์ ํ์ผ์ ์์ค ํ์
์ 'script'๋ก ๋ช
์ํ๋ค.
}
}
],
"parserOptions": {
"ecmaVersion": "latest", //๋ง์ง๋ง ECMASclima์ ๋ฒ์ ์ ์ฌ์ฉํด ํ์ฑํ๋ค.
"sourceType": "module" //์ ์ฒด ํ๋ก์ ํธ์ ์์ค ํ์
์ 'module'๋ก ๋ช
์ํ๋ค.
}
}- ํ๋ก์ ํธ์ ๋ฃจํธ ๋๋ ํ ๋ฆฌ์
.prettierrcํ์ผ์ ์์ฑํ๊ณ Prettier config file์ ์ฐธ๊ณ ํ์ฌ ์ํ๋ ํฌ๋งทํ ์ต์ ์ ์ค์ ํ๋ค.
{
"arrowParens": "avoid", // ํ์ดํ ํจ์ ๊ดํธ ์ฌ์ฉ ๋ฐฉ์
"bracketSpacing": false, // ๊ฐ์ฒด ๋ฆฌํฐ๋ด์์ ๊ดํธ์ ๊ณต๋ฐฑ ์ฝ์
์ฌ๋ถ
"endOfLine": "auto", // EoF ๋ฐฉ์, OS๋ณ๋ก ์ฒ๋ฆฌ ๋ฐฉ์์ด ๋ค๋ฆ
"htmlWhitespaceSensitivity": "css", // HTML ๊ณต๋ฐฑ ๊ฐ๋ ์ค์
"jsxBracketSameLine": false, // JSX์ ๋ง์ง๋ง `>`๋ฅผ ๋ค์ ์ค๋ก ๋ด๋ฆด์ง ์ฌ๋ถ
"jsxSingleQuote": true, // JSX์ singe ์ฟผํ
์ด์
์ฌ์ฉ ์ฌ๋ถ
"printWidth": 100, // ์ค ๋ฐ๊ฟ ํ ํญ ๊ธธ์ด
"proseWrap": "preserve", // markdown ํ
์คํธ์ ์ค๋ฐ๊ฟ ๋ฐฉ์ (v1.8.2)
"quoteProps": "as-needed", // ๊ฐ์ฒด ์์ฑ์ ์ฟผํ
์ด์
์ ์ฉ ๋ฐฉ์
"semi": true, // ์ธ๋ฏธ์ฝ๋ก ์ฌ์ฉ ์ฌ๋ถ
"singleQuote": true, // single ์ฟผํ
์ด์
์ฌ์ฉ ์ฌ๋ถ
"tabWidth": 2, // ํญ ๋๋น
"trailingComma": "all", // ์ฌ๋ฌ ์ค์ ์ฌ์ฉํ ๋, ํํ ์ฝค๋ง ์ฌ์ฉ ๋ฐฉ์
"useTabs": false, // ํญ ์ฌ์ฉ ์ฌ๋ถ
"rangeStart": 0, // ํฌ๋งทํ
์ ๋ถ๋ถ ์ ์ฉํ ํ์ผ์ ์์ ๋ผ์ธ ์ง์
"requirePragma": false, // ํ์ผ ์๋จ์ ๋ฏธ๋ฆฌ ์ ์๋ ์ฃผ์์ ์์ฑํ๊ณ Pragma๋ก ํฌ๋งทํ
์ฌ์ฉ ์ฌ๋ถ ์ง์ (v1.8.0)
"insertPragma": false, // ๋ฏธ๋ฆฌ ์ ์๋ @format marker์ ์ฌ์ฉ ์ฌ๋ถ (v1.8.0)
"overrides": [
{
"files": "*.json",
"options": {
"printWidth": 200
}
}
], // ํน์ ํ์ผ๋ณ๋ก ์ต์
์ ๋ค๋ฅด๊ฒ ์ง์ ํจ, ESLint ๋ฐฉ์ ์ฌ์ฉ
}
- VSCode์ User Setting ํ์ผ(setting.json)์
"editor.formatOnSave": true๋ฅผ ์ฝ์ ํ๋ค.