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

Commit 26ca53e

Browse files
authored
feat: ignore private members for check-unused-l10n command (#650)
1 parent b2efa39 commit 26ca53e

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* fix: ignore private variables in `avoid-global-state` rule.
66
* feat: support excludes for a separate anti-pattern.
77
* chore: restrict `analyzer` version to `>=2.4.0 <3.2.0`.
8+
* feat: ignore private members for `check-unused-l10n` command.
89

910
## 4.9.1
1011

lib/src/analyzers/unused_l10n_analyzer/unused_l10n_analyzer.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ class UnusedL10nAnalyzer {
168168
CompilationUnitElement unit,
169169
) {
170170
final unusedAccessors = classElement.accessors
171-
.where((field) => !usages.contains(field.name))
171+
.where((field) => !field.isPrivate && !usages.contains(field.name))
172172
.map((field) => field.isSynthetic ? field.nonSynthetic : field);
173173

174174
return unusedAccessors
@@ -182,7 +182,7 @@ class UnusedL10nAnalyzer {
182182
CompilationUnitElement unit,
183183
) {
184184
final unusedMethods = classElement.methods
185-
.where((method) => !usages.contains(method.name))
185+
.where((method) => !method.isPrivate && !usages.contains(method.name))
186186
.map((method) => method.isSynthetic ? method.nonSynthetic : method);
187187

188188
return unusedMethods

test/resources/unused_l10n_analyzer/test_i18n.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ class S {
5050

5151
// ignore: prefer_constructors_over_static_methods
5252
static S get current => S();
53+
54+
static const _privateField = 'hello';
55+
56+
String get _privateGetter => 'regular getter';
57+
58+
String _privateMethod() => 'hi';
5359
}
5460

5561
class L10nClass {

0 commit comments

Comments
 (0)