目录

no_duplicate_case_values

Don't use more than one case with same value.

此规则自 Dart 2.0 版本起可用。

_规则集:core , recommended , flutter _

此规则提供 快速修复

详情

#

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.

使用方法

#

要启用 no_duplicate_case_values 规则,请在你的 analysis_options.yaml 文件中,在 linter > rules 下添加 no_duplicate_case_values

analysis_options.yaml
yaml
linter:
  rules:
    - no_duplicate_case_values