Skip to content

πŸ”– Coding Convention

LeeJunSeok edited this page Jun 22, 2026 · 2 revisions

λͺ…λͺ… κ·œμΉ™

λ³€μˆ˜ 및 ν•¨μˆ˜λŠ” 카멜 μΌ€μ΄μŠ€λ₯Ό μ‚¬μš©ν•œλ‹€.

const count = 1
const totalCount = 1
function onClick(){}

μ»΄ν¬λ„ŒνŠΈ 및 class λŠ” 파슀칼 μΌ€μ΄μŠ€λ₯Ό μ‚¬μš©ν•œλ‹€.

export default function MainComponent() {}
class ChannelService {}

μ •μ μœΌλ‘œ μ„ μ–Έλ˜λŠ” μƒμˆ˜λŠ” 영문 λŒ€λ¬Έμž μŠ€λ„€μ΄ν¬ μΌ€μ΄μŠ€λ₯Ό μ‚¬μš©ν•œλ‹€.

const MAX_COUNT = 100

enum 은 영문 λŒ€λ¬Έμž μŠ€λ„€μ΄ν¬ μΌ€μ΄μŠ€λ₯Ό μ‚¬μš©ν•œλ‹€.

enum ERROR_CODES

단어λ₯Ό μΆ•μ•½ν•˜μ§€ μ•Šκ³  μ΅œλŒ€ν•œ μžμ„Ένžˆ λͺ…λͺ…ν•œλ‹€.

// Bad
let totalCnt
let selectedIdx
// Good
let totalCount
let selectedIndex
// 이런 경우 ν—ˆμš©
let addressInfo

μœ μΆ”ν•˜κΈ° μ–΄λ €μš΄ 이름은 μ‚¬μš©ν•˜μ§€ μ•ŠλŠ”λ‹€.

// Bad
let a
let ls
let qs

볡수λ₯Ό λ‚˜νƒ€λ‚΄λŠ” λ³€μˆ˜λͺ…은 λ‹¨μˆ˜+Listλ₯Ό μ‚¬μš©ν•œλ‹€

// Bad
const categories
const users

// Good
const categoryList
const userList

λ³€μˆ˜

μ „μ—­λ³€μˆ˜ μ‚¬μš©μ„ μ΅œλŒ€ν•œ μ§€μ–‘ν•œλ‹€.

// Bad
myGlobalVariable = true
window.myGlobalVariable = true

varλ₯Ό μ‚¬μš©ν•˜μ§€ μ•ŠλŠ”λ‹€.

// Bad
var index
// Good
let index

boolean λ³€μˆ˜μ˜ ν˜•νƒœλŠ” μ•„λž˜μ™€ κ°™λ‹€. μ»΄ν¬λ„ŒνŠΈμ—μ„œλŠ” HTML Attribute ν˜•μ‹μ„ μ΅œλŒ€ν•œ μ‚¬μš©ν•œλ‹€.

// Good
let isOpen
let hasContent
let shouldRenderIcon
let needPassword
// μ»΄ν¬λ„ŒνŠΈμ—μ„œ ν—ˆμš©
let disabled
let opened
let showButton

ν•¨μˆ˜

ν•¨μˆ˜μ˜ 선언은 ν™”μ‚΄ν‘œ ν•¨μˆ˜λ₯Ό ꢌμž₯ν•œλ‹€.

const getData = () => {}

ν•¨μˆ˜μ— ν•œν•΄ TSDoc ν™œμš©ν•˜λ„λ‘ λ…Έλ ₯ν•œλ‹€.

/**
* Returns data
*
* @param key - data key 
* @returns data
*/
function getData(key) {}

λ§€κ°œλ³€μˆ˜λŠ” 3κ°œκΉŒμ§€λ§Œ μ‚¬μš©ν•˜κ³  κ·Έ 이상은 object ν˜•μ‹μ„ ν™œμš©ν•œλ‹€.

// Good
function getResult(a, b, c)
function getResult(dataObject)
function getResult({ a, b, c, d})

이벀트 ν•¨μˆ˜λŠ” handle + [λŒ€μƒ/도메인] + [λ™μž‘(선택)]

`handleSearch`, `handleLogin` 
`handleUserDelete`, `handleModalOpen`

μ»΄ν¬λ„ŒνŠΈ

μ»΄ν¬λ„ŒνŠΈμ˜ 선언은 ν™”μ‚΄ν‘œ ν•¨μˆ˜λ₯Ό ꢌμž₯ν•œλ‹€.

const App = () => {}
export default App

이벀트 ν•Έλ“€λŸ¬μ˜ 이름은 handle 둜 μ‹œμž‘ν•œλ‹€.

const handleClick = () => {}

κ΅¬ν˜„

if-else 둜 이루어진 쑰건식은 early return 을 ν™œμš©ν•œλ‹€.

// Bad
if(value !== null) {
  ...logic
}

// Good
if(value === null) return
... logic

λ³€μˆ˜λ₯Ό ν™œμš©ν•˜μ—¬ λ¬Έμžμ—΄μ„ μ‘°ν•©ν•  경우 ν…œν”Œλ¦Ώ λ¬Έμžμ—΄μ„ μ‚¬μš©ν•œλ‹€.

// Bad
return "i am" + name

// Good
return `i am ${name}` 

λ“±ν˜ΈλŠ” 삼쀑 λ“±ν˜Έ(===, !==) 만 μ‚¬μš©ν•˜λ„λ‘ ν•œλ‹€.

// Bad
if(value1 == value2)
// Good
if(value1 === value2) 

λͺ¨λ“ˆ

νƒ€μž…μΈ 경우 import type 으둜 μ‚¬μš©ν•œλ‹€.

// Bad
import { Data, DataType } from './Data'
import { DocumentType } from './Document'

// Good
import { Data } from './Data'
import type { DataType } from './Data'
import type { DocumentType } from './Document'

import λ¬ΈμœΌλ‘œλΆ€ν„° 직접 export ν•˜μ§€ μ•ŠλŠ”λ‹€.

// Bad
export * from './data'
// Good
import { data } from './data'
export { data }

넀이밍 (폴더, 파일)

  • 폴더 μž‘λͺ…

    • μŠ€λ„€μ΄ν¬ μΌ€μ΄μŠ€ user_auth
  • 파일

    • μ»΄ν¬λ„ŒνŠΈ : νŒŒμŠ€μΉΌμΌ€μ΄μŠ€ : UserItem.tsx, UserList.tsx
    • ν•¨μˆ˜ : μΉ΄λ©œμΌ€μ΄μŠ€.ts
    • ν›… : useμΉ΄λ©œμΌ€μ΄μŠ€.ts