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

Commit b0ddf09

Browse files
authored
fix: correctly handle excluded files for check-unused-code (#697)
1 parent ced086d commit b0ddf09

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* chore: activate new lint rules.
77
* feat: improve `avoid-returning-widgets` builder functions handling.
88
* fix: correctly handle const maps in `no-magic-number`.
9+
* fix: correctly handle excluded files for `check-unused-code`.
910

1011
## 4.11.0-dev.1
1112

analysis_options.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ analyzer:
55
- test/resources/*
66
- test/resources/unused_files_analyzer/**
77
- test/resources/unused_l10n_analyzer/**
8+
- test/resources/unused_code_analyzer/generated/**
89
- test/**/examples/**
910
language:
1011
strict-inference: true

lib/src/analyzers/unused_code_analyzer/unused_code_analyzer.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,12 @@ class UnusedCodeAnalyzer {
5757
final unusedCodeAnalysisConfig =
5858
await _getAnalysisConfig(context, rootFolder, config);
5959

60-
final excludes = unusedCodeAnalysisConfig.globalExcludes
61-
.followedBy(unusedCodeAnalysisConfig.analyzerExcludedPatterns);
62-
final filePaths = getFilePaths(folders, context, rootFolder, excludes);
60+
final filePaths = getFilePaths(
61+
folders,
62+
context,
63+
rootFolder,
64+
unusedCodeAnalysisConfig.globalExcludes,
65+
);
6366

6467
final analyzedFiles =
6568
filePaths.intersection(context.contextRoot.analyzedFiles().toSet());
@@ -76,7 +79,8 @@ class UnusedCodeAnalyzer {
7679

7780
final notAnalyzedFiles = filePaths.difference(analyzedFiles);
7881
for (final filePath in notAnalyzedFiles) {
79-
if (excludes.any((pattern) => pattern.matches(filePath))) {
82+
if (unusedCodeAnalysisConfig.analyzerExcludedPatterns
83+
.any((pattern) => pattern.matches(filePath))) {
8084
final unit = await resolveFile2(path: filePath);
8185

8286
final codeUsage = _analyzeFileCodeUsages(unit);

0 commit comments

Comments
 (0)