deprecated_member_use_from_same_package 린트 규칙

deprecated_member_use_from_same_package 린트 규칙

같은 패키지 안에서 선언된 요소라면 더 이상 사용하지 않는(deprecated) 요소를 참조하지 않도록 도와주는 린트 규칙이에요.

출처: deprecated_member_use_from_same_package

본문

@Deprecated로 표시된 요소는 그 요소를 선언한 패키지 안에서 참조하면 안 돼요.

사용하지 않는 요소는 피하세요.

나쁜 예

// Declared in one library:
class Foo {
  @Deprecated("Use 'm2' instead")
  void m1() {}

  void m2({
      @Deprecated('This is an old parameter') int? p,
  })
}

@Deprecated('Do not use')
int x = 0;

// In the same or another library, but within the same package:
void m(Foo foo) {
  foo.m1();
  foo.m2(p: 7);
  x = 1;
}

이렇게 같은 패키지 안에서 m1(), m2(p:), x 같은 deprecated 요소를 그대로 참조하고 있죠. 이런 코드는 린트가 지적해요.

하지만 deprecated 요소라도 다른 deprecated 요소 안에서는 사용할 수 있어요. 이렇게 하면 여러 API를 한 덩어리로 함께 deprecated 처리할 수 있으니까요.

좋은 예

// Declared in one library:
class Foo {
  @Deprecated("Use 'm2' instead")
  void m1() {}

  void m2({
      @Deprecated('This is an old parameter') int? p,
  })
}

@Deprecated('Do not use')
int x = 0;

// In the same or another library, but within the same package:
@Deprecated('Do not use')
void m(Foo foo) {
  foo.m1();
  foo.m2(p: 7);
  x = 1;
}

이번에는 함수 m 자체도 @Deprecated('Do not use')로 표시되어 있어요. deprecated 요소 안에서 다른 deprecated 요소를 참조하는 건 괜찮아요.

활성화 방법

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

linter:
  rules:
    - deprecated_member_use_from_same_package

linter > rules를 YAML map 문법으로 작성한다면 deprecated_member_use_from_same_package: true처럼 불리언 값을 지정해도 되고요.

linter:
  rules:
    deprecated_member_use_from_same_package: true

더 알아보기

deprecated 처리된 API를 패키지 안에서도 함께 관리하고 싶다면 deprecated_member_use_from_same_package보다는 deprecated_member_use 규칙과 함께 사용하는 걸 고려해 보세요. 린트 규칙 전체 목록은 공식 Linter rules 문서에서 확인할 수 있어요.