From f9e1a99d1ac0fbb91363ec0e442266a285f5c31e Mon Sep 17 00:00:00 2001 From: Parker Lougheed Date: Sat, 1 Jul 2023 00:41:32 -0500 Subject: [PATCH] Account for linter changes in linter_tool (#1930) --- experimental/linting_tool/lib/model/rule.dart | 4 +- .../linting_tool/lib/model/rule.g.dart | 8 +- .../lib/repository/api_provider.dart | 4 +- .../lib/widgets/lint_expansion_tile.dart | 4 +- .../lib/widgets/saved_rule_tile.dart | 4 +- experimental/linting_tool/pubspec.yaml | 6 +- .../linting_tool/test/widget_test.dart | 4 +- .../linting_tool/test/widget_test.mocks.dart | 289 ++++++++++++++---- 8 files changed, 239 insertions(+), 84 deletions(-) diff --git a/experimental/linting_tool/lib/model/rule.dart b/experimental/linting_tool/lib/model/rule.dart index ae88ed499..224bdfbec 100644 --- a/experimental/linting_tool/lib/model/rule.dart +++ b/experimental/linting_tool/lib/model/rule.dart @@ -18,7 +18,7 @@ class Rule extends Equatable { @HiveField(2) final String group; @HiveField(3) - final String maturity; + final String state; @HiveField(4) final List incompatible; @HiveField(5) @@ -30,7 +30,7 @@ class Rule extends Equatable { required this.name, required this.description, required this.group, - required this.maturity, + required this.state, required this.incompatible, required this.sets, required this.details, diff --git a/experimental/linting_tool/lib/model/rule.g.dart b/experimental/linting_tool/lib/model/rule.g.dart index 22d577e0f..bc9e8f8af 100644 --- a/experimental/linting_tool/lib/model/rule.g.dart +++ b/experimental/linting_tool/lib/model/rule.g.dart @@ -20,7 +20,7 @@ class RuleAdapter extends TypeAdapter { name: fields[0] as String, description: fields[1] as String, group: fields[2] as String, - maturity: fields[3] as String, + state: fields[3] as String, incompatible: (fields[4] as List).cast(), sets: (fields[5] as List).cast(), details: fields[6] as String, @@ -38,7 +38,7 @@ class RuleAdapter extends TypeAdapter { ..writeByte(2) ..write(obj.group) ..writeByte(3) - ..write(obj.maturity) + ..write(obj.state) ..writeByte(4) ..write(obj.incompatible) ..writeByte(5) @@ -66,7 +66,7 @@ Rule _$RuleFromJson(Map json) => Rule( name: json['name'] as String, description: json['description'] as String, group: json['group'] as String, - maturity: json['maturity'] as String, + state: json['state'] as String, incompatible: (json['incompatible'] as List) .map((e) => e as String) .toList(), @@ -78,7 +78,7 @@ Map _$RuleToJson(Rule instance) => { 'name': instance.name, 'description': instance.description, 'group': instance.group, - 'maturity': instance.maturity, + 'state': instance.state, 'incompatible': instance.incompatible, 'sets': instance.sets, 'details': instance.details, diff --git a/experimental/linting_tool/lib/repository/api_provider.dart b/experimental/linting_tool/lib/repository/api_provider.dart index 76045a830..40b81a149 100644 --- a/experimental/linting_tool/lib/repository/api_provider.dart +++ b/experimental/linting_tool/lib/repository/api_provider.dart @@ -16,7 +16,7 @@ class APIProvider { Future> getRulesList() async { final response = - await httpClient.get(Uri.parse('$_baseURL//lints/machine/rules.json')); + await httpClient.get(Uri.parse('$_baseURL/lints/machine/rules.json')); if (response.statusCode == 200) { final data = json.decode(response.body) as List; @@ -31,7 +31,7 @@ class APIProvider { Future getTemplateFile() async { final response = await httpClient.get(Uri.parse( - 'https://raw.githubusercontent.com/flutter/flutter/master/packages/flutter_tools/templates/app_shared/analysis_options.yaml.tmpl')); + 'https://raw.githubusercontent.com/flutter/flutter/main/packages/flutter_tools/templates/app_shared/analysis_options.yaml.tmpl')); if (response.statusCode == 200) { return loadYaml(response.body) as YamlMap; } else { diff --git a/experimental/linting_tool/lib/widgets/lint_expansion_tile.dart b/experimental/linting_tool/lib/widgets/lint_expansion_tile.dart index 001156d56..8e476f998 100644 --- a/experimental/linting_tool/lib/widgets/lint_expansion_tile.dart +++ b/experimental/linting_tool/lib/widgets/lint_expansion_tile.dart @@ -79,11 +79,11 @@ class _LintExpansionTileState extends State { TextSpan( children: [ TextSpan( - text: 'Maturity:', + text: 'State:', style: textTheme.titleSmall, ), TextSpan( - text: ' ${rule.maturity}', + text: ' ${rule.state}', ), ], ), diff --git a/experimental/linting_tool/lib/widgets/saved_rule_tile.dart b/experimental/linting_tool/lib/widgets/saved_rule_tile.dart index 853383140..79c927025 100644 --- a/experimental/linting_tool/lib/widgets/saved_rule_tile.dart +++ b/experimental/linting_tool/lib/widgets/saved_rule_tile.dart @@ -101,11 +101,11 @@ class _SavedRuleTileState extends State { TextSpan( children: [ TextSpan( - text: 'Maturity:', + text: 'State:', style: textTheme.titleSmall, ), TextSpan( - text: ' ${rule.maturity}', + text: ' ${rule.state}', ), ], ), diff --git a/experimental/linting_tool/pubspec.yaml b/experimental/linting_tool/pubspec.yaml index 99feed37d..20f1dcaca 100644 --- a/experimental/linting_tool/pubspec.yaml +++ b/experimental/linting_tool/pubspec.yaml @@ -21,7 +21,7 @@ dependencies: hive_flutter: ^1.1.0 http: ^1.0.0 json2yaml: ^3.0.0 - json_annotation: ^4.5.0 + json_annotation: ^4.8.1 mockito: ^5.0.13 provider: ^6.0.2 yaml: ^3.1.0 @@ -36,9 +36,9 @@ dev_dependencies: path: ../../analysis_defaults flutter_test: sdk: flutter - build_runner: ^2.0.6 + build_runner: ^2.4.6 hive_generator: ^2.0.0 - json_serializable: ^6.2.0 + json_serializable: ^6.7.1 flutter: uses-material-design: true diff --git a/experimental/linting_tool/test/widget_test.dart b/experimental/linting_tool/test/widget_test.dart index 10bffef4b..bccdb599a 100644 --- a/experimental/linting_tool/test/widget_test.dart +++ b/experimental/linting_tool/test/widget_test.dart @@ -72,10 +72,10 @@ void main() { testWidgets('NavigationRail smoke test', (tester) async { var responseBody = - '''[{"name": "always_use_package_imports","description": "Avoid relative imports for files in `lib/`.","group": "errors","maturity": "stable","incompatible": [],"sets": [],"details": "*DO* avoid relative imports for files in `lib/`.\n\nWhen mixing relative and absolute imports it's possible to create confusion\nwhere the same member gets imported in two different ways. One way to avoid\nthat is to ensure you consistently use absolute imports for files withing the\n`lib/` directory.\n\nThis is the opposite of 'prefer_relative_imports'.\nMight be used with 'avoid_relative_lib_imports' to avoid relative imports of\nfiles within `lib/` directory outside of it. (for example `test/`)\n\n**GOOD:**\n\n```dart\nimport 'package:foo/bar.dart';\n\nimport 'package:foo/baz.dart';\n\nimport 'package:foo/src/baz.dart';\n...\n```\n\n**BAD:**\n\n```dart\nimport 'baz.dart';\n\nimport 'src/bag.dart'\n\nimport '../lib/baz.dart';\n\n...\n```\n\n"}]'''; + '''[{"name": "always_use_package_imports","description": "Avoid relative imports for files in `lib/`.","group": "errors","state": "stable","incompatible": [],"sets": [],"details": "*DO* avoid relative imports for files in `lib/`.\n\nWhen mixing relative and absolute imports it's possible to create confusion\nwhere the same member gets imported in two different ways. One way to avoid\nthat is to ensure you consistently use absolute imports for files withing the\n`lib/` directory.\n\nThis is the opposite of 'prefer_relative_imports'.\nMight be used with 'avoid_relative_lib_imports' to avoid relative imports of\nfiles within `lib/` directory outside of it. (for example `test/`)\n\n**GOOD:**\n\n```dart\nimport 'package:foo/bar.dart';\n\nimport 'package:foo/baz.dart';\n\nimport 'package:foo/src/baz.dart';\n...\n```\n\n**BAD:**\n\n```dart\nimport 'baz.dart';\n\nimport 'src/bag.dart'\n\nimport '../lib/baz.dart';\n\n...\n```\n\n"}]'''; when(_mockClient.get(Uri.parse( - 'https://dart-lang.github.io/linter//lints/machine/rules.json'))) + 'https://dart-lang.github.io/linter/lints/machine/rules.json'))) .thenAnswer( (_) async => http.Response(responseBody, 400), ); diff --git a/experimental/linting_tool/test/widget_test.mocks.dart b/experimental/linting_tool/test/widget_test.mocks.dart index 4e4b435c9..c3b2fb95d 100644 --- a/experimental/linting_tool/test/widget_test.mocks.dart +++ b/experimental/linting_tool/test/widget_test.mocks.dart @@ -1,15 +1,13 @@ -// Mocks generated by Mockito 5.2.0 from annotations +// Mocks generated by Mockito 5.4.2 from annotations // in linting_tool/test/widget_test.dart. // Do not manually edit this file. -import 'dart:async' as _i5; -import 'dart:convert' as _i6; -import 'dart:typed_data' as _i7; +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:async' as _i3; +import 'dart:convert' as _i4; +import 'dart:typed_data' as _i5; -import 'package:http/src/base_request.dart' as _i8; -import 'package:http/src/client.dart' as _i4; -import 'package:http/src/response.dart' as _i2; -import 'package:http/src/streamed_response.dart' as _i3; +import 'package:http/http.dart' as _i2; import 'package:mockito/mockito.dart' as _i1; // ignore_for_file: type=lint @@ -21,88 +19,245 @@ import 'package:mockito/mockito.dart' as _i1; // ignore_for_file: prefer_const_constructors // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types +// ignore_for_file: subtype_of_sealed_class -class _FakeResponse_0 extends _i1.Fake implements _i2.Response {} +class _FakeResponse_0 extends _i1.SmartFake implements _i2.Response { + _FakeResponse_0( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} -class _FakeStreamedResponse_1 extends _i1.Fake - implements _i3.StreamedResponse {} +class _FakeStreamedResponse_1 extends _i1.SmartFake + implements _i2.StreamedResponse { + _FakeStreamedResponse_1( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} /// A class which mocks [Client]. /// /// See the documentation for Mockito's code generation for more information. -class MockClient extends _i1.Mock implements _i4.Client { +class MockClient extends _i1.Mock implements _i2.Client { MockClient() { _i1.throwOnMissingStub(this); } @override - _i5.Future<_i2.Response> head(Uri? url, {Map? headers}) => - (super.noSuchMethod(Invocation.method(#head, [url], {#headers: headers}), - returnValue: Future<_i2.Response>.value(_FakeResponse_0())) - as _i5.Future<_i2.Response>); + _i3.Future<_i2.Response> head( + Uri? url, { + Map? headers, + }) => + (super.noSuchMethod( + Invocation.method( + #head, + [url], + {#headers: headers}, + ), + returnValue: _i3.Future<_i2.Response>.value(_FakeResponse_0( + this, + Invocation.method( + #head, + [url], + {#headers: headers}, + ), + )), + ) as _i3.Future<_i2.Response>); @override - _i5.Future<_i2.Response> get(Uri? url, {Map? headers}) => - (super.noSuchMethod(Invocation.method(#get, [url], {#headers: headers}), - returnValue: Future<_i2.Response>.value(_FakeResponse_0())) - as _i5.Future<_i2.Response>); + _i3.Future<_i2.Response> get( + Uri? url, { + Map? headers, + }) => + (super.noSuchMethod( + Invocation.method( + #get, + [url], + {#headers: headers}, + ), + returnValue: _i3.Future<_i2.Response>.value(_FakeResponse_0( + this, + Invocation.method( + #get, + [url], + {#headers: headers}, + ), + )), + ) as _i3.Future<_i2.Response>); @override - _i5.Future<_i2.Response> post(Uri? url, - {Map? headers, - Object? body, - _i6.Encoding? encoding}) => + _i3.Future<_i2.Response> post( + Uri? url, { + Map? headers, + Object? body, + _i4.Encoding? encoding, + }) => (super.noSuchMethod( - Invocation.method(#post, [url], - {#headers: headers, #body: body, #encoding: encoding}), - returnValue: Future<_i2.Response>.value(_FakeResponse_0())) - as _i5.Future<_i2.Response>); + Invocation.method( + #post, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + returnValue: _i3.Future<_i2.Response>.value(_FakeResponse_0( + this, + Invocation.method( + #post, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + )), + ) as _i3.Future<_i2.Response>); @override - _i5.Future<_i2.Response> put(Uri? url, - {Map? headers, - Object? body, - _i6.Encoding? encoding}) => + _i3.Future<_i2.Response> put( + Uri? url, { + Map? headers, + Object? body, + _i4.Encoding? encoding, + }) => (super.noSuchMethod( - Invocation.method(#put, [url], - {#headers: headers, #body: body, #encoding: encoding}), - returnValue: Future<_i2.Response>.value(_FakeResponse_0())) - as _i5.Future<_i2.Response>); + Invocation.method( + #put, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + returnValue: _i3.Future<_i2.Response>.value(_FakeResponse_0( + this, + Invocation.method( + #put, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + )), + ) as _i3.Future<_i2.Response>); @override - _i5.Future<_i2.Response> patch(Uri? url, - {Map? headers, - Object? body, - _i6.Encoding? encoding}) => + _i3.Future<_i2.Response> patch( + Uri? url, { + Map? headers, + Object? body, + _i4.Encoding? encoding, + }) => (super.noSuchMethod( - Invocation.method(#patch, [url], - {#headers: headers, #body: body, #encoding: encoding}), - returnValue: Future<_i2.Response>.value(_FakeResponse_0())) - as _i5.Future<_i2.Response>); + Invocation.method( + #patch, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + returnValue: _i3.Future<_i2.Response>.value(_FakeResponse_0( + this, + Invocation.method( + #patch, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + )), + ) as _i3.Future<_i2.Response>); @override - _i5.Future<_i2.Response> delete(Uri? url, - {Map? headers, - Object? body, - _i6.Encoding? encoding}) => + _i3.Future<_i2.Response> delete( + Uri? url, { + Map? headers, + Object? body, + _i4.Encoding? encoding, + }) => (super.noSuchMethod( - Invocation.method(#delete, [url], - {#headers: headers, #body: body, #encoding: encoding}), - returnValue: Future<_i2.Response>.value(_FakeResponse_0())) - as _i5.Future<_i2.Response>); + Invocation.method( + #delete, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + returnValue: _i3.Future<_i2.Response>.value(_FakeResponse_0( + this, + Invocation.method( + #delete, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + )), + ) as _i3.Future<_i2.Response>); @override - _i5.Future read(Uri? url, {Map? headers}) => - (super.noSuchMethod(Invocation.method(#read, [url], {#headers: headers}), - returnValue: Future.value('')) as _i5.Future); + _i3.Future read( + Uri? url, { + Map? headers, + }) => + (super.noSuchMethod( + Invocation.method( + #read, + [url], + {#headers: headers}, + ), + returnValue: _i3.Future.value(''), + ) as _i3.Future); @override - _i5.Future<_i7.Uint8List> readBytes(Uri? url, - {Map? headers}) => + _i3.Future<_i5.Uint8List> readBytes( + Uri? url, { + Map? headers, + }) => (super.noSuchMethod( - Invocation.method(#readBytes, [url], {#headers: headers}), - returnValue: Future<_i7.Uint8List>.value(_i7.Uint8List(0))) - as _i5.Future<_i7.Uint8List>); + Invocation.method( + #readBytes, + [url], + {#headers: headers}, + ), + returnValue: _i3.Future<_i5.Uint8List>.value(_i5.Uint8List(0)), + ) as _i3.Future<_i5.Uint8List>); @override - _i5.Future<_i3.StreamedResponse> send(_i8.BaseRequest? request) => - (super.noSuchMethod(Invocation.method(#send, [request]), - returnValue: - Future<_i3.StreamedResponse>.value(_FakeStreamedResponse_1())) - as _i5.Future<_i3.StreamedResponse>); + _i3.Future<_i2.StreamedResponse> send(_i2.BaseRequest? request) => + (super.noSuchMethod( + Invocation.method( + #send, + [request], + ), + returnValue: + _i3.Future<_i2.StreamedResponse>.value(_FakeStreamedResponse_1( + this, + Invocation.method( + #send, + [request], + ), + )), + ) as _i3.Future<_i2.StreamedResponse>); @override - void close() => super.noSuchMethod(Invocation.method(#close, []), - returnValueForMissingStub: null); + void close() => super.noSuchMethod( + Invocation.method( + #close, + [], + ), + returnValueForMissingStub: null, + ); }