join_return_with_assignment: 가능하면 return 문과 할당을 합치세요

join_return_with_assignment: 가능하면 return 문과 할당을 합치세요

join_return_with_assignment 린트는 할당과 그 값을 반환하는 return 문을 합칠 수 있을 때 합치도록 권장하는 규칙이에요. 같은 변수를 할당하고 바로 return하는 코드를 한 줄로 줄여서 더 간결하게 만들 수 있어요.

출처: join_return_with_assignment

본문

설명

DO — 가능하면 return 문과 할당을 합쳐요.

나쁜 예:

class A {
  B _lazyInstance;
  static B get instance {
    _lazyInstance ??= B(); // LINT
    return _lazyInstance;
  }
}

좋은 예:

class A {
  B _lazyInstance;
  static B get instance => _lazyInstance ??= B();
}

활성화(Enable)

join_return_with_assignment 규칙을 활성화하려면 analysis_options.yaml 파일의 linter > rules 아래에 join_return_with_assignment를 추가해요.

linter:
  rules:
    - join_return_with_assignment

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

linter:
  rules:
    join_return_with_assignment: true

더 알아보기