Skip to content

Commit

Permalink
Analyer v6 (#2791)
Browse files Browse the repository at this point in the history
  • Loading branch information
rrousselGit authored Aug 3, 2023
1 parent 3908e41 commit 540dd03
Show file tree
Hide file tree
Showing 24 changed files with 78 additions and 57 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ jobs:
strategy:
matrix:
channel:
- stable
# Disabled due to some outdated dependencies on Flutter stable
# - stable
- master
package_path:
- examples/counter
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ on:
types:
- opened
- reopened
pull_request:
types:
- opened
- reopened

jobs:
add-to-project:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/riverpod_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
strategy:
matrix:
channel:
- stable
- master
package_path:
- packages/riverpod_analyzer_utils
- packages/riverpod_analyzer_utils_tests
Expand Down
2 changes: 1 addition & 1 deletion examples/counter/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dependencies:
dev_dependencies:
build_runner: ^2.3.3
build_verify: ^3.0.0
custom_lint: ^0.4.0
custom_lint: ^0.5.1
flutter_test:
sdk: flutter
freezed: ^2.3.2
Expand Down
2 changes: 2 additions & 0 deletions examples/pub/pubspec_overrides.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ dependency_overrides:
path: ../../packages/riverpod_annotation
riverpod_generator:
path: ../../packages/riverpod_generator
# necessary for mockito
analyzer: ^6.0.0
2 changes: 2 additions & 0 deletions examples/stackoverflow/pubspec_overrides.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ dependency_overrides:
path: ../../packages/riverpod_annotation
riverpod_generator:
path: ../../packages/riverpod_generator
# necessary for mockito
analyzer: ^6.0.0
2 changes: 1 addition & 1 deletion packages/riverpod/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies:
state_notifier: ^0.7.2

dev_dependencies:
analyzer: ^4.6.0
analyzer: ^6.0.0
expect_error: ^1.0.0
mockito: ^5.0.0
test: ^1.16.0
Expand Down
3 changes: 3 additions & 0 deletions packages/riverpod/pubspec_overrides.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dependency_overrides:
# necessary for mockito
analyzer: ^6.0.0
4 changes: 4 additions & 0 deletions packages/riverpod_analyzer_utils/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Unreleased patch

Support analyzer 6.0.0

## 0.3.1 - 2023-05-12

- Upgrade `custom_lint_core` to 0.4.0
Expand Down
4 changes: 2 additions & 2 deletions packages/riverpod_analyzer_utils/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ environment:
sdk: ">=2.18.0 <3.0.0"

dependencies:
analyzer: ^5.12.0
analyzer: ^6.0.0
collection: ^1.16.0
crypto: ^3.0.2
custom_lint_core: ^0.4.0
custom_lint_core: ^0.5.1
freezed_annotation: ^2.2.0
meta: ^1.7.0
path: ^1.8.0
Expand Down
2 changes: 1 addition & 1 deletion packages/riverpod_analyzer_utils_tests/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ environment:
sdk: ">=2.18.0 <3.0.0"

dependencies:
analyzer: ^5.12.0
analyzer: ^6.0.0
collection: ^1.16.0
freezed_annotation: ^2.2.0
meta: ^1.7.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,13 @@ int sixth(SixthRef ref) => 0;
errors[4].message,
'Unsupported dependency. Only functions and classes annotated by @riverpod are supported.',
);
expect(errors[4].targetElement.toString(), 'int sixth(dynamic ref)');
expect(errors[4].targetElement.toString(), 'int sixth(InvalidType ref)');

expect(
errors[5].message,
'Failed to parse dependency Type (int*)',
);
expect(errors[5].targetElement?.toString(), 'int sixth(dynamic ref)');
expect(errors[5].targetElement?.toString(), 'int sixth(InvalidType ref)');
});

