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

Commit

Permalink
fix: support static getters for check unused l10n (#633)
Browse files Browse the repository at this point in the history
* fix: support static getters for check unused l10n

* docs: move gtag in website config (#634)

* fix: remove unreachable code
  • Loading branch information
incendial authored Jan 9, 2022
1 parent 840146c commit 09038f6
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* feat: facelift console reporters.
* chore: restrict `analyzer` version to `>=2.4.0 <3.1.0`.
* chore: restrict `analyzer_plugin` version to `>=0.8.0 <0.10.0`.
* feat: support extensions for check-unused-l10n.
* feat: support extensions and static getters for check-unused-l10n.
* feat: improve `prefer-correct-type-name` rule.
* build: activate check_unused_files on CI.

Expand Down
14 changes: 8 additions & 6 deletions lib/src/analyzers/unused_l10n_analyzer/unused_l10n_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,8 @@ class UnusedL10nVisitor extends RecursiveAstVisitor<void> {
final classTarget = (target as PrefixedIdentifier).identifier;

_addMemberInvocationOnAccessor(classTarget, name);
} else if (_matchMethodOf(target)) {
final classTarget = (target as MethodInvocation).target;

if (_matchIdentifier(classTarget)) {
_addMemberInvocation(classTarget as SimpleIdentifier, name);
}
} else if (_matchStaticGetter(target)) {
_addMemberInvocation((target as PrefixedIdentifier).prefix, name);
}
}

Expand All @@ -102,6 +98,12 @@ class UnusedL10nVisitor extends RecursiveAstVisitor<void> {
target is PrefixedIdentifier &&
target.staticElement?.enclosingElement is ExtensionElement;

bool _matchStaticGetter(Expression? target) =>
target is PrefixedIdentifier &&
_classPattern.hasMatch(
target.staticType?.getDisplayString(withNullability: false) ?? '',
);

void _addMemberInvocation(SimpleIdentifier target, String name) {
final staticElement = target.staticElement;

Expand Down
3 changes: 3 additions & 0 deletions test/resources/unused_l10n_analyzer/test_i18n.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class S {

return S();
}

// ignore: prefer_constructors_over_static_methods
static S get current => S();
}

class L10nClass {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ class SomeClass {

void method() {
S.of('').regularMethod('');
S.of('').regularGetter;
S.current.regularGetter;
}
}
6 changes: 3 additions & 3 deletions website/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ module.exports = {
projectName: 'dart-code-metrics',
trailingSlash: false,
themeConfig: {
gtag: {
trackingID: 'G-C2B16RHS34',
},
algolia: {
apiKey: '77b6353dcfcae7da42fcb75524a90002',
indexName: 'dartcodemetrics',
Expand Down Expand Up @@ -146,6 +143,9 @@ module.exports = {
theme: {
customCss: require.resolve('./src/css/custom.css'),
},
gtag: {
trackingID: 'G-C2B16RHS34',
},
},
],
],
Expand Down

0 comments on commit 09038f6

Please sign in to comment.