๐ Airbnb JavaScript Style Guide for Practice โ
์์ด๋น์ค๋น ์๋ฐ์คํฌ๋ฆฝํธ ์คํ์ผ ๊ฐ์ด๋๋ฅผ ๊ธฐ๋ฐ์ผ๋ก, ๋์ ์ดํด์ ํ์ต ๋ด์ฉ ์ ๋ฆฌํ๊ธฐ
๐ JavaScript Style Guide
๐งฉ ESLint
- ESLint
- prefer-const
- no-const-assign
- no-new-object
- object-shorthand
- quote-props
- no-prototype-builtins
- prefer-object-spread
- no-array-constructor
- array-callback-return
- prefer-destructuring
- func-style
- wrap-iife
- no-loop-func
- prefer-rest-params
- default-param-last
- no-new-func
- space-before-function-paren space-before-blocks
- no-param-reassign
- prefer-spread
- function-paren-newline
๐ Reference
โ๏ธ Note on Environment
Airbnb ์คํ์ผ ๊ฐ์ด๋๋ ํ๋์ ์ธ ์๋ฐ์คํฌ๋ฆฝํธ ์คํ ํ๊ฒฝ(ES6+)
์ ์ ์ ๋ก ํ๋ค.
๋ฐ๋ผ์, ์ฝ๋ ์์ ๋ ๊ท์น๋ค์ด ์ต์ ๋ฌธ๋ฒ์ ์ฌ์ฉํ๋ ๊ฒ์ ๊ธฐ๋ณธ ๊ฐ์ ์ผ๋ก ํ๋ค.
- ์ฌ์ฉ์๋ Babel๊ณผ babel-preset-airbnb ํน์ ์ด์ ๋๋ฑํ ์ค์ ์ ์ฌ์ฉํ๋ค๊ณ ๊ฐ์ ํ๋ค.
- ๋ธ๋ผ์ฐ์ ํ๊ฒฝ์์๋ airbnb-browser-shims ๋๋ ์ด์ ์์ํ๋ shims/polyfills์ด ์ ์ฉ๋์ด ์๋ค๊ณ ๊ฐ์ ํ๋ค.
๐ก ์ฆ, ์ด ๊ฐ์ด๋๋ ES6+ + Babel + Polyfill
์กฐํฉ์ด ๊ธฐ๋ณธ ์ ์ ๋ค.
๐ญ ์ Airbnb ์คํ์ผ ๊ฐ์ด๋์ธ๊ฐ?
ํ์ฌ ์งํ ์ค์ธ ์ฝ์ด ์๋ฐ์คํฌ๋ฆฝํธ ๊ฐ์ฌ๋์ ์ถ์ฒ๊ณผ, ์ฐํ ์ฝ์์๋ Airbnb ์ปจ๋ฒค์ ์ ๋ฐ๋ฅธ๋ค๋ ๋ธ๋ก๊ทธ ๊ธ์ ๋ณด์๋ค.
์กฐ๊ธ ๋ ์์นํด๋ณด๋ Google, Idiomatic JS, standard.js ๋ฑ ๋ค์ํ ์ปจ๋ฒค์ ์ด ์์์ง๋ง, Airbnb ๊ฐ์ด๋ ๋ถํฐ ์ ๋ ํด๋ณด๋ ค ํ๋ค. ์๋ฌธ ํด์๋ณธ์ ์ด๋ฏธ ์กด์ฌํ์ง๋ง, ์ ์ด๋ฐ ๊ท์น์ด ํ์ํ๊ฐ์ ์ด์ ์ ๋๊ณ ๊ณต๋ถํด๋ณด์!
์ ๋ต์ด๋ผ๊ธฐ๋ณด๋ค, ์ข์ ๊ธฐ์ค์ ์ผ๋ก ์ผ๊ธฐ ์ํ ๊ฐ์ด๋์ด๋ ์์ผ๋ก ๋ค์ํ ์ปจ๋ฒค์ ์ ์ฝ์ด๋ณด๋ฉด์ ๋ฐ์ ์ํค๊ณ ์ ํ๋ค! ๐
๐๏ธ Structure โ
์ฃผ์ | ์์ฝ |
---|---|
01. Types (ํ) | ์์ํยท์ฐธ์กฐํ |
02. References (์ฐธ์กฐ) | var/let/const |
03. Object (๊ฐ์ฒด) | ๋ฆฌํฐ๋ด ๋ฌธ๋ฒ, ๋จ์ถ ๊ตฌ๋ฌธ, ์์ ํ ์ ๊ทผ๊ณผ ๋ถ๋ณ์ฑ ์ ์ง |
Functions | ํจ์ ์ ์ธ/ํํ์, ๋งค๊ฐ๋ณ์, ํ์ดํ ํจ์ |
Classes & Prototypes | ํด๋์ค ๋ฌธ๋ฒ, ์์, ํ๋กํ ํ์ ์ฐ๊ฒฐ |
Modules | ES Modules / CommonJS, import/export ๊ท์น |
Iteration & Control Flow | ๋ฐ๋ณต๋ฌธ, ์กฐ๊ฑด๋ฌธ, ์กฐ๊ธฐ ๋ฐํ(early return) ํจํด |
Comparisons & Coercion | == vs ===, truthy/falsy, ํ์ ๊ฐ์ ๋ณํ |
Whitespace & Commas | ๋ค์ฌ์ฐ๊ธฐ, ์ค๋ฐ๊ฟ, ์ฝค๋ง ์คํ์ผ |
Semicolons | ์ธ๋ฏธ์ฝ๋ก ์ฌ์ฉ ์ฌ๋ถ์ Airbnb์ ์ ์ฅ |
Naming & Accessors | ๋ณ์ยทํจ์ ๋ค์ด๋ฐ ์ปจ๋ฒค์ , getter/setter |
ESLint & Prettier Setup | Airbnb ๊ท์น์ ๋ด ํ๋ก์ ํธ์ ์ ์ฉํ๊ธฐ |