From 5574a46f6d20b367b472fe124dfb756a87f36f2d Mon Sep 17 00:00:00 2001 From: Dmitry Krutskikh Date: Mon, 4 Oct 2021 17:24:20 +0300 Subject: [PATCH] feat: cleanup metrics configs --- .../metrics/metrics_factory.dart | 8 ++- lib/src/config_builder/config_builder.dart | 49 +++++++++++-------- 2 files changed, 35 insertions(+), 22 deletions(-) diff --git a/lib/src/analyzers/lint_analyzer/metrics/metrics_factory.dart b/lib/src/analyzers/lint_analyzer/metrics/metrics_factory.dart index a11743197c..21c7a2aa80 100644 --- a/lib/src/analyzers/lint_analyzer/metrics/metrics_factory.dart +++ b/lib/src/analyzers/lint_analyzer/metrics/metrics_factory.dart @@ -33,10 +33,14 @@ final _implementedMetrics = )>{ Iterable getMetrics({ required Map config, + Iterable patternsDependencies = const [], EntityType? measuredType, }) { - final _metrics = - _implementedMetrics.keys.map((id) => _implementedMetrics[id]!(config)); + final _metrics = _implementedMetrics.keys.map( + (id) => _implementedMetrics[id]!( + !patternsDependencies.contains(id) ? config : {}, + ), + ); return measuredType != null ? _metrics diff --git a/lib/src/config_builder/config_builder.dart b/lib/src/config_builder/config_builder.dart index 30863b0a52..a2ad0169fa 100644 --- a/lib/src/config_builder/config_builder.dart +++ b/lib/src/config_builder/config_builder.dart @@ -25,26 +25,35 @@ class ConfigBuilder { String excludesRootFolder, { Iterable>? classMetrics, Iterable>? functionMetrics, - }) => - LintAnalysisConfig( - prepareExcludes(config.excludePatterns, excludesRootFolder), - getRulesById(config.rules), - prepareExcludes(config.excludeForRulesPatterns, excludesRootFolder), - getPatternsById(config), - classMetrics ?? - getMetrics( - config: config.metrics, - measuredType: EntityType.classEntity, - ), - functionMetrics ?? - getMetrics( - config: config.metrics, - measuredType: EntityType.methodEntity, - ), - prepareExcludes(config.excludeForMetricsPatterns, excludesRootFolder), - config.metrics, - excludesRootFolder, - ); + }) { + final patterns = getPatternsById(config); + final patternsDependencies = patterns + .map((pattern) => pattern.dependentMetricIds) + .expand((e) => e) + .toSet(); + + return LintAnalysisConfig( + prepareExcludes(config.excludePatterns, excludesRootFolder), + getRulesById(config.rules), + prepareExcludes(config.excludeForRulesPatterns, excludesRootFolder), + patterns, + classMetrics ?? + getMetrics( + config: config.metrics, + patternsDependencies: patternsDependencies, + measuredType: EntityType.classEntity, + ), + functionMetrics ?? + getMetrics( + config: config.metrics, + patternsDependencies: patternsDependencies, + measuredType: EntityType.methodEntity, + ), + prepareExcludes(config.excludeForMetricsPatterns, excludesRootFolder), + config.metrics, + excludesRootFolder, + ); + } static UnusedFilesConfig getUnusedFilesConfigFromArgs( Iterable excludePatterns,