跳到主要內容

annotate_redeclares

實驗性
可用的修正

註解重新宣告的成員。

詳細資訊

#

務必 註解重新宣告的成員。

此作法可改善程式碼可讀性,並有助於防止意外地重新宣告成員,或在成員停止重新宣告時感到驚訝 (例如,由於重新命名重構)。

不良

dart
class C {
  void f() { }
}

extension type E(C c) implements C {
  void f() {
    ...
  }
}

良好

dart
import 'package:meta/meta.dart';

class C {
  void f() { }
}

extension type E(C c) implements C {
  @redeclare
  void f() {
    ...
  }
}

啟用

#

若要啟用 annotate_redeclares 規則,請在您的 analysis_options.yaml 檔案中的 linter > rules 下新增 annotate_redeclares

analysis_options.yaml
yaml
linter:
  rules:
    - annotate_redeclares

如果您改為使用 YAML 地圖語法來設定 linter 規則,請在 linter > rules 下新增 annotate_redeclares: true

analysis_options.yaml
yaml
linter:
  rules:
    annotate_redeclares: true