empty_constructor_bodies 린트 규칙
empty_constructor_bodies 린트 규칙
빈 생성자 본문은 {} 대신 ;을 사용하도록 안내하는 린트 규칙이에요.
본문
Effective Dart 가이드를 따르면, 빈 생성자 본문에는 {} 대신 ;을 사용하는 게 좋아요.
Dart에서 본문이 비어 있는 생성자는 세미콜론(;) 하나로 끝낼 수 있어요. const 생성자는 이 방식이 필수인데요, 일관성과 간결함을 위해 다른 생성자들도 이렇게 쓰는 게 좋아요.
나쁜 예
class Point {
int x, y;
Point(this.x, this.y) {}
}
Point(this.x, this.y) {}처럼 빈 중괄호로 본문을 표현하고 있어요.
좋은 예
class Point {
int x, y;
Point(this.x, this.y);
}
Point(this.x, this.y);처럼 세미콜론으로 깔끔하게 끝냈어요.
활성화 방법
이 규칙을 활성화하려면 analysis_options.yaml 파일의 linter > rules 아래에 empty_constructor_bodies을 추가하면 돼요.
linter:
rules:
- empty_constructor_bodies
linter > rules를 YAML map 문법으로 작성한다면 empty_constructor_bodies: true처럼 불리언 값을 지정해도 되고요.
linter:
rules:
empty_constructor_bodies: true
더 알아보기
생성자 작성 규칙에 대해 더 자세히 알고 싶다면 Effective Dart 스타일 가이드의 생성자 항목을 참고해 보세요. 린트 규칙 전체 목록은 공식 Linter rules 문서에서 확인할 수 있어요.