testSource('Decode name', runGenerator: true, source: r'''
Expand Down
71 changes: 36 additions & 35 deletions packages/riverpod_cli/lib/src/migrate/unified_syntax.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class RiverpodProviderUsageInfo extends GeneralizingAstVisitor<void>
void visitFunctionDeclaration(FunctionDeclaration node) {
try {
currentFunctionInfo = ProviderFunction(
name: node.name.name,
name: node.name.lexeme,
path: node.declaredElement!.declaration.location!.components.join('/'),
line: node.name.offset,
);
Expand All @@ -121,7 +121,7 @@ class RiverpodProviderUsageInfo extends GeneralizingAstVisitor<void>
void visitMethodDeclaration(MethodDeclaration node) {
try {
currentFunctionInfo = ProviderFunction(
name: node.name.name,
name: node.name.lexeme,
path: node.declaredElement!.declaration.location!.components.join('/'),
line: node.name.offset,
);
Expand Down Expand Up @@ -226,7 +226,7 @@ class RiverpodUnifiedSyntaxChangesMigrationSuggestor
try {
foundProviderUsage.add(false);
methodDecls.clear();
final name = node.extendsClause?.superclass.name.name;
final name = node.extendsClause?.superclass.name2.lexeme;
if (name == 'StatelessWidget') {
withinClass = ClassType.stateless;
} else if (name == 'State') {
Expand All @@ -240,9 +240,9 @@ class RiverpodUnifiedSyntaxChangesMigrationSuggestor
withinClass = ClassType.none;
}
if (name == 'StatefulWidget') {
statefulDeclarations[node.name.name] = node;
if (statefulNeedsMigration.contains(node.name.name)) {
migrateStateful(node.name.name);
statefulDeclarations[node.name.lexeme] = node;
if (statefulNeedsMigration.contains(node.name.lexeme)) {
migrateStateful(node.name.lexeme);
}
}
} catch (e, st) {
Expand Down Expand Up @@ -334,8 +334,8 @@ class RiverpodUnifiedSyntaxChangesMigrationSuggestor
} else if (withinClass == ClassType.stateful) {
yieldPatch(
'ConsumerState',
classDecl.extendsClause!.superclass.name.offset,
classDecl.extendsClause!.superclass.name.end,
classDecl.extendsClause!.superclass.name2.offset,
classDecl.extendsClause!.superclass.name2.end,
);

migrateStateful(
Expand Down Expand Up @@ -384,7 +384,7 @@ class RiverpodUnifiedSyntaxChangesMigrationSuggestor
node.functionExpression.parameters!.rightParenthesis.offset,
);
}
functionDecls[node.name.name] = node;
functionDecls[node.name.lexeme] = node;
} catch (e, st) {
addError('migrating function declaration $node\n$e\n$st');
}
Expand All @@ -405,7 +405,7 @@ class RiverpodUnifiedSyntaxChangesMigrationSuggestor
node.parameters!.rightParenthesis.offset,
);
}
methodDecls[node.name.name] = node;
methodDecls[node.name.lexeme] = node;
} catch (e, st) {
addError('migrating function declaration $node\n$e\n$st');
}
Expand Down Expand Up @@ -496,7 +496,7 @@ class RiverpodUnifiedSyntaxChangesMigrationSuggestor
bool inAutoDisposeProvider = false;
String providerTypeArgs = '';
@override
void visitTypeName(TypeName node) {
void visitNamedType(NamedType node) {
final typeName = node.type?.getDisplayString(withNullability: true);

try {
Expand All @@ -506,55 +506,55 @@ class RiverpodUnifiedSyntaxChangesMigrationSuggestor
case ProviderType.stream:
yieldPatch(
'${autoDisposePrefix}StreamProviderRef<$providerTypeArgs>',
node.name.offset,
node.name.end,
node.name2.offset,
node.name2.end,
);
break;
case ProviderType.future:
yieldPatch(
'${autoDisposePrefix}FutureProviderRef<$providerTypeArgs>',
node.name.offset,
node.name.end,
node.name2.offset,
node.name2.end,
);
break;
case ProviderType.plain:
yieldPatch(
'${autoDisposePrefix}ProviderRef<$providerTypeArgs>',
node.name.offset,
node.name.end,
node.name2.offset,
node.name2.end,
);
break;
case ProviderType.state:
yieldPatch(
'${autoDisposePrefix}StateProviderRef<$providerTypeArgs>',
node.name.offset,
node.name.end,
node.name2.offset,
node.name2.end,
);
break;
case ProviderType.statenotifier:
yieldPatch(
'${autoDisposePrefix}StateNotifierProviderRef<$providerTypeArgs>',
node.name.offset,
node.name.end,
node.name2.offset,
node.name2.end,
);
break;
case ProviderType.changenotifier:
yieldPatch(
'${autoDisposePrefix}ChangeNotifierProviderRef<$providerTypeArgs>',
node.name.offset,
node.name.end,
node.name2.offset,
node.name2.end,
);
break;
case ProviderType.none:
yieldPatch('Ref', node.name.offset, node.name.end);
yieldPatch('Ref', node.name2.offset, node.name2.end);
break;
}
}
} catch (e, st) {
addError('when visiting type $typeName\n$e\n$st');
}

super.visitTypeName(node);
super.visitNamedType(node);
}

void updateProviderType(String type, DartType staticType) {
Expand Down Expand Up @@ -785,16 +785,16 @@ class RiverpodUnifiedSyntaxChangesMigrationSuggestor
void visitFunctionDeclaration(FunctionDeclaration node) {
try {
final func = ProviderFunction(
name: node.name.name,
name: node.name.lexeme,
path: node.declaredElement!.declaration.location!.components.join('/'),
line: node.name.offset,
);
if (RiverpodProviderUsageInfo.shouldMigrate(func)) {
migrateFunctionDeclaration(node);
}

functionDecls[node.name.name] = node;
migrateOnChangeFunction(node.name.name);
functionDecls[node.name.lexeme] = node;
migrateOnChangeFunction(node.name.lexeme);
} catch (e, st) {
addError('before visiting function declaration\n$e\n$st');
}
Expand All @@ -804,14 +804,14 @@ class RiverpodUnifiedSyntaxChangesMigrationSuggestor
@override
void visitMethodDeclaration(MethodDeclaration node) {
try {
if (node.name.name == 'build') {
if (node.name.lexeme == 'build') {
buildParams = node.parameters;
functionBody = node.body;
if (withinClass == ClassType.consumer) {
// Consumer should be migrated regardless if providers are watched / read or not
migrateParams(buildParams);
}
} else if (node.name.name == 'didUpdateProvider') {
} else if (node.name.lexeme == 'didUpdateProvider') {
yieldPatch(
', ProviderContainer container',
node.parameters!.parameters.last.end,
Expand All @@ -824,17 +824,17 @@ class RiverpodUnifiedSyntaxChangesMigrationSuggestor
);
}
final func = ProviderFunction(
name: node.name.name,
name: node.name.lexeme,
path: node.declaredElement!.declaration.location!.components.join('/'),
line: node.name.offset,
);
if (node.name.name != 'build' &&
if (node.name.lexeme != 'build' &&
RiverpodProviderUsageInfo.shouldMigrate(func)) {
migrateMethodDeclaration(node);
}

methodDecls[node.name.name] = node;
migrateOnChangeFunction(node.name.name);
methodDecls[node.name.lexeme] = node;
migrateOnChangeFunction(node.name.lexeme);
} catch (e, st) {
addError('before visiting method declaration\n$e\n$st');
}
Expand Down Expand Up @@ -977,7 +977,8 @@ class RiverpodUnifiedSyntaxChangesMigrationSuggestor
statefulDeclaration.extendsClause!.superclass.end,
);
final method = statefulDeclaration.members.firstWhereOrNull(
(m) => m is MethodDeclaration && m.name.name.contains('createState'),
(m) =>
m is MethodDeclaration && m.name.lexeme.contains('createState'),
) as MethodDeclaration?;

if (method != null &&
Expand Down
2 changes: 1 addition & 1 deletion packages/riverpod_cli/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ environment:
sdk: '>=2.12.0 <3.0.0'

dependencies:
analyzer: "^1.5.0"
analyzer: ^6.0.0
args: ^2.0.0
codemod: ^1.0.1
collection: ^1.15.0
Expand Down
3 changes: 3 additions & 0 deletions packages/riverpod_cli/pubspec_overrides.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dependency_overrides:
# necessary for codemod
analyzer: ^6.0.0
4 changes: 4 additions & 0 deletions packages/riverpod_generator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Unreleased patch

Support analyzer 6.0.0

## 2.2.4 - 2023-07-25

Disable all lints in generated files.
Expand Down
2 changes: 1 addition & 1 deletion packages/riverpod_generator/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ environment:
sdk: ">=2.17.0 <3.0.0"

dependencies:
analyzer: ">4.2.0 <6.0.0"
analyzer: ^6.0.0
build: ^2.0.0
build_config: ^1.0.0
collection: ^1.15.0
Expand Down
3 changes: 3 additions & 0 deletions packages/riverpod_graph/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Unreleased patch

Support analyzer 6.0.0
2 changes: 1 addition & 1 deletion packages/riverpod_graph/lib/src/analyze.dart
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ class ProviderDependencyVisitor extends RecursiveAstVisitor<void> {
final buildMethod = classDeclaration.members
.whereType<MethodDeclaration>()
.firstWhere(
(method) => method.name.name == 'build',
(method) => method.name.lexeme == 'build',
);
// Instead of continuing with the current node, we visit the one of
// the referenced constructor.
Expand Down
2 changes: 1 addition & 1 deletion packages/riverpod_graph/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ environment:
sdk: ">=2.15.0 <3.0.0"

dependencies:
analyzer: ">=4.0.0 <4.1.0"
analyzer: ^6.0.0
args: ^2.4.0
collection: ^1.0.0
path: ^1.8.2
Expand Down
1 change: 1 addition & 0 deletions packages/riverpod_lint/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Added `avoid_ref_inside_state_dispose` (thanks to @LeonardoRosaa).
This warns if a `WidgetRef` is used in `State.dispose`, which would result
in a runtime error.
- Support analyzer 6.0.0

## 1.4.0 - 2023-07-25

Expand Down
Loading

0 comments on commit 540dd03

Please sign in to comment.