From d37d46e3bccf5d4061f6e3e7ad90b96ab74c2312 Mon Sep 17 00:00:00 2001 From: Dmitry Krutskikh Date: Thu, 23 Sep 2021 20:28:28 +0300 Subject: [PATCH 1/3] fix: unhandled exception while parsing `analysis_options.yaml` --- CHANGELOG.md | 1 + lib/src/utils/yaml_utils.dart | 2 +- test/resources/analysis_options_repo.yaml | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e30c49010..d691c853bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * Don't trigger prefer-extracting-callbacks on empty function blocks. * Improve unused files check, add support for `vm:entry-point` annotation. +* Fix unhandled exception while parsing `analysis_options.yaml` ## 4.3.1 diff --git a/lib/src/utils/yaml_utils.dart b/lib/src/utils/yaml_utils.dart index b096613920..1a9a501ce3 100644 --- a/lib/src/utils/yaml_utils.dart +++ b/lib/src/utils/yaml_utils.dart @@ -8,7 +8,7 @@ List yamlListToDartList(YamlList list) => Map yamlMapToDartMap(YamlMap map) => Map.unmodifiable(Map.fromEntries(map.nodes.keys .whereType() - .where((key) => key.value is String) + .where((key) => key.value is String && map.nodes[key]?.value != null) .map((key) => MapEntry( key.value as String, yamlNodeToDartObject(map.nodes[key]), diff --git a/test/resources/analysis_options_repo.yaml b/test/resources/analysis_options_repo.yaml index d4b916ebca..1e5c3e8013 100644 --- a/test/resources/analysis_options_repo.yaml +++ b/test/resources/analysis_options_repo.yaml @@ -1,5 +1,9 @@ include: ./analysis_options_common.yaml +linter: + # rules: + # avoid_print: true + analyzer: plugins: - code_checker From 9b2bfd6dfcd590f9ca1a30cc054fd366b200bfb7 Mon Sep 17 00:00:00 2001 From: Dmitry Krutskikh Date: Thu, 23 Sep 2021 21:18:18 +0300 Subject: [PATCH 2/3] chore: sync with stable branch --- CHANGELOG.md | 9 ++++++++- CONTRIBUTING.md | 2 +- README.md | 2 +- pubspec.yaml | 2 +- tools/analyzer_plugin/pubspec.yaml | 4 ++-- 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d691c853bb..c59b573281 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,10 +2,17 @@ ## Unreleased -* Don't trigger prefer-extracting-callbacks on empty function blocks. +* Improve static code diagnostic `prefer-extracting-callbacks`, don't trigger on empty function blocks. * Improve unused files check, add support for `vm:entry-point` annotation. + +## 4.3.3 + * Fix unhandled exception while parsing `analysis_options.yaml` +## 4.3.2 + +* Restrict analyzer version to '>=2.1.0 <2.4.0' + ## 4.3.1 * Update .pubignore diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 79d671d968..50b4e6d908 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -89,7 +89,7 @@ To set this up: ```yaml name: dart_code_metrics_plugin_loader description: This pubspec determines the version of the analyzer plugin to load. - version: 4.3.1 + version: 4.3.3 environment: sdk: '>=2.12.0 <3.0.0' diff --git a/README.md b/README.md index 6efb43716d..1ba721501d 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ A plugin for the Dart `analyzer` [package](https://pub.dev/packages/analyzer) pr ```yaml dev_dependencies: - dart_code_metrics: ^4.3.1 + dart_code_metrics: ^4.3.3 ``` and then run diff --git a/pubspec.yaml b/pubspec.yaml index 3fd747d14e..3592ae04cd 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: dart_code_metrics -version: 4.3.1 +version: 4.3.3 description: Software analytics tool that helps developers analyse and improve software quality. homepage: https://dartcodemetrics.dev repository: https://github.com/dart-code-checker/dart-code-metrics diff --git a/tools/analyzer_plugin/pubspec.yaml b/tools/analyzer_plugin/pubspec.yaml index 9aa164f7ab..29ab145919 100644 --- a/tools/analyzer_plugin/pubspec.yaml +++ b/tools/analyzer_plugin/pubspec.yaml @@ -1,9 +1,9 @@ name: dart_code_metrics_plugin_loader description: This pubspec determines the version of the analyzer plugin to load. -version: 4.3.1 +version: 4.3.3 environment: sdk: ">=2.12.0 <3.0.0" dependencies: - dart_code_metrics: ^4.3.1 + dart_code_metrics: ^4.3.3 From 2f4f0ba184ef29f0e61b2de28f0623fe587a79a0 Mon Sep 17 00:00:00 2001 From: Dmitry Krutskikh Date: Thu, 23 Sep 2021 21:19:23 +0300 Subject: [PATCH 3/3] refactor: improve anti patterns --- .../anti_patterns_list/long_method.dart | 41 +++++++++--------- .../long_parameter_list.dart | 42 ++++++++++--------- 2 files changed, 43 insertions(+), 40 deletions(-) diff --git a/lib/src/analyzers/lint_analyzer/anti_patterns/anti_patterns_list/long_method.dart b/lib/src/analyzers/lint_analyzer/anti_patterns/anti_patterns_list/long_method.dart index 9d3c3216ac..a4a643309a 100644 --- a/lib/src/analyzers/lint_analyzer/anti_patterns/anti_patterns_list/long_method.dart +++ b/lib/src/analyzers/lint_analyzer/anti_patterns/anti_patterns_list/long_method.dart @@ -53,28 +53,29 @@ class LongMethod extends Pattern { functionMetrics.entries .where((entry) => !_isExcluded(entry.key)) .expand((entry) => [ - ...entry.value.metrics - .where((metricValue) => - metricValue.metricsId == - SourceLinesOfCodeMetric.metricId && - metricValue.level >= MetricValueLevel.warning) - .map( - (metricValue) => createIssue( - pattern: this, - location: nodeLocation( - node: entry.key.declaration, - source: source, - ), - message: _compileMessage( - lines: metricValue.value, - functionType: entry.key.type, - ), - verboseMessage: _compileRecommendationMessage( - maximumLines: _sourceLinesOfCodeMetricTreshold, - functionType: entry.key.type, + if (_sourceLinesOfCodeMetricTreshold != null) + ...entry.value.metrics + .where((metricValue) => + metricValue.metricsId == + SourceLinesOfCodeMetric.metricId && + metricValue.value > _sourceLinesOfCodeMetricTreshold!) + .map( + (metricValue) => createIssue( + pattern: this, + location: nodeLocation( + node: entry.key.declaration, + source: source, + ), + message: _compileMessage( + lines: metricValue.value, + functionType: entry.key.type, + ), + verboseMessage: _compileRecommendationMessage( + maximumLines: _sourceLinesOfCodeMetricTreshold, + functionType: entry.key.type, + ), ), ), - ), if (_sourceLinesOfCodeMetricTreshold == null) // ignore: deprecated_member_use_from_same_package ..._legacyBehaviour(source, entry), diff --git a/lib/src/analyzers/lint_analyzer/anti_patterns/anti_patterns_list/long_parameter_list.dart b/lib/src/analyzers/lint_analyzer/anti_patterns/anti_patterns_list/long_parameter_list.dart index 3b063fc628..962a5824ee 100644 --- a/lib/src/analyzers/lint_analyzer/anti_patterns/anti_patterns_list/long_parameter_list.dart +++ b/lib/src/analyzers/lint_analyzer/anti_patterns/anti_patterns_list/long_parameter_list.dart @@ -50,28 +50,30 @@ class LongParameterList extends Pattern { ) => functionMetrics.entries .expand((entry) => [ - ...entry.value.metrics - .where((metricValue) => - metricValue.metricsId == - NumberOfParametersMetric.metricId && - metricValue.level >= MetricValueLevel.warning) - .map( - (metricValue) => createIssue( - pattern: this, - location: nodeLocation( - node: entry.key.declaration, - source: source, - ), - message: _compileMessage( - args: metricValue.value, - functionType: entry.key.type, - ), - verboseMessage: _compileRecommendationMessage( - maximumArguments: _numberOfParametersMetricTreshold, - functionType: entry.key.type, + if (_numberOfParametersMetricTreshold != null) + ...entry.value.metrics + .where((metricValue) => + metricValue.metricsId == + NumberOfParametersMetric.metricId && + metricValue.value > + _numberOfParametersMetricTreshold!) + .map( + (metricValue) => createIssue( + pattern: this, + location: nodeLocation( + node: entry.key.declaration, + source: source, + ), + message: _compileMessage( + args: metricValue.value, + functionType: entry.key.type, + ), + verboseMessage: _compileRecommendationMessage( + maximumArguments: _numberOfParametersMetricTreshold, + functionType: entry.key.type, + ), ), ), - ), if (_numberOfParametersMetricTreshold == null) // ignore: deprecated_member_use_from_same_package ..._legacyBehaviour(source, entry),