Skip to content

Commit a532d0d

Browse files
chore: upgrade to analyzer 8 (#223)
* chore: upgrade to analyzer 8 chore: replace usage of deprecated members * refactor: replace use of Diagnostic.data with expando * fix: upgrade example custom_lint dependency * docs: add changelog for 0.3.2 release
1 parent 7a96dd6 commit a532d0d

File tree

54 files changed

+179
-170
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+179
-170
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## 0.3.2
22

33
- Added `named_parameters_ordering` rule.
4+
- Upgraded to analyzer: ^8.4.0 and custom_lint_builder: ^0.8.1
45

56
## 0.3.1
67

example/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ dependencies:
1010
sdk: flutter
1111

1212
dev_dependencies:
13-
custom_lint: ^0.7.1
13+
custom_lint: ^0.8.1
1414
solid_lints:
1515
path: ../
1616
test: ^1.25.14

lib/src/common/parameters/excluded_identifiers_list_parameter.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class ExcludedIdentifiersListParameter {
5555

5656
/// Returns whether the target node should be ignored during analysis.
5757
bool shouldIgnore(Declaration node) {
58-
final declarationName = node.declaredFragment?.name2;
58+
final declarationName = node.declaredFragment?.name;
5959

6060
final excludedItem = exclude.firstWhereOrNull(
6161
(e) {

lib/src/lints/avoid_debug_print_in_release/avoid_debug_print_in_release_rule.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ your `debugPrint` call in a `!kReleaseMode` check.""",
6161
@override
6262
void run(
6363
CustomLintResolver resolver,
64-
ErrorReporter reporter,
64+
DiagnosticReporter reporter,
6565
CustomLintContext context,
6666
) {
6767
context.registry.addFunctionExpressionInvocation(
@@ -102,7 +102,7 @@ your `debugPrint` call in a `!kReleaseMode` check.""",
102102
void _checkIdentifier({
103103
required Identifier identifier,
104104
required AstNode node,
105-
required ErrorReporter reporter,
105+
required DiagnosticReporter reporter,
106106
}) {
107107
if (!_isDebugPrintNode(identifier)) {
108108
return;
@@ -137,7 +137,7 @@ your `debugPrint` call in a `!kReleaseMode` check.""",
137137
/// Handles variable assignment and declaration
138138
void _handleVariableAssignmentDeclaration({
139139
required AstNode node,
140-
required ErrorReporter reporter,
140+
required DiagnosticReporter reporter,
141141
}) {
142142
final rightOperand = _getRightOperand(node.childEntities.toList());
143143

@@ -159,10 +159,10 @@ your `debugPrint` call in a `!kReleaseMode` check.""",
159159
case PrefixedIdentifier():
160160
final prefix = node.prefix.name;
161161
name = node.name.replaceAll('$prefix.', '');
162-
sourcePath = node.element?.library2?.uri.toString() ?? '';
162+
sourcePath = node.element?.library?.uri.toString() ?? '';
163163
case SimpleIdentifier():
164164
name = node.name;
165-
sourcePath = node.element?.library2?.uri.toString() ?? '';
165+
sourcePath = node.element?.library?.uri.toString() ?? '';
166166

167167
default:
168168
return false;
@@ -193,10 +193,10 @@ your `debugPrint` call in a `!kReleaseMode` check.""",
193193
final prefix = node.prefix.name;
194194

195195
name = node.name.replaceAll('$prefix.', '');
196-
sourcePath = node.element?.library2?.uri.toString() ?? '';
196+
sourcePath = node.element?.library?.uri.toString() ?? '';
197197
case SimpleIdentifier():
198198
name = node.name;
199-
sourcePath = node.element?.library2?.uri.toString() ?? '';
199+
sourcePath = node.element?.library?.uri.toString() ?? '';
200200
default:
201201
return false;
202202
}

lib/src/lints/avoid_final_with_getter/avoid_final_with_getter_rule.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'package:analyzer/error/error.dart' as error;
1+
import 'package:analyzer/diagnostic/diagnostic.dart';
22
import 'package:analyzer/error/listener.dart';
33
import 'package:analyzer/source/source_range.dart';
44
import 'package:custom_lint_builder/custom_lint_builder.dart';
@@ -39,6 +39,8 @@ class AvoidFinalWithGetterRule extends SolidLintRule {
3939
/// the error whether we use final private fields with getters.
4040
static const lintName = 'avoid_final_with_getter';
4141

42+
final _diagnosticsInfoExpando = Expando<FinalWithGetterInfo>();
43+
4244
AvoidFinalWithGetterRule._(super.config);
4345

4446
/// Creates a new instance of [AvoidFinalWithGetterRule]
@@ -56,23 +58,21 @@ class AvoidFinalWithGetterRule extends SolidLintRule {
5658
@override
5759
void run(
5860
CustomLintResolver resolver,
59-
ErrorReporter reporter,
61+
DiagnosticReporter reporter,
6062
CustomLintContext context,
6163
) {
6264
context.registry.addCompilationUnit((node) {
6365
final visitor = AvoidFinalWithGetterVisitor();
6466
node.accept(visitor);
6567

6668
for (final element in visitor.getters) {
67-
reporter.atNode(
68-
element.getter,
69-
code,
70-
data: element,
71-
);
69+
final diagnostic = reporter.atNode(element.getter, code);
70+
71+
_diagnosticsInfoExpando[diagnostic] = element;
7272
}
7373
});
7474
}
7575

7676
@override
77-
List<Fix> getFixes() => [_FinalWithGetterFix()];
77+
List<Fix> getFixes() => [_FinalWithGetterFix(_diagnosticsInfoExpando)];
7878
}

lib/src/lints/avoid_final_with_getter/fixes/avoid_final_with_getter_fix.dart

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
part of '../avoid_final_with_getter_rule.dart';
22

33
class _FinalWithGetterFix extends DartFix {
4+
final Expando<FinalWithGetterInfo> _diagnosticsInfoExpando;
5+
6+
_FinalWithGetterFix(this._diagnosticsInfoExpando);
7+
48
@override
59
void run(
610
CustomLintResolver resolver,
711
ChangeReporter reporter,
812
CustomLintContext context,
9-
error.AnalysisError analysisError,
10-
List<error.AnalysisError> others,
13+
Diagnostic diagnostic,
14+
List<Diagnostic> others,
1115
) {
1216
context.registry.addMethodDeclaration((node) {
13-
if (analysisError.sourceRange.intersects(node.sourceRange)) {
14-
final info = analysisError.data as FinalWithGetterInfo?;
15-
if (info == null) return;
17+
if (!diagnostic.sourceRange.intersects(node.sourceRange)) return;
18+
19+
final info = _diagnosticsInfoExpando[diagnostic];
20+
if (info == null) return;
1621

17-
_addReplacement(reporter, info);
18-
}
22+
_addReplacement(reporter, info);
1923
});
2024
}
2125

lib/src/lints/avoid_final_with_getter/visitors/avoid_final_with_getter_visitor.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'package:analyzer/dart/ast/ast.dart';
22
import 'package:analyzer/dart/ast/visitor.dart';
3-
import 'package:analyzer/dart/element/element2.dart';
3+
import 'package:analyzer/dart/element/element.dart';
44
import 'package:solid_lints/src/lints/avoid_final_with_getter/visitors/getter_variable_visitor.dart';
55

66
/// A visitor that checks for final private fields with getters.
@@ -17,7 +17,7 @@ class AvoidFinalWithGetterVisitor extends RecursiveAstVisitor<void> {
1717
case MethodDeclaration(
1818
isGetter: true,
1919
declaredFragment: ExecutableFragment(
20-
element: ExecutableElement2(
20+
element: ExecutableElement(
2121
isAbstract: false,
2222
isPublic: true,
2323
)

lib/src/lints/avoid_final_with_getter/visitors/getter_variable_visitor.dart

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'package:analyzer/dart/ast/ast.dart';
22
import 'package:analyzer/dart/ast/visitor.dart';
3-
import 'package:analyzer/dart/element/element2.dart';
3+
import 'package:analyzer/dart/element/element.dart';
44

55
/// A visitor that checks the association of the getter with
66
/// the final private variable
@@ -31,14 +31,13 @@ class GetterVariableVisitor extends RecursiveAstVisitor<void> {
3131

3232
extension on MethodDeclaration {
3333
int? get getterReferenceId {
34-
if (body is! ExpressionFunctionBody) return null;
35-
36-
final expression = (body as ExpressionFunctionBody).expression;
37-
if (expression is SimpleIdentifier) {
38-
final element = expression.element;
39-
if (element is PropertyAccessorElement2) {
40-
return element.variable3?.id;
41-
}
34+
if (body
35+
case ExpressionFunctionBody(
36+
expression: SimpleIdentifier(
37+
element: PropertyAccessorElement(:final variable)
38+
)
39+
)) {
40+
return variable.id;
4241
}
4342

4443
return null;

lib/src/lints/avoid_global_state/avoid_global_state_rule.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class AvoidGlobalStateRule extends SolidLintRule {
5757
@override
5858
void run(
5959
CustomLintResolver resolver,
60-
ErrorReporter reporter,
60+
DiagnosticReporter reporter,
6161
CustomLintContext context,
6262
) {
6363
context.registry.addTopLevelVariableDeclaration(
@@ -77,7 +77,7 @@ class AvoidGlobalStateRule extends SolidLintRule {
7777
extension on VariableDeclaration {
7878
bool get isMutable => !isFinal && !isConst;
7979

80-
bool get isPrivate => declaredElement2?.isPrivate ?? false;
80+
bool get isPrivate => declaredFragment?.element.isPrivate ?? false;
8181

8282
bool get isPublicMutable => isMutable && !isPrivate;
8383
}

lib/src/lints/avoid_late_keyword/avoid_late_keyword_rule.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class AvoidLateKeywordRule extends SolidLintRule<AvoidLateKeywordParameters> {
7171
@override
7272
void run(
7373
CustomLintResolver resolver,
74-
ErrorReporter reporter,
74+
DiagnosticReporter reporter,
7575
CustomLintContext context,
7676
) {
7777
context.registry.addVariableDeclaration((node) {

0 commit comments

Comments
 (0)