Skip to content
This repository was archived by the owner on Jul 16, 2023. It is now read-only.

Commit 7fea291

Browse files
authored
fix: unhandled exception while parsing analysis_options.yaml (#473)
* fix: unhandled exception while parsing `analysis_options.yaml` * chore: sync with stable branch
1 parent 473a956 commit 7fea291

File tree

9 files changed

+62
-47
lines changed

9 files changed

+62
-47
lines changed

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,17 @@
22

33
## Unreleased
44

5-
* Don't trigger prefer-extracting-callbacks on empty function blocks.
5+
* Improve static code diagnostic `prefer-extracting-callbacks`, don't trigger on empty function blocks.
66
* Improve unused files check, add support for `vm:entry-point` annotation.
77

8+
## 4.3.3
9+
10+
* Fix unhandled exception while parsing `analysis_options.yaml`
11+
12+
## 4.3.2
13+
14+
* Restrict analyzer version to '>=2.1.0 <2.4.0'
15+
816
## 4.3.1
917

1018
* Update .pubignore

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ To set this up:
8989
```yaml
9090
name: dart_code_metrics_plugin_loader
9191
description: This pubspec determines the version of the analyzer plugin to load.
92-
version: 4.3.1
92+
version: 4.3.3
9393
9494
environment:
9595
sdk: '>=2.12.0 <3.0.0'

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ A plugin for the Dart `analyzer` [package](https://pub.dev/packages/analyzer) pr
5656

5757
```yaml
5858
dev_dependencies:
59-
dart_code_metrics: ^4.3.1
59+
dart_code_metrics: ^4.3.3
6060
```
6161

6262
and then run

lib/src/analyzers/lint_analyzer/anti_patterns/anti_patterns_list/long_method.dart

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -53,28 +53,29 @@ class LongMethod extends Pattern {
5353
functionMetrics.entries
5454
.where((entry) => !_isExcluded(entry.key))
5555
.expand((entry) => [
56-
...entry.value.metrics
57-
.where((metricValue) =>
58-
metricValue.metricsId ==
59-
SourceLinesOfCodeMetric.metricId &&
60-
metricValue.level >= MetricValueLevel.warning)
61-
.map(
62-
(metricValue) => createIssue(
63-
pattern: this,
64-
location: nodeLocation(
65-
node: entry.key.declaration,
66-
source: source,
67-
),
68-
message: _compileMessage(
69-
lines: metricValue.value,
70-
functionType: entry.key.type,
71-
),
72-
verboseMessage: _compileRecommendationMessage(
73-
maximumLines: _sourceLinesOfCodeMetricTreshold,
74-
functionType: entry.key.type,
56+
if (_sourceLinesOfCodeMetricTreshold != null)
57+
...entry.value.metrics
58+
.where((metricValue) =>
59+
metricValue.metricsId ==
60+
SourceLinesOfCodeMetric.metricId &&
61+
metricValue.value > _sourceLinesOfCodeMetricTreshold!)
62+
.map(
63+
(metricValue) => createIssue(
64+
pattern: this,
65+
location: nodeLocation(
66+
node: entry.key.declaration,
67+
source: source,
68+
),
69+
message: _compileMessage(
70+
lines: metricValue.value,
71+
functionType: entry.key.type,
72+
),
73+
verboseMessage: _compileRecommendationMessage(
74+
maximumLines: _sourceLinesOfCodeMetricTreshold,
75+
functionType: entry.key.type,
76+
),
7577
),
7678
),
77-
),
7879
if (_sourceLinesOfCodeMetricTreshold == null)
7980
// ignore: deprecated_member_use_from_same_package
8081
..._legacyBehaviour(source, entry),

lib/src/analyzers/lint_analyzer/anti_patterns/anti_patterns_list/long_parameter_list.dart

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,28 +50,30 @@ class LongParameterList extends Pattern {
5050
) =>
5151
functionMetrics.entries
5252
.expand((entry) => [
53-
...entry.value.metrics
54-
.where((metricValue) =>
55-
metricValue.metricsId ==
56-
NumberOfParametersMetric.metricId &&
57-
metricValue.level >= MetricValueLevel.warning)
58-
.map(
59-
(metricValue) => createIssue(
60-
pattern: this,
61-
location: nodeLocation(
62-
node: entry.key.declaration,
63-
source: source,
64-
),
65-
message: _compileMessage(
66-
args: metricValue.value,
67-
functionType: entry.key.type,
68-
),
69-
verboseMessage: _compileRecommendationMessage(
70-
maximumArguments: _numberOfParametersMetricTreshold,
71-
functionType: entry.key.type,
53+
if (_numberOfParametersMetricTreshold != null)
54+
...entry.value.metrics
55+
.where((metricValue) =>
56+
metricValue.metricsId ==
57+
NumberOfParametersMetric.metricId &&
58+
metricValue.value >
59+
_numberOfParametersMetricTreshold!)
60+
.map(
61+
(metricValue) => createIssue(
62+
pattern: this,
63+
location: nodeLocation(
64+
node: entry.key.declaration,
65+
source: source,
66+
),
67+
message: _compileMessage(
68+
args: metricValue.value,
69+
functionType: entry.key.type,
70+
),
71+
verboseMessage: _compileRecommendationMessage(
72+
maximumArguments: _numberOfParametersMetricTreshold,
73+
functionType: entry.key.type,
74+
),
7275
),
7376
),
74-
),
7577
if (_numberOfParametersMetricTreshold == null)
7678
// ignore: deprecated_member_use_from_same_package
7779
..._legacyBehaviour(source, entry),

lib/src/utils/yaml_utils.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ List<Object> yamlListToDartList(YamlList list) =>
88
Map<String, Object> yamlMapToDartMap(YamlMap map) =>
99
Map.unmodifiable(Map<String, Object>.fromEntries(map.nodes.keys
1010
.whereType<YamlScalar>()
11-
.where((key) => key.value is String)
11+
.where((key) => key.value is String && map.nodes[key]?.value != null)
1212
.map((key) => MapEntry(
1313
key.value as String,
1414
yamlNodeToDartObject(map.nodes[key]),

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: dart_code_metrics
2-
version: 4.3.1
2+
version: 4.3.3
33
description: Software analytics tool that helps developers analyse and improve software quality.
44
homepage: https://dartcodemetrics.dev
55
repository: https://github.com/dart-code-checker/dart-code-metrics

test/resources/analysis_options_repo.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
include: ./analysis_options_common.yaml
22

3+
linter:
4+
# rules:
5+
# avoid_print: true
6+
37
analyzer:
48
plugins:
59
- code_checker

tools/analyzer_plugin/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name: dart_code_metrics_plugin_loader
22
description: This pubspec determines the version of the analyzer plugin to load.
3-
version: 4.3.1
3+
version: 4.3.3
44

55
environment:
66
sdk: ">=2.12.0 <3.0.0"
77

88
dependencies:
9-
dart_code_metrics: ^4.3.1
9+
dart_code_metrics: ^4.3.3

0 commit comments

Comments
 (0)