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

Commit

Permalink
feat: cleanup metrics configs
Browse files Browse the repository at this point in the history
  • Loading branch information
dkrutskikh committed Oct 4, 2021
1 parent 179c505 commit 5574a46
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 22 deletions.
8 changes: 6 additions & 2 deletions lib/src/analyzers/lint_analyzer/metrics/metrics_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@ final _implementedMetrics = <String, Metric Function(Map<String, Object>)>{

Iterable<Metric> getMetrics({
required Map<String, Object> config,
Iterable<String> 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
Expand Down
49 changes: 29 additions & 20 deletions lib/src/config_builder/config_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,35 @@ class ConfigBuilder {
String excludesRootFolder, {
Iterable<Metric<num>>? classMetrics,
Iterable<Metric<num>>? 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<String> excludePatterns,
Expand Down

0 comments on commit 5574a46

Please sign in to comment.