상세 컨텐츠

본문 제목

함수를 만들 때 주의사항 - 2. 가능한 작게 만들자

Front-End/Javascript

by devloper-jun 2024. 4. 21. 14:40

본문

- https://eslint.org/docs/latest/rules/max-lines-per-function#rule-details

 

max-lines-per-function - 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

- ESLint에는 max-lines-per-function이라는 rule이 존재. 함수의 코드가 길어질수록 문제를 일으킬 확률이 높고, 내부에서 추적이 어려워짐.

- 기본값으로 50줄 이상이 넘어가면 경고 메시지를 출력하며, 얼마나 많은 중첩, 콜백이 많은지도 확인가능하다.

- 한 개의 함수에서 너무 많은 일을 하지 않게 하는 것이 기본적인 규칙. "Do one thing and Do it well" -Malcolm Douglas Mcllory

관련글 더보기