no_duplicate_case_values
Don't use more than one case with same value.
This rule is available as of Dart 2.0.
Rule sets: core, recommended, flutter
This rule has a quick fix available.
Details
#DON'T use more than one case with same value.
This is usually a typo or changed value of constant.
BAD:
dart
const int A = 1;
switch (v) {
case 1:
case 2:
case A:
case 2:
}
GOOD:
dart
const int A = 1;
switch (v) {
case A:
case 2:
}
NOTE: this lint only reports duplicate cases in libraries opted in to Dart 2.19 and below. In Dart 3.0 and after, duplicate cases are reported as dead code by the analyzer.
Usage
#To enable the no_duplicate_case_values
rule,
add no_duplicate_case_values
under linter > rules in your
analysis_options.yaml
file:
analysis_options.yaml
yaml
linter:
rules:
- no_duplicate_case_values
除非另有说明,文档之所提及适用于 Dart 3.5.4 版本,本页面最后更新时间: 2024-08-02。 查看文档源码 或者 报告页面问题。