From dab7f56f3e28c0d4fedf0127b576180012a17590 Mon Sep 17 00:00:00 2001 From: fzyzcjy <5236035+fzyzcjy@users.noreply.github.com> Date: Tue, 19 Apr 2022 15:20:40 +0800 Subject: [PATCH] fix: dart-code-metrics crash saying `Bad state: No element` when running command (#805) * Fix dart-code-metrics crash saying Bad state: No element when running command * Update CHANGELOG.md * fix formatting --- CHANGELOG.md | 4 ++++ lib/src/analyzers/lint_analyzer/utils/report_utils.dart | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f4160df380..f8bac6246f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Unreleased + +* fix: dart-code-metrics crash saying `Bad state: No element` when running command. + ## 4.14.0 * feat: add static code diagnostic [`prefer-commenting-analyzer-ignores`](https://dartcodemetrics.dev/docs/rules/common/prefer-commenting-analyzer-ignores). diff --git a/lib/src/analyzers/lint_analyzer/utils/report_utils.dart b/lib/src/analyzers/lint_analyzer/utils/report_utils.dart index d36ec165e0..09ead8fa4a 100644 --- a/lib/src/analyzers/lint_analyzer/utils/report_utils.dart +++ b/lib/src/analyzers/lint_analyzer/utils/report_utils.dart @@ -15,7 +15,8 @@ MetricValueLevel maxMetricViolationLevel(Iterable records) => (record) => [...record.classes.values, ...record.functions.values] .map((report) => report.metricsLevel), ) - .max; + .maxOrNull ?? + MetricValueLevel.none; bool hasIssueWithSeverity( Iterable records,