empty_statements 진단: 빈 문장은 피하세요

empty_statements 진단: 빈 문장은 피하세요

빈 문장(empty statement)을 쓰지 않도록 알려주는 린트 규칙이에요. 빈 문장은 대부분 버그의 신호라서, 코드를 읽는 사람이 의도를 잘못 짚을 수 있어요.

출처: empty_statements

본문

설명

빈 문장은 피하세요(AVOID).

빈 문장은 거의 항상 버그를 뜻해요. 예를 들어 다음 코드를 봐요.

BAD:

if (complicated.expression.foo());
  bar();

이 코드를 dart format으로 정돈하면 버그가 금방 드러나요.

if (complicated.expression.foo()) ;
bar();

빈 문장 자체를 두지 않는 게 더 낫겠죠.

GOOD:

if (complicated.expression.foo())
  bar();

활성화 방법

empty_statements 규칙을 쓰려면 analysis_options.yaml 파일의 linter > rules 아래에 규칙을 추가하면 돼요.

linter:
  rules:
    - empty_statements

대신 YAML 맵(map) 문법으로 린터 규칙을 설정한다면, linter > rules 아래에 empty_statements: true를 추가해요.

linter:
  rules:
    empty_statements: true

더 알아보기