From 1711913abd79a6a97e2f7813cbf96e3e57c9b892 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Mon, 1 May 2023 15:22:56 -0700 Subject: [PATCH 1/6] Update to latest lints and Dart SDK --- .github/workflows/dart.yml | 54 ++++----- analysis_options.yaml | 15 +-- api_benchmark/analysis_options.yaml | 2 + api_benchmark/lib/benchmarks/get_strings.dart | 2 +- api_benchmark/lib/benchmarks/has_strings.dart | 2 +- api_benchmark/lib/benchmarks/int32_json.dart | 2 +- api_benchmark/lib/benchmarks/int64_json.dart | 2 +- .../lib/benchmarks/repeated_int32_json.dart | 2 +- .../lib/benchmarks/repeated_int64_json.dart | 2 +- .../lib/benchmarks/repeated_string_json.dart | 2 +- api_benchmark/lib/benchmarks/set_strings.dart | 2 +- api_benchmark/lib/benchmarks/string_json.dart | 4 +- api_benchmark/lib/dashboard.dart | 6 +- api_benchmark/lib/dashboard_model.dart | 3 +- api_benchmark/lib/dashboard_view.dart | 2 +- api_benchmark/lib/report.dart | 4 +- api_benchmark/lib/vm.dart | 10 +- api_benchmark/pubspec.yaml | 7 +- benchmarks/pubspec.yaml | 4 +- benchmarks/tool/compile_benchmarks.dart | 2 +- protobuf/CHANGELOG.md | 1 + protobuf/lib/protobuf.dart | 13 +- protobuf/lib/src/protobuf/annotations.dart | 2 +- protobuf/lib/src/protobuf/builder_info.dart | 2 +- protobuf/lib/src/protobuf/coded_buffer.dart | 4 +- .../lib/src/protobuf/coded_buffer_reader.dart | 2 +- .../lib/src/protobuf/coded_buffer_writer.dart | 13 +- protobuf/lib/src/protobuf/consts.dart | 2 +- protobuf/lib/src/protobuf/event_plugin.dart | 2 +- protobuf/lib/src/protobuf/exceptions.dart | 2 +- protobuf/lib/src/protobuf/extension.dart | 2 +- .../lib/src/protobuf/extension_field_set.dart | 2 +- .../lib/src/protobuf/extension_registry.dart | 2 +- protobuf/lib/src/protobuf/field_error.dart | 2 +- protobuf/lib/src/protobuf/field_info.dart | 2 +- protobuf/lib/src/protobuf/field_set.dart | 2 +- protobuf/lib/src/protobuf/field_type.dart | 2 +- .../lib/src/protobuf/generated_message.dart | 2 +- .../lib/src/protobuf/generated_service.dart | 2 +- protobuf/lib/src/protobuf/json.dart | 4 +- .../lib/src/protobuf/mixins/event_mixin.dart | 2 +- protobuf/lib/src/protobuf/pb_list.dart | 2 +- protobuf/lib/src/protobuf/pb_map.dart | 2 +- protobuf/lib/src/protobuf/proto3_json.dart | 6 +- protobuf/lib/src/protobuf/protobuf_enum.dart | 2 +- protobuf/lib/src/protobuf/rpc_client.dart | 2 +- .../lib/src/protobuf/unknown_field_set.dart | 4 +- protobuf/lib/src/protobuf/unpack.dart | 2 +- protobuf/lib/src/protobuf/utils.dart | 2 +- protobuf/lib/src/protobuf/wire_format.dart | 2 +- protobuf/pubspec.yaml | 4 +- protobuf/test/event_test.dart | 4 +- protobuf/test/json_test.dart | 8 +- protobuf/test/json_vm_test.dart | 1 + protobuf/test/list_test.dart | 7 +- protobuf/test/map_mixin_test.dart | 9 +- protobuf/test/message_test.dart | 16 +-- protobuf/test/mock_util.dart | 2 +- protobuf/test/readonly_message_test.dart | 48 ++++---- protoc_plugin/CHANGELOG.md | 2 +- protoc_plugin/analysis_options.yaml | 6 + protoc_plugin/lib/mixins.dart | 2 + protoc_plugin/lib/names.dart | 2 +- protoc_plugin/lib/src/file_generator.dart | 4 +- protoc_plugin/pubspec.yaml | 4 +- protoc_plugin/test/map_test.dart | 2 +- protoc_plugin/test/merge_test.dart | 2 +- protoc_plugin/test/message_test.dart | 114 +++++++++--------- 68 files changed, 231 insertions(+), 226 deletions(-) create mode 100644 protoc_plugin/analysis_options.yaml diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 51604c197..ecd9bad38 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -39,23 +39,23 @@ jobs: - name: mono_repo self validate run: dart pub global run mono_repo generate --validate job_002: - name: "format_analyze; linux; Dart 2.12.0; PKG: protobuf; `dart analyze lib`, `dart analyze test`" + name: "format_analyze; linux; Dart 2.19.0; PKG: protobuf; `dart analyze lib`, `dart analyze test`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.12.0;packages:protobuf;commands:analyze_1-analyze_2" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:protobuf;commands:analyze_1-analyze_2" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:2.12.0;packages:protobuf - os:ubuntu-latest;pub-cache-hosted;sdk:2.12.0 + os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:protobuf + os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: - sdk: "2.12.0" + sdk: "2.19.0" - id: checkout name: Checkout repository uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab @@ -233,23 +233,23 @@ jobs: if: "always() && steps.protoc_plugin_pub_upgrade.conclusion == 'success'" working-directory: protoc_plugin job_007: - name: "run_tests; linux; Dart 2.12.0; PKG: protobuf; `dart test`" + name: "run_tests; linux; Dart 2.19.0; PKG: protobuf; `dart test`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.12.0;packages:protobuf;commands:test_0" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:protobuf;commands:test_0" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:2.12.0;packages:protobuf - os:ubuntu-latest;pub-cache-hosted;sdk:2.12.0 + os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:protobuf + os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: - sdk: "2.12.0" + sdk: "2.19.0" - id: checkout name: Checkout repository uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab @@ -270,23 +270,23 @@ jobs: - job_005 - job_006 job_008: - name: "run_tests; linux; Dart 2.17.0; PKG: protoc_plugin; `./../tool/setup.sh`, `make protos`, `dart test`" + name: "run_tests; linux; Dart 2.19.0; PKG: protoc_plugin; `./../tool/setup.sh`, `make protos`, `dart test`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0;packages:protoc_plugin;commands:command_0-command_3-test_0" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:protoc_plugin;commands:command_0-command_3-test_0" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0;packages:protoc_plugin - os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0 + os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:protoc_plugin + os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: - sdk: "2.17.0" + sdk: "2.19.0" - id: checkout name: Checkout repository uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab @@ -397,23 +397,23 @@ jobs: - job_005 - job_006 job_011: - name: "run_tests; osx; Dart 2.12.0; PKG: protobuf; `dart test`" + name: "run_tests; osx; Dart 2.19.0; PKG: protobuf; `dart test`" runs-on: macos-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 with: path: "~/.pub-cache/hosted" - key: "os:macos-latest;pub-cache-hosted;sdk:2.12.0;packages:protobuf;commands:test_0" + key: "os:macos-latest;pub-cache-hosted;sdk:2.19.0;packages:protobuf;commands:test_0" restore-keys: | - os:macos-latest;pub-cache-hosted;sdk:2.12.0;packages:protobuf - os:macos-latest;pub-cache-hosted;sdk:2.12.0 + os:macos-latest;pub-cache-hosted;sdk:2.19.0;packages:protobuf + os:macos-latest;pub-cache-hosted;sdk:2.19.0 os:macos-latest;pub-cache-hosted os:macos-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: - sdk: "2.12.0" + sdk: "2.19.0" - id: checkout name: Checkout repository uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab @@ -471,13 +471,13 @@ jobs: - job_005 - job_006 job_013: - name: "run_tests; windows; Dart 2.12.0; PKG: protobuf; `dart test`" + name: "run_tests; windows; Dart 2.19.0; PKG: protobuf; `dart test`" runs-on: windows-latest steps: - name: Setup Dart SDK uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: - sdk: "2.12.0" + sdk: "2.19.0" - id: checkout name: Checkout repository uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab @@ -525,23 +525,23 @@ jobs: - job_005 - job_006 job_015: - name: "run_legacy_tests; linux; Dart 2.17.0; PKG: protoc_plugin; `./../tool/setup.sh`, `make protos`, `dart test legacy_tests/generated_message_test.dart`" + name: "run_legacy_tests; linux; Dart 2.19.0; PKG: protoc_plugin; `./../tool/setup.sh`, `make protos`, `dart test legacy_tests/generated_message_test.dart`" runs-on: ubuntu-latest steps: - name: Cache Pub hosted dependencies uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 with: path: "~/.pub-cache/hosted" - key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0;packages:protoc_plugin;commands:command_0-command_3-test_1" + key: "os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:protoc_plugin;commands:command_0-command_3-test_1" restore-keys: | - os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0;packages:protoc_plugin - os:ubuntu-latest;pub-cache-hosted;sdk:2.17.0 + os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0;packages:protoc_plugin + os:ubuntu-latest;pub-cache-hosted;sdk:2.19.0 os:ubuntu-latest;pub-cache-hosted os:ubuntu-latest - name: Setup Dart SDK uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f with: - sdk: "2.17.0" + sdk: "2.19.0" - id: checkout name: Checkout repository uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab diff --git a/analysis_options.yaml b/analysis_options.yaml index f5a590e73..0913b1151 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,22 +1,13 @@ -include: package:lints/recommended.yaml +include: package:dart_flutter_team_lints/analysis_options.yaml analyzer: language: strict-casts: true + errors: + lines_longer_than_80_chars: ignore linter: rules: - - always_declare_return_types - avoid_bool_literals_in_conditional_expressions - - camel_case_types - comment_references - - directives_ordering - - no_leading_underscores_for_local_identifiers - - omit_local_variable_types - prefer_relative_imports - - prefer_single_quotes - - prefer_spread_collections - - sort_pub_dependencies - - throw_in_finally - - type_annotate_public_apis - - unawaited_futures diff --git a/api_benchmark/analysis_options.yaml b/api_benchmark/analysis_options.yaml index 06eee2aec..7e489e016 100644 --- a/api_benchmark/analysis_options.yaml +++ b/api_benchmark/analysis_options.yaml @@ -3,3 +3,5 @@ include: ../analysis_options.yaml analyzer: language: strict-casts: false + errors: + only_throw_errors: ignore diff --git a/api_benchmark/lib/benchmarks/get_strings.dart b/api_benchmark/lib/benchmarks/get_strings.dart index 40b29b35e..fba311e92 100644 --- a/api_benchmark/lib/benchmarks/get_strings.dart +++ b/api_benchmark/lib/benchmarks/get_strings.dart @@ -4,7 +4,7 @@ import '../benchmark.dart'; import '../generated/benchmark.pb.dart' - show BenchmarkID, Request, Params, Sample; + show BenchmarkID, Params, Request, Sample; import '../generated/string_grid.pb.dart' as pb; /// A benchmark that accesses each value in a grid of string fields. diff --git a/api_benchmark/lib/benchmarks/has_strings.dart b/api_benchmark/lib/benchmarks/has_strings.dart index 1de3c7272..eb1a8612e 100644 --- a/api_benchmark/lib/benchmarks/has_strings.dart +++ b/api_benchmark/lib/benchmarks/has_strings.dart @@ -4,7 +4,7 @@ import '../benchmark.dart'; import '../generated/benchmark.pb.dart' - show BenchmarkID, Request, Params, Sample; + show BenchmarkID, Params, Request, Sample; import '../generated/string_grid.pb.dart' as pb; /// A benchmark that checks the existence of each item in a grid of strings. diff --git a/api_benchmark/lib/benchmarks/int32_json.dart b/api_benchmark/lib/benchmarks/int32_json.dart index 3a7857da1..f17d37c8d 100644 --- a/api_benchmark/lib/benchmarks/int32_json.dart +++ b/api_benchmark/lib/benchmarks/int32_json.dart @@ -4,7 +4,7 @@ import '../benchmark.dart'; import '../generated/benchmark.pb.dart' - show BenchmarkID, Request, Params, Sample; + show BenchmarkID, Params, Request, Sample; import '../generated/int32grid.pb.dart' as pb; /// A benchmark that deserializes a grid of int fields. diff --git a/api_benchmark/lib/benchmarks/int64_json.dart b/api_benchmark/lib/benchmarks/int64_json.dart index 1fe869df2..370fadb61 100644 --- a/api_benchmark/lib/benchmarks/int64_json.dart +++ b/api_benchmark/lib/benchmarks/int64_json.dart @@ -6,7 +6,7 @@ import 'package:fixnum/fixnum.dart' show Int64; import '../benchmark.dart'; import '../generated/benchmark.pb.dart' - show BenchmarkID, Request, Params, Sample; + show BenchmarkID, Params, Request, Sample; import '../generated/int64grid.pb.dart' as pb; /// A benchmark that deserializes a grid of int fields. diff --git a/api_benchmark/lib/benchmarks/repeated_int32_json.dart b/api_benchmark/lib/benchmarks/repeated_int32_json.dart index 70e0bf905..a3586342f 100644 --- a/api_benchmark/lib/benchmarks/repeated_int32_json.dart +++ b/api_benchmark/lib/benchmarks/repeated_int32_json.dart @@ -4,7 +4,7 @@ import '../benchmark.dart'; import '../generated/benchmark.pb.dart' - show BenchmarkID, Request, Params, Sample; + show BenchmarkID, Params, Request, Sample; import '../generated/int32grid.pb.dart' as pb; /// A benchmark that deserializes a grid of repeated ints. diff --git a/api_benchmark/lib/benchmarks/repeated_int64_json.dart b/api_benchmark/lib/benchmarks/repeated_int64_json.dart index 2b80ea882..c6bfb0c8d 100644 --- a/api_benchmark/lib/benchmarks/repeated_int64_json.dart +++ b/api_benchmark/lib/benchmarks/repeated_int64_json.dart @@ -6,7 +6,7 @@ import 'package:fixnum/fixnum.dart'; import '../benchmark.dart'; import '../generated/benchmark.pb.dart' - show BenchmarkID, Request, Params, Sample; + show BenchmarkID, Params, Request, Sample; import '../generated/int64grid.pb.dart' as pb; /// A benchmark that deserializes a grid of repeated ints. diff --git a/api_benchmark/lib/benchmarks/repeated_string_json.dart b/api_benchmark/lib/benchmarks/repeated_string_json.dart index c67dd7955..aa22cc8aa 100644 --- a/api_benchmark/lib/benchmarks/repeated_string_json.dart +++ b/api_benchmark/lib/benchmarks/repeated_string_json.dart @@ -4,7 +4,7 @@ import '../benchmark.dart'; import '../generated/benchmark.pb.dart' - show BenchmarkID, Request, Params, Sample; + show BenchmarkID, Params, Request, Sample; import '../generated/string_grid.pb.dart' as pb; /// A benchmark that deserializes a grid of string fields. diff --git a/api_benchmark/lib/benchmarks/set_strings.dart b/api_benchmark/lib/benchmarks/set_strings.dart index 73bd07104..8515e9291 100644 --- a/api_benchmark/lib/benchmarks/set_strings.dart +++ b/api_benchmark/lib/benchmarks/set_strings.dart @@ -4,7 +4,7 @@ import '../benchmark.dart'; import '../generated/benchmark.pb.dart' - show BenchmarkID, Request, Params, Sample; + show BenchmarkID, Params, Request, Sample; import '../generated/string_grid.pb.dart' as pb; /// A benchmark that sets each value in a grid of string fields. diff --git a/api_benchmark/lib/benchmarks/string_json.dart b/api_benchmark/lib/benchmarks/string_json.dart index cc5acd290..82dea4fcb 100644 --- a/api_benchmark/lib/benchmarks/string_json.dart +++ b/api_benchmark/lib/benchmarks/string_json.dart @@ -4,7 +4,7 @@ import '../benchmark.dart'; import '../generated/benchmark.pb.dart' - show BenchmarkID, Request, Params, Sample; + show BenchmarkID, Params, Request, Sample; import '../generated/string_grid.pb.dart' as pb; /// A benchmark that deserializes a grid of string fields. @@ -66,7 +66,7 @@ class StringBenchmark extends Benchmark { @override void run() { var grid = pb.Grid10.fromJson(json); - var actual = grid.lines[height - 1].getField(lastFieldTag!); + var actual = grid.lines[height - 1].getField(lastFieldTag!) as String; if (actual.length != stringSize) throw 'failed; got $actual'; } diff --git a/api_benchmark/lib/dashboard.dart b/api_benchmark/lib/dashboard.dart index bb9881559..3f9a49195 100644 --- a/api_benchmark/lib/dashboard.dart +++ b/api_benchmark/lib/dashboard.dart @@ -5,14 +5,14 @@ import 'dart:async' show Future; import 'dart:convert'; import 'dart:html'; -import 'dart:js' show context, JsObject; +import 'dart:js' show JsObject, context; import 'benchmark.dart' show Profiler; -import 'dashboard_model.dart' show DashboardModel, Table, SelectEvent; +import 'dashboard_model.dart' show DashboardModel, SelectEvent, Table; import 'dashboard_view.dart' show DashboardView; import 'data_index.dart' as data; import 'generated/benchmark.pb.dart' as pb; -import 'report.dart' show createPlatform, createPackages; +import 'report.dart' show createPackages, createPlatform; import 'suite.dart' show runSuite; /// Displays a dashboard that can be used to run benchmarks. diff --git a/api_benchmark/lib/dashboard_model.dart b/api_benchmark/lib/dashboard_model.dart index c951f4fd3..0d236db32 100644 --- a/api_benchmark/lib/dashboard_model.dart +++ b/api_benchmark/lib/dashboard_model.dart @@ -41,7 +41,8 @@ class Table { Table._raw(suite, null, null, Set<pb.Request>.from(suite.requests)); Table._raw(this.suite, this.baseline, this.report, this.selections) { - var it = report == null ? [].iterator : report!.responses.iterator; + var it = + report == null ? <pb.Response>[].iterator : report!.responses.iterator; for (var r in suite.requests) { var b = createBenchmark(r); pb.Sample? baseline; diff --git a/api_benchmark/lib/dashboard_view.dart b/api_benchmark/lib/dashboard_view.dart index 270601ff5..bd04410e0 100644 --- a/api_benchmark/lib/dashboard_view.dart +++ b/api_benchmark/lib/dashboard_view.dart @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'dart:async' show Stream, StreamController, EventSink; +import 'dart:async' show EventSink, Stream, StreamController; import 'dart:html'; import 'dashboard_model.dart'; diff --git a/api_benchmark/lib/report.dart b/api_benchmark/lib/report.dart index cd516b9a5..36d10a1ff 100644 --- a/api_benchmark/lib/report.dart +++ b/api_benchmark/lib/report.dart @@ -99,7 +99,7 @@ String encodeReport(pb.Report report) { } String _stringifyMap(StringBuffer out, Map json, String indent) { - var childIndent = indent + ' '; + var childIndent = '$indent '; out.writeln('{'); var first = true; for (var key in json.keys) { @@ -124,7 +124,7 @@ String _stringifyMap(StringBuffer out, Map json, String indent) { } void _stringifyList(StringBuffer out, List json, String indent) { - var childIndent = indent + ' '; + var childIndent = '$indent '; out.write('[\n'); var first = true; for (var item in json) { diff --git a/api_benchmark/lib/vm.dart b/api_benchmark/lib/vm.dart index 7d745a225..170c435c0 100644 --- a/api_benchmark/lib/vm.dart +++ b/api_benchmark/lib/vm.dart @@ -3,14 +3,14 @@ // BSD-style license that can be found in the LICENSE file. import 'dart:async' show Future; -import 'dart:io' show File, Directory, Link, Platform, stdout; +import 'dart:io' show Directory, File, Link, Platform, stdout; import 'benchmarks/index.dart' show createBenchmark; import 'data_index.dart' - show latestVMReportName, pubspecYamlName, pubspecLockName, hostfileName; + show hostfileName, latestVMReportName, pubspecLockName, pubspecYamlName; import 'generated/benchmark.pb.dart' as pb; import 'report.dart' - show createPlatform, createPackages, encodeReport, findUpdatedResponse; + show createPackages, createPlatform, encodeReport, findUpdatedResponse; import 'suite.dart' show runSuite; /// Runs a benchmark suite. @@ -68,8 +68,8 @@ Future<pb.Env> _loadEnv() async { ..osType = _osType ..dartVersion = Platform.version; - var pubspec = await (File(pubspecYaml.path).readAsString()); - var lock = await (File(pubspecLock.path).readAsString()); + var pubspec = await File(pubspecYaml.path).readAsString(); + var lock = await File(pubspecLock.path).readAsString(); return pb.Env() ..script = _script diff --git a/api_benchmark/pubspec.yaml b/api_benchmark/pubspec.yaml index 1c00b6457..1ec86e37f 100644 --- a/api_benchmark/pubspec.yaml +++ b/api_benchmark/pubspec.yaml @@ -9,20 +9,21 @@ description: Benchmarking a number of different api calls. publish_to: none environment: - sdk: '>=2.12.0 <3.0.0' + sdk: '>=2.19.0 <3.0.0' dependencies: + fixnum: any protobuf: any + yaml: ^3.0.0 dev_dependencies: build: ^2.0.0 build_runner: ^2.0.6 build_web_compilers: ^3.0.0 + dart_flutter_team_lints: ^1.0.0 glob: ^2.0.0 - lints: ^1.0.0 protoc_plugin: path: "../protoc_plugin" - yaml: ^3.0.0 dependency_overrides: protobuf: diff --git a/benchmarks/pubspec.yaml b/benchmarks/pubspec.yaml index 7aa6f562c..68b002584 100644 --- a/benchmarks/pubspec.yaml +++ b/benchmarks/pubspec.yaml @@ -7,7 +7,7 @@ description: Benchmarks various protobuf functions publish_to: none environment: - sdk: '>=2.18.0 <3.0.0' + sdk: '>=2.19.0 <3.0.0' dependencies: # NB. When bumping benchmark_harness check if `benchmark_base.BenchmarkBase` @@ -19,7 +19,7 @@ dependencies: dev_dependencies: args: ^2.3.1 - lints: ^1.0.0 + dart_flutter_team_lints: ^1.0.0 path: ^1.8.2 pool: ^1.5.1 protoc_plugin: diff --git a/benchmarks/tool/compile_benchmarks.dart b/benchmarks/tool/compile_benchmarks.dart index 5bcc5d283..e22203284 100755 --- a/benchmarks/tool/compile_benchmarks.dart +++ b/benchmarks/tool/compile_benchmarks.dart @@ -1,6 +1,6 @@ #!/usr/bin/env dart -import 'dart:io' show exit, Platform, Process, Directory, ProcessResult; +import 'dart:io' show Directory, Platform, Process, ProcessResult, exit; import 'package:args/args.dart' show ArgParser; import 'package:path/path.dart' as path; diff --git a/protobuf/CHANGELOG.md b/protobuf/CHANGELOG.md index 223603344..49412301d 100644 --- a/protobuf/CHANGELOG.md +++ b/protobuf/CHANGELOG.md @@ -1,5 +1,6 @@ ## 3.0.0-dev +* Require Dart `2.19`. * Remove `ReadonlyMessageMixin` ([#183], [#644]) * Remove `frozenMessageModificationHandler` ([#175], [#643]) * Remove `PbListBase` and `FrozenPbList` types. All proto repeated fields now diff --git a/protobuf/lib/protobuf.dart b/protobuf/lib/protobuf.dart index b4d4ca996..5f73a14ed 100644 --- a/protobuf/lib/protobuf.dart +++ b/protobuf/lib/protobuf.dart @@ -5,13 +5,13 @@ /// Runtime library for Dart implementation of [protobufs][1]. /// /// [1]: https://developers.google.com/protocol-buffers -library protobuf; +library; import 'dart:collection' show ListBase, MapBase; import 'dart:convert' - show base64Decode, base64Encode, jsonEncode, jsonDecode, Utf8Codec; + show Utf8Codec, base64Decode, base64Encode, jsonDecode, jsonEncode; import 'dart:math' as math; -import 'dart:typed_data' show TypedData, Uint8List, ByteData, Endian; +import 'dart:typed_data' show ByteData, Endian, TypedData, Uint8List; import 'package:fixnum/fixnum.dart' show Int64; import 'package:meta/meta.dart' show UseResult; @@ -19,14 +19,15 @@ import 'package:meta/meta.dart' show UseResult; import 'src/protobuf/json_parsing_context.dart'; import 'src/protobuf/permissive_compare.dart'; import 'src/protobuf/type_registry.dart'; + export 'src/protobuf/type_registry.dart' show TypeRegistry; part 'src/protobuf/annotations.dart'; +part 'src/protobuf/builder_info.dart'; part 'src/protobuf/coded_buffer.dart'; part 'src/protobuf/coded_buffer_reader.dart'; part 'src/protobuf/coded_buffer_writer.dart'; part 'src/protobuf/consts.dart'; -part 'src/protobuf/builder_info.dart'; part 'src/protobuf/event_plugin.dart'; part 'src/protobuf/exceptions.dart'; part 'src/protobuf/extension.dart'; @@ -41,12 +42,12 @@ part 'src/protobuf/generated_service.dart'; part 'src/protobuf/json.dart'; part 'src/protobuf/pb_list.dart'; part 'src/protobuf/pb_map.dart'; -part 'src/protobuf/protobuf_enum.dart'; part 'src/protobuf/proto3_json.dart'; +part 'src/protobuf/protobuf_enum.dart'; part 'src/protobuf/rpc_client.dart'; part 'src/protobuf/unknown_field_set.dart'; -part 'src/protobuf/utils.dart'; part 'src/protobuf/unpack.dart'; +part 'src/protobuf/utils.dart'; part 'src/protobuf/wire_format.dart'; // TODO(sra): Use Int64.parse() when available - see http://dartbug.com/21915. diff --git a/protobuf/lib/src/protobuf/annotations.dart b/protobuf/lib/src/protobuf/annotations.dart index 193f434ae..9ec997b66 100644 --- a/protobuf/lib/src/protobuf/annotations.dart +++ b/protobuf/lib/src/protobuf/annotations.dart @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -part of protobuf; +part of '../../protobuf.dart'; /// Annotation for marking accessors that belong together. class TagNumber { diff --git a/protobuf/lib/src/protobuf/builder_info.dart b/protobuf/lib/src/protobuf/builder_info.dart index f122733a5..e2baa50ab 100644 --- a/protobuf/lib/src/protobuf/builder_info.dart +++ b/protobuf/lib/src/protobuf/builder_info.dart @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -part of protobuf; +part of '../../protobuf.dart'; /// Per-message type setup. class BuilderInfo { diff --git a/protobuf/lib/src/protobuf/coded_buffer.dart b/protobuf/lib/src/protobuf/coded_buffer.dart index 76d95edc6..ca611737b 100644 --- a/protobuf/lib/src/protobuf/coded_buffer.dart +++ b/protobuf/lib/src/protobuf/coded_buffer.dart @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -part of protobuf; +part of '../../protobuf.dart'; void _writeToCodedBufferWriter(_FieldSet fs, CodedBufferWriter out) { // Sorting by tag number isn't required, but it sometimes enables @@ -196,7 +196,7 @@ void _mergeFromCodedBufferReader(BuilderInfo meta, _FieldSet fs, ._mergeEntry(mapEntryMeta, input, registry); break; default: - throw 'Unknown field type $fieldType'; + throw UnsupportedError('Unknown field type $fieldType'); } } } diff --git a/protobuf/lib/src/protobuf/coded_buffer_reader.dart b/protobuf/lib/src/protobuf/coded_buffer_reader.dart index a296b009c..2f6158fe9 100644 --- a/protobuf/lib/src/protobuf/coded_buffer_reader.dart +++ b/protobuf/lib/src/protobuf/coded_buffer_reader.dart @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -part of protobuf; +part of '../../protobuf.dart'; /// Reader used for converting binary-encoded protobufs into /// [GeneratedMessage]s. diff --git a/protobuf/lib/src/protobuf/coded_buffer_writer.dart b/protobuf/lib/src/protobuf/coded_buffer_writer.dart index a778b71fb..ffb1e820f 100644 --- a/protobuf/lib/src/protobuf/coded_buffer_writer.dart +++ b/protobuf/lib/src/protobuf/coded_buffer_writer.dart @@ -4,7 +4,7 @@ // ignore_for_file: constant_identifier_names -part of protobuf; +part of '../../protobuf.dart'; /// Writer used for converting [GeneratedMessage]s into binary /// representation. @@ -268,7 +268,7 @@ class CodedBufferWriter { value >>= 7; } _outputChunk![i++] = value; - _bytesTotal += (i - _bytesInChunk); + _bytesTotal += i - _bytesInChunk; _bytesInChunk = i; } @@ -283,7 +283,7 @@ class CodedBufferWriter { hi >>= 7; } _outputChunk![i++] = lo; - _bytesTotal += (i - _bytesInChunk); + _bytesTotal += i - _bytesInChunk; _bytesInChunk = i; } @@ -338,10 +338,10 @@ class CodedBufferWriter { break; case PbFieldType._BYTES_BIT: _writeBytesNoTag( - value is TypedData ? value : Uint8List.fromList(value)); + value is Uint8List ? value : Uint8List.fromList(value)); break; case PbFieldType._STRING_BIT: - _writeBytesNoTag(_utf8.encode(value)); + _writeBytesNoTag(_utf8.encoder.convert(value)); break; case PbFieldType._DOUBLE_BIT: _writeDouble(value); @@ -355,6 +355,7 @@ class CodedBufferWriter { break; case PbFieldType._GROUP_BIT: // value is UnknownFieldSet or GeneratedMessage + // ignore: avoid_dynamic_calls value.writeToCodedBufferWriter(this); break; case PbFieldType._INT32_BIT: @@ -396,7 +397,7 @@ class CodedBufferWriter { } } - void _writeBytesNoTag(dynamic value) { + void _writeBytesNoTag(Uint8List value) { writeInt32NoTag(value.length); writeRawBytes(value); } diff --git a/protobuf/lib/src/protobuf/consts.dart b/protobuf/lib/src/protobuf/consts.dart index fb09aca0c..227188ac7 100644 --- a/protobuf/lib/src/protobuf/consts.dart +++ b/protobuf/lib/src/protobuf/consts.dart @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -part of protobuf; +part of '../../protobuf.dart'; /// Constant string value of `double.infinity.toString()` and the infinity /// value recognized by `double.parse(..)`. diff --git a/protobuf/lib/src/protobuf/event_plugin.dart b/protobuf/lib/src/protobuf/event_plugin.dart index b4b701924..8e752d380 100644 --- a/protobuf/lib/src/protobuf/event_plugin.dart +++ b/protobuf/lib/src/protobuf/event_plugin.dart @@ -1,4 +1,4 @@ -part of protobuf; +part of '../../protobuf.dart'; /// An `EventPlugin` receives callbacks when the fields of a [GeneratedMessage] /// change. diff --git a/protobuf/lib/src/protobuf/exceptions.dart b/protobuf/lib/src/protobuf/exceptions.dart index 838dbe78c..ae629f5b7 100644 --- a/protobuf/lib/src/protobuf/exceptions.dart +++ b/protobuf/lib/src/protobuf/exceptions.dart @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -part of protobuf; +part of '../../protobuf.dart'; const _truncatedMessageText = ''' While parsing a protocol message, the input ended unexpectedly diff --git a/protobuf/lib/src/protobuf/extension.dart b/protobuf/lib/src/protobuf/extension.dart index 93485dd2e..bf31fbfff 100644 --- a/protobuf/lib/src/protobuf/extension.dart +++ b/protobuf/lib/src/protobuf/extension.dart @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -part of protobuf; +part of '../../protobuf.dart'; /// An object representing an extension field. class Extension<T> extends FieldInfo<T> { diff --git a/protobuf/lib/src/protobuf/extension_field_set.dart b/protobuf/lib/src/protobuf/extension_field_set.dart index ce97c0de1..ef1753afe 100644 --- a/protobuf/lib/src/protobuf/extension_field_set.dart +++ b/protobuf/lib/src/protobuf/extension_field_set.dart @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -part of protobuf; +part of '../../protobuf.dart'; class _ExtensionFieldSet { final _FieldSet _parent; diff --git a/protobuf/lib/src/protobuf/extension_registry.dart b/protobuf/lib/src/protobuf/extension_registry.dart index 9c8f9d126..83f64eeed 100644 --- a/protobuf/lib/src/protobuf/extension_registry.dart +++ b/protobuf/lib/src/protobuf/extension_registry.dart @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -part of protobuf; +part of '../../protobuf.dart'; /// A collection of [Extension] objects, organized by the message type they /// extend. diff --git a/protobuf/lib/src/protobuf/field_error.dart b/protobuf/lib/src/protobuf/field_error.dart index a9ddaccd4..79e07c71c 100644 --- a/protobuf/lib/src/protobuf/field_error.dart +++ b/protobuf/lib/src/protobuf/field_error.dart @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -part of protobuf; +part of '../../protobuf.dart'; /// Returns the error message for an invalid field value, /// or null if it's valid. diff --git a/protobuf/lib/src/protobuf/field_info.dart b/protobuf/lib/src/protobuf/field_info.dart index 3eb325234..a968f76a0 100644 --- a/protobuf/lib/src/protobuf/field_info.dart +++ b/protobuf/lib/src/protobuf/field_info.dart @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -part of protobuf; +part of '../../protobuf.dart'; /// An object representing a protobuf message field. class FieldInfo<T> { diff --git a/protobuf/lib/src/protobuf/field_set.dart b/protobuf/lib/src/protobuf/field_set.dart index d4bf29ab5..d204eb3a7 100644 --- a/protobuf/lib/src/protobuf/field_set.dart +++ b/protobuf/lib/src/protobuf/field_set.dart @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -part of protobuf; +part of '../../protobuf.dart'; void _throwFrozenMessageModificationError(String messageName, [String? methodName]) { diff --git a/protobuf/lib/src/protobuf/field_type.dart b/protobuf/lib/src/protobuf/field_type.dart index ae9f3557a..cb6a1a47f 100644 --- a/protobuf/lib/src/protobuf/field_type.dart +++ b/protobuf/lib/src/protobuf/field_type.dart @@ -3,7 +3,7 @@ // BSD-style license that can be found in the LICENSE file. // ignore_for_file: constant_identifier_names,non_constant_identifier_names -part of protobuf; +part of '../../protobuf.dart'; bool _isRepeated(int fieldType) => (fieldType & PbFieldType._REPEATED_BIT) != 0; diff --git a/protobuf/lib/src/protobuf/generated_message.dart b/protobuf/lib/src/protobuf/generated_message.dart index d30f9de9c..15467b5c6 100644 --- a/protobuf/lib/src/protobuf/generated_message.dart +++ b/protobuf/lib/src/protobuf/generated_message.dart @@ -4,7 +4,7 @@ // ignore_for_file: non_constant_identifier_names -part of protobuf; +part of '../../protobuf.dart'; /// Type of an empty message builder. typedef CreateBuilderFunc = GeneratedMessage Function(); diff --git a/protobuf/lib/src/protobuf/generated_service.dart b/protobuf/lib/src/protobuf/generated_service.dart index 13b5882fc..d3b3b0134 100644 --- a/protobuf/lib/src/protobuf/generated_service.dart +++ b/protobuf/lib/src/protobuf/generated_service.dart @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -part of protobuf; +part of '../../protobuf.dart'; /// Server side context. class ServerContext { diff --git a/protobuf/lib/src/protobuf/json.dart b/protobuf/lib/src/protobuf/json.dart index 2ed29621a..bd9cdf369 100644 --- a/protobuf/lib/src/protobuf/json.dart +++ b/protobuf/lib/src/protobuf/json.dart @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -part of protobuf; +part of '../../protobuf.dart'; Map<String, dynamic> _writeToJsonMap(_FieldSet fs) { dynamic convertToMap(dynamic fieldValue, int fieldType) { @@ -54,7 +54,7 @@ Map<String, dynamic> _writeToJsonMap(_FieldSet fs) { final GeneratedMessage msg = fieldValue; return msg.writeToJsonMap(); default: - throw 'Unknown type $fieldType'; + throw UnsupportedError('Unknown type $fieldType'); } } diff --git a/protobuf/lib/src/protobuf/mixins/event_mixin.dart b/protobuf/lib/src/protobuf/mixins/event_mixin.dart index d5beb6c0c..c8ef58662 100644 --- a/protobuf/lib/src/protobuf/mixins/event_mixin.dart +++ b/protobuf/lib/src/protobuf/mixins/event_mixin.dart @@ -5,7 +5,7 @@ import 'dart:async' show StreamController, scheduleMicrotask; import 'dart:collection' show UnmodifiableListView; -import '../../../protobuf.dart' show GeneratedMessage, FieldInfo, EventPlugin; +import '../../../protobuf.dart' show EventPlugin, FieldInfo, GeneratedMessage; /// Provides a stream of changes to fields in a [GeneratedMessage]. /// (Experimental.) diff --git a/protobuf/lib/src/protobuf/pb_list.dart b/protobuf/lib/src/protobuf/pb_list.dart index a67827ed5..e9c39c445 100644 --- a/protobuf/lib/src/protobuf/pb_list.dart +++ b/protobuf/lib/src/protobuf/pb_list.dart @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -part of protobuf; +part of '../../protobuf.dart'; /// Type of a function that checks items added to a `PbList`. /// diff --git a/protobuf/lib/src/protobuf/pb_map.dart b/protobuf/lib/src/protobuf/pb_map.dart index 4ec9b3f53..d98397ddc 100644 --- a/protobuf/lib/src/protobuf/pb_map.dart +++ b/protobuf/lib/src/protobuf/pb_map.dart @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -part of protobuf; +part of '../../protobuf.dart'; /// A [MapBase] implementation used for protobuf `map` fields. class PbMap<K, V> extends MapBase<K, V> { diff --git a/protobuf/lib/src/protobuf/proto3_json.dart b/protobuf/lib/src/protobuf/proto3_json.dart index b919c2715..5800e659b 100644 --- a/protobuf/lib/src/protobuf/proto3_json.dart +++ b/protobuf/lib/src/protobuf/proto3_json.dart @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -part of protobuf; +part of '../../protobuf.dart'; Object? _writeToProto3Json(_FieldSet fs, TypeRegistry typeRegistry) { String? convertToMapKey(dynamic key, int keyType) { @@ -67,8 +67,8 @@ Object? _writeToProto3Json(_FieldSet fs, TypeRegistry typeRegistry) { if (value.isInfinite) { return value.isNegative ? _negativeInfinity : _infinity; } - if (fieldValue.toInt() == fieldValue) { - return fieldValue.toInt(); + if (value.toInt() == fieldValue) { + return value.toInt(); } return value; case PbFieldType._UINT64_BIT: diff --git a/protobuf/lib/src/protobuf/protobuf_enum.dart b/protobuf/lib/src/protobuf/protobuf_enum.dart index edeb35450..c3d316e60 100644 --- a/protobuf/lib/src/protobuf/protobuf_enum.dart +++ b/protobuf/lib/src/protobuf/protobuf_enum.dart @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -part of protobuf; +part of '../../protobuf.dart'; /// A base class for all proto enum types. /// diff --git a/protobuf/lib/src/protobuf/rpc_client.dart b/protobuf/lib/src/protobuf/rpc_client.dart index 9c5f24418..776eb01d1 100644 --- a/protobuf/lib/src/protobuf/rpc_client.dart +++ b/protobuf/lib/src/protobuf/rpc_client.dart @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -part of protobuf; +part of '../../protobuf.dart'; /// Client side context for [RpcClient]s. class ClientContext { diff --git a/protobuf/lib/src/protobuf/unknown_field_set.dart b/protobuf/lib/src/protobuf/unknown_field_set.dart index 5a6f268eb..83914fe6d 100644 --- a/protobuf/lib/src/protobuf/unknown_field_set.dart +++ b/protobuf/lib/src/protobuf/unknown_field_set.dart @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -part of protobuf; +part of '../../protobuf.dart'; /// A set of unknown fields in a [GeneratedMessage]. class UnknownFieldSet { @@ -132,7 +132,7 @@ class UnknownFieldSet { UnknownFieldSetField _getField(int number) { _checkFieldNumber(number); if (_isReadOnly) assert(_fields.containsKey(number)); - return _fields.putIfAbsent(number, () => UnknownFieldSetField()); + return _fields.putIfAbsent(number, UnknownFieldSetField.new); } @override diff --git a/protobuf/lib/src/protobuf/unpack.dart b/protobuf/lib/src/protobuf/unpack.dart index b920e98c6..5b798da7a 100644 --- a/protobuf/lib/src/protobuf/unpack.dart +++ b/protobuf/lib/src/protobuf/unpack.dart @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -part of protobuf; +part of '../../protobuf.dart'; /// Unpacks the message in [value] into [instance]. /// diff --git a/protobuf/lib/src/protobuf/utils.dart b/protobuf/lib/src/protobuf/utils.dart index 830e73df3..6e4df1da1 100644 --- a/protobuf/lib/src/protobuf/utils.dart +++ b/protobuf/lib/src/protobuf/utils.dart @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -part of protobuf; +part of '../../protobuf.dart'; // TODO(antonm): reconsider later if PbList should take care of equality. bool _deepEquals(lhs, rhs) { diff --git a/protobuf/lib/src/protobuf/wire_format.dart b/protobuf/lib/src/protobuf/wire_format.dart index b4784d244..a255c8176 100644 --- a/protobuf/lib/src/protobuf/wire_format.dart +++ b/protobuf/lib/src/protobuf/wire_format.dart @@ -4,7 +4,7 @@ // ignore_for_file: constant_identifier_names -part of protobuf; +part of '../../protobuf.dart'; const int _TAG_TYPE_BITS = 3; const int _TAG_TYPE_MASK = (1 << _TAG_TYPE_BITS) - 1; diff --git a/protobuf/pubspec.yaml b/protobuf/pubspec.yaml index 80f6032af..748914306 100644 --- a/protobuf/pubspec.yaml +++ b/protobuf/pubspec.yaml @@ -6,7 +6,7 @@ description: >- repository: https://github.com/google/protobuf.dart/tree/master/protobuf environment: - sdk: '>=2.12.0 <3.0.0' + sdk: '>=2.19.0 <3.0.0' dependencies: collection: ^1.15.0 @@ -14,6 +14,6 @@ dependencies: meta: ^1.7.0 dev_dependencies: - lints: ^1.0.0 + dart_flutter_team_lints: ^1.0.0 matcher: ^0.12.11 test: ^1.16.0 diff --git a/protobuf/test/event_test.dart b/protobuf/test/event_test.dart index c38e7910f..5ef7d2fe8 100644 --- a/protobuf/test/event_test.dart +++ b/protobuf/test/event_test.dart @@ -7,14 +7,14 @@ import 'package:protobuf/protobuf.dart'; import 'package:protobuf/src/protobuf/mixins/event_mixin.dart' show PbEventMixin, PbFieldChange; -import 'package:test/test.dart' show test, expect; +import 'package:test/test.dart' show expect, test; import 'mock_util.dart' show MockMessage, mockInfo; class Rec extends MockMessage with PbEventMixin { @override BuilderInfo get info_ => _info; - static final _info = mockInfo('Rec', () => Rec()); + static final _info = mockInfo('Rec', Rec.new); @override Rec createEmptyInstance() => Rec(); } diff --git a/protobuf/test/json_test.dart b/protobuf/test/json_test.dart index 8e7ae26d6..76478a329 100644 --- a/protobuf/test/json_test.dart +++ b/protobuf/test/json_test.dart @@ -34,8 +34,8 @@ void main() { () => example..mergeFromProto3Json({'enm': 'c'}), throwsA(allOf( isFormatException, - predicate( - (dynamic e) => e.message.contains('Unknown enum value'))))); + predicate((FormatException e) => + e.message.contains('Unknown enum value'))))); // `example` hasn't changed. expect(example.hasEnm, isTrue); expect(example.enm.name, equals('b')); @@ -55,8 +55,8 @@ void main() { () => example..mergeFromProto3Json({'enm': 3}), throwsA(allOf( isFormatException, - predicate( - (dynamic e) => e.message.contains('Unknown enum value'))))); + predicate((FormatException e) => + e.message.contains('Unknown enum value'))))); // `example` hasn't changed. expect(example.hasEnm, isTrue); expect(example.enm.name, equals('b')); diff --git a/protobuf/test/json_vm_test.dart b/protobuf/test/json_vm_test.dart index 09538f165..bab4bd37a 100644 --- a/protobuf/test/json_vm_test.dart +++ b/protobuf/test/json_vm_test.dart @@ -7,6 +7,7 @@ // These tests will be skipped on js, as the dart2js platform // does not support 64-bit ints. @TestOn('!js') +library; import 'package:fixnum/fixnum.dart' show Int64; import 'package:test/test.dart'; diff --git a/protobuf/test/list_test.dart b/protobuf/test/list_test.dart index ce1fd232b..ef2ca2deb 100644 --- a/protobuf/test/list_test.dart +++ b/protobuf/test/list_test.dart @@ -35,7 +35,7 @@ void main() { expect(lb1.lastIndexOf(99), 5); - expect(lb1.firstWhere((e) => e % 2 == 0), 0); + expect(lb1.firstWhere((e) => e.isEven), 0); expect(lb1.last, 99); var last = lb1.removeLast(); @@ -48,7 +48,7 @@ void main() { } expect(count, 108); - bool isEven(int i) => i % 2 == 0; + bool isEven(int i) => i.isEven; var evens = List<int>.from(lb1.where(isEven)); expect(evens, [0, 2, 6]); @@ -91,7 +91,8 @@ void main() { test('PbList validates items', () { expect(() { - (PbList<int>() as dynamic).add('hello'); + // ignore: unnecessary_cast + (PbList<int>() as List).add('hello'); }, throwsA(TypeMatcher<TypeError>())); }); diff --git a/protobuf/test/map_mixin_test.dart b/protobuf/test/map_mixin_test.dart index bd4cc2b09..e923e8f7e 100644 --- a/protobuf/test/map_mixin_test.dart +++ b/protobuf/test/map_mixin_test.dart @@ -9,7 +9,8 @@ import 'dart:collection' show MapMixin; import 'package:protobuf/protobuf.dart'; import 'package:protobuf/src/protobuf/mixins/map_mixin.dart'; -import 'package:test/test.dart' show expect, same, test, throwsArgumentError; +import 'package:test/test.dart' + show expect, isA, same, test, throwsArgumentError; import 'mock_util.dart' show MockMessage, mockInfo; @@ -17,7 +18,7 @@ import 'mock_util.dart' show MockMessage, mockInfo; class Rec extends MockMessage with MapMixin<Object?, Object>, PbMapMixin { @override BuilderInfo get info_ => _info; - static final _info = mockInfo('Rec', () => Rec()); + static final _info = mockInfo('Rec', Rec.new); @override Rec createEmptyInstance() => Rec(); @@ -35,7 +36,7 @@ void main() { expect(r['val'], 42); expect(r['str'], ''); - expect(r['child'].runtimeType, Rec); + expect(r['child'], isA<Rec>()); expect(r['child'].toString(), 'Rec(42, "")'); expect(r['int32s'], []); @@ -65,7 +66,7 @@ void main() { expect(r['child'], same(child)); expect(() => r['int32s'] = 123, throwsArgumentError); - r['int32s'].add(123); + (r['int32s'] as List).add(123); expect(r['int32s'], [123]); expect(r['int32s'], same(r['int32s'])); }); diff --git a/protobuf/test/message_test.dart b/protobuf/test/message_test.dart index 8fb2013a4..77f08e934 100644 --- a/protobuf/test/message_test.dart +++ b/protobuf/test/message_test.dart @@ -6,38 +6,34 @@ import 'package:matcher/src/interfaces.dart'; import 'package:protobuf/protobuf.dart'; -import 'package:test/test.dart' show test, expect, predicate, throwsA; +import 'package:test/test.dart' show expect, isA, test, throwsA; import 'mock_util.dart' show MockMessage, mockInfo; class Rec extends MockMessage { @override BuilderInfo get info_ => _info; - static final _info = mockInfo('Rec', () => Rec()); + static final _info = mockInfo('Rec', Rec.new); @override Rec createEmptyInstance() => Rec(); } -Matcher throwsError(Type expectedType, String expectedMessage) => - throwsA(predicate((dynamic x) { - expect(x.runtimeType, expectedType); - expect(x!.message, expectedMessage); - return true; - })); +Matcher throwsError(String expectedMessage) => throwsA(isA<ArgumentError>() + .having((p0) => p0.message, 'message', expectedMessage)); void main() { test('getField with invalid tag throws exception', () { var r = Rec(); expect(() { r.getField(123); - }, throwsError(ArgumentError, 'tag 123 not defined in Rec')); + }, throwsError('tag 123 not defined in Rec')); }); test('getDefaultForField with invalid tag throws exception', () { var r = Rec(); expect(() { r.getDefaultForField(123); - }, throwsError(ArgumentError, 'tag 123 not defined in Rec')); + }, throwsError('tag 123 not defined in Rec')); }); test('operator== and hashCode works for frozen message', () { diff --git a/protobuf/test/mock_util.dart b/protobuf/test/mock_util.dart index 8b6bfb44c..35d346aed 100644 --- a/protobuf/test/mock_util.dart +++ b/protobuf/test/mock_util.dart @@ -60,7 +60,7 @@ abstract class MockMessage extends GeneratedMessage { class T extends MockMessage { @override BuilderInfo get info_ => _info; - static final _info = mockInfo('T', () => T()); + static final _info = mockInfo('T', T.new); @override T createEmptyInstance() => T(); } diff --git a/protobuf/test/readonly_message_test.dart b/protobuf/test/readonly_message_test.dart index ef365b993..7df200c5c 100644 --- a/protobuf/test/readonly_message_test.dart +++ b/protobuf/test/readonly_message_test.dart @@ -6,12 +6,10 @@ import 'package:protobuf/protobuf.dart' show BuilderInfo, GeneratedMessage, PbFieldType, UnknownFieldSetField; import 'package:test/test.dart'; -Matcher throwsError(Type expectedType, Matcher expectedMessage) => - throwsA(predicate((dynamic x) { - expect(x.runtimeType, expectedType); - expect(x!.message, expectedMessage); - return true; - })); +Matcher throwsUnsupportedError(Matcher expectedMessage) => throwsA( + isA<UnsupportedError>() + .having((p0) => p0.message, 'message', expectedMessage), + ); class Rec extends GeneratedMessage { static Rec getDefault() => Rec()..freeze(); @@ -56,53 +54,51 @@ void main() { test("can't merge to a read-only message", () { expect( () => Rec.getDefault().mergeFromJson('{"1":1}'), - throwsError(UnsupportedError, + throwsUnsupportedError( equals('Attempted to change a read-only message (rec)'))); }); test("can't set a field on a read-only message", () { expect( () => Rec.getDefault().setField(1, 456), - throwsError(UnsupportedError, + throwsUnsupportedError( equals('Attempted to change a read-only message (rec)'))); }); test("can't clear a read-only message", () { expect( () => Rec.getDefault().clear(), - throwsError(UnsupportedError, + throwsUnsupportedError( equals('Attempted to change a read-only message (rec)'))); }); test("can't clear a field on a read-only message", () { expect( () => Rec.getDefault().clearField(1), - throwsError(UnsupportedError, + throwsUnsupportedError( equals('Attempted to change a read-only message (rec)'))); }); test("can't modify repeated fields on a read-only message", () { expect(() => Rec.getDefault().sub.add(Rec.create()), - throwsError(UnsupportedError, contains('add'))); + throwsUnsupportedError(contains('add'))); var r = Rec.create() ..ints.add(10) ..freeze(); expect(() => r.ints.clear(), - throwsError(UnsupportedError, equals("'clear' on a read-only list"))); - expect( - () => r.ints[0] = 2, - throwsError( - UnsupportedError, equals("'set element' on a read-only list"))); + throwsUnsupportedError(equals("'clear' on a read-only list"))); + expect(() => r.ints[0] = 2, + throwsUnsupportedError(equals("'set element' on a read-only list"))); expect(() => r.sub.add(Rec.create()), - throwsError(UnsupportedError, equals("'add' on a read-only list"))); + throwsUnsupportedError(equals("'add' on a read-only list"))); r = Rec.create() ..sub.add(Rec.create()) ..freeze(); expect(() => r.sub.add(Rec.create()), - throwsError(UnsupportedError, equals("'add' on a read-only list"))); - expect(() => r.ints.length = 20, - throwsError(UnsupportedError, contains('length'))); + throwsUnsupportedError(equals("'add' on a read-only list"))); + expect( + () => r.ints.length = 20, throwsUnsupportedError(contains('length'))); }); test("can't modify sub-messages on a read-only message", () { @@ -113,17 +109,15 @@ void main() { expect(r.sub[0].sub[0].value, 1); expect( () => subMessage.value = 2, - throwsError(UnsupportedError, + throwsUnsupportedError( equals('Attempted to change a read-only message (rec)'))); }); test("can't modify unknown fields on a read-only message", () { expect( () => Rec.getDefault().unknownFields.clear(), - throwsError( - UnsupportedError, - equals( - 'Attempted to call clear on a read-only message (UnknownFieldSet)'))); + throwsUnsupportedError(equals( + 'Attempted to call clear on a read-only message (UnknownFieldSet)'))); }); test('can rebuild a frozen message with merge', () { @@ -202,11 +196,11 @@ void main() { final rebuilt = orig.copyWith((m) { expect( () => subMessage.value = 5, - throwsError(UnsupportedError, + throwsUnsupportedError( equals('Attempted to change a read-only message (rec)'))); expect( () => m.sub[0].sub[0].value = 2, - throwsError(UnsupportedError, + throwsUnsupportedError( equals('Attempted to change a read-only message (rec)'))); m.sub[0] = m.sub[0].copyWith( (m2) => m2.sub[0] = m2.sub[0].copyWith((m3) => m3.value = 2)); diff --git a/protoc_plugin/CHANGELOG.md b/protoc_plugin/CHANGELOG.md index a1ad2e41c..7bca4f35f 100644 --- a/protoc_plugin/CHANGELOG.md +++ b/protoc_plugin/CHANGELOG.md @@ -6,7 +6,7 @@ * Remove message constructor arguments. Constructors with arguments cause increase in release binary sizes even when no arguments are passed to the constructors. ([#703]) -* Require Dart `2.17`. +* Require Dart `2.19`. **Migration:** diff --git a/protoc_plugin/analysis_options.yaml b/protoc_plugin/analysis_options.yaml new file mode 100644 index 000000000..2a1174d71 --- /dev/null +++ b/protoc_plugin/analysis_options.yaml @@ -0,0 +1,6 @@ +include: ../analysis_options.yaml + +analyzer: + errors: + avoid_dynamic_calls: ignore + only_throw_errors: ignore diff --git a/protoc_plugin/lib/mixins.dart b/protoc_plugin/lib/mixins.dart index 437183879..2fe9d9ca4 100644 --- a/protoc_plugin/lib/mixins.dart +++ b/protoc_plugin/lib/mixins.dart @@ -4,6 +4,8 @@ /// Provides metadata about mixins to dart-protoc-plugin. /// (Experimental API; subject to change.) +library; + import 'indenting_writer.dart'; /// Finds [name] in the exported mixins. diff --git a/protoc_plugin/lib/names.dart b/protoc_plugin/lib/names.dart index b9702d66e..5dfc361f8 100644 --- a/protoc_plugin/lib/names.dart +++ b/protoc_plugin/lib/names.dart @@ -188,7 +188,7 @@ Iterable<String> defaultSuffixes() sync* { yield '_'; var i = 0; while (true) { - yield ('_$i'); + yield '_$i'; i++; } } diff --git a/protoc_plugin/lib/src/file_generator.dart b/protoc_plugin/lib/src/file_generator.dart index f4c199498..976e4de4a 100644 --- a/protoc_plugin/lib/src/file_generator.dart +++ b/protoc_plugin/lib/src/file_generator.dart @@ -156,8 +156,8 @@ class FileGenerator extends ProtobufContainer { var defaultMixin = declaredMixins[defaultMixinName] ?? findMixin(defaultMixinName); if (defaultMixin == null && defaultMixinName.isNotEmpty) { - throw ('Option default_mixin on file ${descriptor.name}: Unknown mixin ' - '$defaultMixinName'); + throw 'Option default_mixin on file ${descriptor.name}: Unknown mixin ' + '$defaultMixinName'; } // Load and register all enum and message types. diff --git a/protoc_plugin/pubspec.yaml b/protoc_plugin/pubspec.yaml index 26d02432b..9d41023ab 100644 --- a/protoc_plugin/pubspec.yaml +++ b/protoc_plugin/pubspec.yaml @@ -4,7 +4,7 @@ description: A protobuf protoc compiler plugin used to generate Dart code. repository: https://github.com/google/protobuf.dart/tree/master/protoc_plugin environment: - sdk: '>=2.17.0 <3.0.0' + sdk: '>=2.19.0 <3.0.0' dependencies: fixnum: ^1.0.0 @@ -13,7 +13,7 @@ dependencies: dev_dependencies: collection: ^1.15.0 - lints: ^1.0.0 + dart_flutter_team_lints: ^1.0.0 matcher: ^0.12.10 test: ^1.16.0 diff --git a/protoc_plugin/test/map_test.dart b/protoc_plugin/test/map_test.dart index 538456c6e..00d5eda00 100644 --- a/protoc_plugin/test/map_test.dart +++ b/protoc_plugin/test/map_test.dart @@ -3,7 +3,7 @@ // BSD-style license that can be found in the LICENSE file. import 'package:test/test.dart' - show test, expect, predicate, same, throwsA, throwsArgumentError, isA; + show expect, isA, predicate, same, test, throwsA, throwsArgumentError; import '../out/protos/map_api.pb.dart' as pb; import '../out/protos/map_api2.pb.dart' as pb2; diff --git a/protoc_plugin/test/merge_test.dart b/protoc_plugin/test/merge_test.dart index f0b9efa6f..827cd45c8 100644 --- a/protoc_plugin/test/merge_test.dart +++ b/protoc_plugin/test/merge_test.dart @@ -3,7 +3,7 @@ // BSD-style license that can be found in the LICENSE file. import 'package:fixnum/fixnum.dart'; -import 'package:test/test.dart' show test, expect; +import 'package:test/test.dart' show expect, test; import '../out/protos/foo.pb.dart' as pb; diff --git a/protoc_plugin/test/message_test.dart b/protoc_plugin/test/message_test.dart index 60038cf64..5d1b994c4 100644 --- a/protoc_plugin/test/message_test.dart +++ b/protoc_plugin/test/message_test.dart @@ -107,12 +107,16 @@ repeatedString: qux }); test('testUninitializedException', () { - try { - TestRequired().check(); - fail('Should have thrown an exception.'); - } on StateError catch (e) { - expect(e.message, 'Message missing required fields: a, b, c'); - } + expect( + () => TestRequired().check(), + throwsA( + isA<StateError>().having( + (p0) => p0.message, + 'message', + 'Message missing required fields: a, b, c', + ), + ), + ); }); test('testBuildPartial', () { @@ -122,30 +126,29 @@ repeatedString: qux }); test('testNestedUninitializedException', () { - try { - var message = TestRequiredForeign(); - message.optionalMessage = testRequiredUninitialized; - message.repeatedMessage.add(testRequiredUninitialized); - message.repeatedMessage.add(testRequiredUninitialized); - message.check(); - fail('Should have thrown an exception.'); - } on StateError catch (e) { - // NOTE: error message differs from Java in that - // fields are referenced using Dart fieldnames r.t. - // proto field names. - expect( - e.message, + var message = TestRequiredForeign(); + message.optionalMessage = testRequiredUninitialized; + message.repeatedMessage.add(testRequiredUninitialized); + message.repeatedMessage.add(testRequiredUninitialized); + expect( + () => message.check(), + throwsA( + isA<StateError>().having( + (p0) => p0.message, + 'message', 'Message missing required fields: ' - 'optionalMessage.a, ' - 'optionalMessage.b, ' - 'optionalMessage.c, ' - 'repeatedMessage[0].a, ' - 'repeatedMessage[0].b, ' - 'repeatedMessage[0].c, ' - 'repeatedMessage[1].a, ' - 'repeatedMessage[1].b, ' - 'repeatedMessage[1].c'); - } + 'optionalMessage.a, ' + 'optionalMessage.b, ' + 'optionalMessage.c, ' + 'repeatedMessage[0].a, ' + 'repeatedMessage[0].b, ' + 'repeatedMessage[0].c, ' + 'repeatedMessage[1].a, ' + 'repeatedMessage[1].b, ' + 'repeatedMessage[1].c', + ), + ), + ); }); test('testBuildNestedPartial', () { @@ -158,12 +161,16 @@ repeatedString: qux }); test('testParseUnititialized', () { - try { - (TestRequired.fromBuffer([])).check(); - fail('Should have thrown an exception.'); - } on StateError catch (e) { - expect(e.message, 'Message missing required fields: a, b, c'); - } + expect( + () => TestRequired.fromBuffer([]).check(), + throwsA( + isA<StateError>().having( + (p0) => p0.message, + 'message', + 'Message missing required fields: a, b, c', + ), + ), + ); }); test('testParseNestedUnititialized', () { @@ -173,26 +180,25 @@ repeatedString: qux message.repeatedMessage.add(testRequiredUninitialized); List<int> buffer = message.writeToBuffer(); - try { - (TestRequiredForeign.fromBuffer(buffer)).check(); - fail('Should have thrown an exception.'); - } on StateError catch (e) { - // NOTE: error message differs from Java in that - // fields are referenced using Dart fieldnames r.t. - // proto field names. - expect( - e.message, + expect( + () => TestRequiredForeign.fromBuffer(buffer).check(), + throwsA( + isA<StateError>().having( + (p0) => p0.message, + 'message', 'Message missing required fields: ' - 'optionalMessage.a, ' - 'optionalMessage.b, ' - 'optionalMessage.c, ' - 'repeatedMessage[0].a, ' - 'repeatedMessage[0].b, ' - 'repeatedMessage[0].c, ' - 'repeatedMessage[1].a, ' - 'repeatedMessage[1].b, ' - 'repeatedMessage[1].c'); - } + 'optionalMessage.a, ' + 'optionalMessage.b, ' + 'optionalMessage.c, ' + 'repeatedMessage[0].a, ' + 'repeatedMessage[0].b, ' + 'repeatedMessage[0].c, ' + 'repeatedMessage[1].a, ' + 'repeatedMessage[1].b, ' + 'repeatedMessage[1].c', + ), + ), + ); }); test('testClearField', () { From a38906b5d79d4dbe94f921a1744a9cc241da7eba Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Mon, 1 May 2023 15:32:25 -0700 Subject: [PATCH 2/6] more more lint --- analysis_options.yaml | 1 + benchmarks/bin/deep_copy.dart | 5 ++--- benchmarks/bin/from_binary.dart | 5 ++--- benchmarks/bin/from_json_string.dart | 5 ++--- benchmarks/bin/from_proto3_json_object.dart | 5 ++--- benchmarks/bin/from_proto3_json_string.dart | 5 ++--- benchmarks/bin/hash_code.dart | 5 ++--- benchmarks/bin/query_decode_binary.dart | 2 +- benchmarks/bin/query_decode_json.dart | 5 ++--- benchmarks/bin/query_encode_binary.dart | 4 +--- benchmarks/bin/query_encode_json.dart | 4 +--- benchmarks/bin/query_set_nested_value.dart | 5 ++--- benchmarks/bin/to_binary.dart | 5 ++--- benchmarks/bin/to_json_string.dart | 5 ++--- benchmarks/bin/to_proto3_json_object.dart | 5 ++--- benchmarks/bin/to_proto3_json_string.dart | 5 ++--- benchmarks/lib/benchmark_base.dart | 2 +- 17 files changed, 29 insertions(+), 44 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 0913b1151..270367bfb 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -11,3 +11,4 @@ linter: - avoid_bool_literals_in_conditional_expressions - comment_references - prefer_relative_imports + - use_super_parameters diff --git a/benchmarks/bin/deep_copy.dart b/benchmarks/bin/deep_copy.dart index 9dbb9fe85..359a71401 100644 --- a/benchmarks/bin/deep_copy.dart +++ b/benchmarks/bin/deep_copy.dart @@ -16,12 +16,11 @@ class Benchmark extends BenchmarkBase { final p3.GoogleMessage1 _message1Proto3; final GoogleMessage2 _message2; - Benchmark(String name, List<int> message1Proto2Input, + Benchmark(super.name, List<int> message1Proto2Input, List<int> message1Proto3Input, List<int> message2Input) : _message1Proto2 = p2.GoogleMessage1.fromBuffer(message1Proto2Input), _message1Proto3 = p3.GoogleMessage1.fromBuffer(message1Proto3Input), - _message2 = GoogleMessage2.fromBuffer(message2Input), - super(name); + _message2 = GoogleMessage2.fromBuffer(message2Input); @override void run() { diff --git a/benchmarks/bin/from_binary.dart b/benchmarks/bin/from_binary.dart index 8d5990b17..bf5818949 100644 --- a/benchmarks/bin/from_binary.dart +++ b/benchmarks/bin/from_binary.dart @@ -17,12 +17,11 @@ class Benchmark extends BenchmarkBase { final Uint8List _message1Proto3Input; final Uint8List _message2Input; - Benchmark(String name, List<int> message1Proto2Input, + Benchmark(super.name, List<int> message1Proto2Input, List<int> message1Proto3Input, List<int> message2Input) : _message1Proto2Input = Uint8List.fromList(message1Proto2Input), _message1Proto3Input = Uint8List.fromList(message1Proto3Input), - _message2Input = Uint8List.fromList(message2Input), - super(name); + _message2Input = Uint8List.fromList(message2Input); @override void run() { diff --git a/benchmarks/bin/from_json_string.dart b/benchmarks/bin/from_json_string.dart index 02e22a276..a571fc694 100644 --- a/benchmarks/bin/from_json_string.dart +++ b/benchmarks/bin/from_json_string.dart @@ -15,15 +15,14 @@ class Benchmark extends BenchmarkBase { final String _message1Proto3JsonString; final String _message2JsonString; - Benchmark(String name, List<int> message1Proto2Input, + Benchmark(super.name, List<int> message1Proto2Input, List<int> message1Proto3Input, List<int> message2Input) : _message1Proto2JsonString = p2.GoogleMessage1.fromBuffer(message1Proto2Input).writeToJson(), _message1Proto3JsonString = p3.GoogleMessage1.fromBuffer(message1Proto3Input).writeToJson(), _message2JsonString = - GoogleMessage2.fromBuffer(message2Input).writeToJson(), - super(name); + GoogleMessage2.fromBuffer(message2Input).writeToJson(); @override void run() { diff --git a/benchmarks/bin/from_proto3_json_object.dart b/benchmarks/bin/from_proto3_json_object.dart index 1ca424ac2..d9e5705bc 100644 --- a/benchmarks/bin/from_proto3_json_object.dart +++ b/benchmarks/bin/from_proto3_json_object.dart @@ -15,15 +15,14 @@ class Benchmark extends BenchmarkBase { final Object? _message1Proto3Proto3JsonObject; final Object? _message2Proto3JsonObject; - Benchmark(String name, List<int> message1Proto2Input, + Benchmark(super.name, List<int> message1Proto2Input, List<int> message1Proto3Input, List<int> message2Input) : _message1Proto2Proto3JsonObject = p2.GoogleMessage1.fromBuffer(message1Proto2Input).toProto3Json(), _message1Proto3Proto3JsonObject = p3.GoogleMessage1.fromBuffer(message1Proto3Input).toProto3Json(), _message2Proto3JsonObject = - GoogleMessage2.fromBuffer(message2Input).toProto3Json(), - super(name); + GoogleMessage2.fromBuffer(message2Input).toProto3Json(); @override void run() { diff --git a/benchmarks/bin/from_proto3_json_string.dart b/benchmarks/bin/from_proto3_json_string.dart index f3c8c1e04..a18b9cabd 100644 --- a/benchmarks/bin/from_proto3_json_string.dart +++ b/benchmarks/bin/from_proto3_json_string.dart @@ -17,15 +17,14 @@ class Benchmark extends BenchmarkBase { final String _message1Proto3Proto3JsonString; final String _message2Proto3JsonString; - Benchmark(String name, List<int> message1Proto2Input, + Benchmark(super.name, List<int> message1Proto2Input, List<int> message1Proto3Input, List<int> message2Input) : _message1Proto2Proto3JsonString = jsonEncode( p2.GoogleMessage1.fromBuffer(message1Proto2Input).toProto3Json()), _message1Proto3Proto3JsonString = jsonEncode( p3.GoogleMessage1.fromBuffer(message1Proto3Input).toProto3Json()), _message2Proto3JsonString = - jsonEncode(GoogleMessage2.fromBuffer(message2Input).toProto3Json()), - super(name); + jsonEncode(GoogleMessage2.fromBuffer(message2Input).toProto3Json()); @override void run() { diff --git a/benchmarks/bin/hash_code.dart b/benchmarks/bin/hash_code.dart index 5d1e01e67..3053ab7ae 100644 --- a/benchmarks/bin/hash_code.dart +++ b/benchmarks/bin/hash_code.dart @@ -15,12 +15,11 @@ class Benchmark extends BenchmarkBase { final p3.GoogleMessage1 _message1Proto3; final GoogleMessage2 _message2; - Benchmark(String name, List<int> message1Proto2Input, + Benchmark(super.name, List<int> message1Proto2Input, List<int> message1Proto3Input, List<int> message2Input) : _message1Proto2 = p2.GoogleMessage1.fromBuffer(message1Proto2Input), _message1Proto3 = p3.GoogleMessage1.fromBuffer(message1Proto3Input), - _message2 = GoogleMessage2.fromBuffer(message2Input), - super(name); + _message2 = GoogleMessage2.fromBuffer(message2Input); @override void run() { diff --git a/benchmarks/bin/query_decode_binary.dart b/benchmarks/bin/query_decode_binary.dart index 80a8123c2..865ba87ca 100644 --- a/benchmarks/bin/query_decode_binary.dart +++ b/benchmarks/bin/query_decode_binary.dart @@ -9,7 +9,7 @@ import 'package:protobuf_benchmarks/readfile.dart'; class Benchmark extends BenchmarkBase { final List<int> _input; - Benchmark(String name, this._input) : super(name); + Benchmark(super.name, this._input); @override void run() { diff --git a/benchmarks/bin/query_decode_json.dart b/benchmarks/bin/query_decode_json.dart index 1909b4b1c..95e206b14 100644 --- a/benchmarks/bin/query_decode_json.dart +++ b/benchmarks/bin/query_decode_json.dart @@ -9,9 +9,8 @@ import 'package:protobuf_benchmarks/readfile.dart'; class Benchmark extends BenchmarkBase { final String _input; - Benchmark(String name, List<int> input) - : _input = f0.A0.fromBuffer(input).writeToJson(), - super(name); + Benchmark(super.name, List<int> input) + : _input = f0.A0.fromBuffer(input).writeToJson(); @override void run() { diff --git a/benchmarks/bin/query_encode_binary.dart b/benchmarks/bin/query_encode_binary.dart index ff0b3b189..a8ab15b9c 100644 --- a/benchmarks/bin/query_encode_binary.dart +++ b/benchmarks/bin/query_encode_binary.dart @@ -9,9 +9,7 @@ import 'package:protobuf_benchmarks/readfile.dart'; class Benchmark extends BenchmarkBase { final f0.A0 _input; - Benchmark(String name, List<int> input) - : _input = f0.A0.fromBuffer(input), - super(name); + Benchmark(super.name, List<int> input) : _input = f0.A0.fromBuffer(input); @override void run() { diff --git a/benchmarks/bin/query_encode_json.dart b/benchmarks/bin/query_encode_json.dart index 17789d554..3dbef4810 100644 --- a/benchmarks/bin/query_encode_json.dart +++ b/benchmarks/bin/query_encode_json.dart @@ -9,9 +9,7 @@ import 'package:protobuf_benchmarks/readfile.dart'; class Benchmark extends BenchmarkBase { final f0.A0 _input; - Benchmark(String name, List<int> input) - : _input = f0.A0.fromBuffer(input), - super(name); + Benchmark(super.name, List<int> input) : _input = f0.A0.fromBuffer(input); @override void run() { diff --git a/benchmarks/bin/query_set_nested_value.dart b/benchmarks/bin/query_set_nested_value.dart index 0e9bf5c24..e03df8794 100644 --- a/benchmarks/bin/query_set_nested_value.dart +++ b/benchmarks/bin/query_set_nested_value.dart @@ -12,9 +12,8 @@ import 'package:protobuf_benchmarks/readfile.dart'; class Benchmark extends BenchmarkBase { final f0.A0 _input; - Benchmark(String name, List<int> input) - : _input = f0.A0.fromBuffer(input)..freeze(), - super(name); + Benchmark(super.name, List<int> input) + : _input = f0.A0.fromBuffer(input)..freeze(); @override void run() { diff --git a/benchmarks/bin/to_binary.dart b/benchmarks/bin/to_binary.dart index d008c4d0c..861fd745f 100644 --- a/benchmarks/bin/to_binary.dart +++ b/benchmarks/bin/to_binary.dart @@ -15,12 +15,11 @@ class Benchmark extends BenchmarkBase { final p3.GoogleMessage1 _message1Proto3; final GoogleMessage2 _message2; - Benchmark(String name, List<int> message1Proto2Input, + Benchmark(super.name, List<int> message1Proto2Input, List<int> message1Proto3Input, List<int> message2Input) : _message1Proto2 = p2.GoogleMessage1.fromBuffer(message1Proto2Input), _message1Proto3 = p3.GoogleMessage1.fromBuffer(message1Proto3Input), - _message2 = GoogleMessage2.fromBuffer(message2Input), - super(name); + _message2 = GoogleMessage2.fromBuffer(message2Input); @override void run() { diff --git a/benchmarks/bin/to_json_string.dart b/benchmarks/bin/to_json_string.dart index 32df02cf2..850964a0c 100644 --- a/benchmarks/bin/to_json_string.dart +++ b/benchmarks/bin/to_json_string.dart @@ -15,12 +15,11 @@ class Benchmark extends BenchmarkBase { final p3.GoogleMessage1 _message1Proto3; final GoogleMessage2 _message2; - Benchmark(String name, List<int> message1Proto2Input, + Benchmark(super.name, List<int> message1Proto2Input, List<int> message1Proto3Input, List<int> message2Input) : _message1Proto2 = p2.GoogleMessage1.fromBuffer(message1Proto2Input), _message1Proto3 = p3.GoogleMessage1.fromBuffer(message1Proto3Input), - _message2 = GoogleMessage2.fromBuffer(message2Input), - super(name); + _message2 = GoogleMessage2.fromBuffer(message2Input); @override void run() { diff --git a/benchmarks/bin/to_proto3_json_object.dart b/benchmarks/bin/to_proto3_json_object.dart index 8c23790c1..77483fc2b 100644 --- a/benchmarks/bin/to_proto3_json_object.dart +++ b/benchmarks/bin/to_proto3_json_object.dart @@ -15,12 +15,11 @@ class Benchmark extends BenchmarkBase { final p3.GoogleMessage1 _message1Proto3; final GoogleMessage2 _message2; - Benchmark(String name, List<int> message1Proto2Input, + Benchmark(super.name, List<int> message1Proto2Input, List<int> message1Proto3Input, List<int> message2Input) : _message1Proto2 = p2.GoogleMessage1.fromBuffer(message1Proto2Input), _message1Proto3 = p3.GoogleMessage1.fromBuffer(message1Proto3Input), - _message2 = GoogleMessage2.fromBuffer(message2Input), - super(name); + _message2 = GoogleMessage2.fromBuffer(message2Input); @override void run() { diff --git a/benchmarks/bin/to_proto3_json_string.dart b/benchmarks/bin/to_proto3_json_string.dart index 1a3407d27..36717c069 100644 --- a/benchmarks/bin/to_proto3_json_string.dart +++ b/benchmarks/bin/to_proto3_json_string.dart @@ -17,12 +17,11 @@ class Benchmark extends BenchmarkBase { final p3.GoogleMessage1 _message1Proto3; final GoogleMessage2 _message2; - Benchmark(String name, List<int> message1Proto2Input, + Benchmark(super.name, List<int> message1Proto2Input, List<int> message1Proto3Input, List<int> message2Input) : _message1Proto2 = p2.GoogleMessage1.fromBuffer(message1Proto2Input), _message1Proto3 = p3.GoogleMessage1.fromBuffer(message1Proto3Input), - _message2 = GoogleMessage2.fromBuffer(message2Input), - super(name); + _message2 = GoogleMessage2.fromBuffer(message2Input); @override void run() { diff --git a/benchmarks/lib/benchmark_base.dart b/benchmarks/lib/benchmark_base.dart index cec44ccd5..ec9f060fa 100644 --- a/benchmarks/lib/benchmark_base.dart +++ b/benchmarks/lib/benchmark_base.dart @@ -16,7 +16,7 @@ import 'package:benchmark_harness/benchmark_harness.dart' as bh; /// what the benchmarks are about in Golem UI. /// abstract class BenchmarkBase extends bh.BenchmarkBase { - BenchmarkBase(String name) : super(name, emitter: const _ResultPrinter()); + BenchmarkBase(super.name) : super(emitter: const _ResultPrinter()); @override double measure() { From a591f5734fa8a7a1c3fcb8055cb657076d335587 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Fri, 26 May 2023 19:03:36 -0700 Subject: [PATCH 3/6] eliminate duplicates --- analysis_options.yaml | 3 --- 1 file changed, 3 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 859d2ed74..e7321a172 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -10,9 +10,6 @@ linter: rules: - avoid_bool_literals_in_conditional_expressions - comment_references - - directives_ordering - - no_leading_underscores_for_local_identifiers - - omit_local_variable_types - prefer_final_in_for_each - prefer_final_locals - prefer_relative_imports From 3e6243ec6357688d7be1ee9131d807ae13499398 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Fri, 26 May 2023 19:49:44 -0700 Subject: [PATCH 4/6] dep update --- api_benchmark/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api_benchmark/pubspec.yaml b/api_benchmark/pubspec.yaml index 1ec86e37f..9a9d11ade 100644 --- a/api_benchmark/pubspec.yaml +++ b/api_benchmark/pubspec.yaml @@ -19,7 +19,7 @@ dependencies: dev_dependencies: build: ^2.0.0 build_runner: ^2.0.6 - build_web_compilers: ^3.0.0 + build_web_compilers: ^4.0.0 dart_flutter_team_lints: ^1.0.0 glob: ^2.0.0 protoc_plugin: From d78e5a7be5eb799d6cd34114b4ff9440cc43c1d7 Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Tue, 30 May 2023 09:14:11 -0700 Subject: [PATCH 5/6] review nits --- protoc_plugin/test/message_test.dart | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/protoc_plugin/test/message_test.dart b/protoc_plugin/test/message_test.dart index 354361afe..9064721a1 100644 --- a/protoc_plugin/test/message_test.dart +++ b/protoc_plugin/test/message_test.dart @@ -132,6 +132,9 @@ repeatedString: qux message.repeatedMessage.add(testRequiredUninitialized); expect( message.check, + // NOTE: error message differs from Java in that + // fields are referenced using Dart fieldnames r.t. + // proto field names. throwsA( isA<StateError>().having( (p0) => p0.message, @@ -182,6 +185,9 @@ repeatedString: qux expect( () => TestRequiredForeign.fromBuffer(buffer).check(), + // NOTE: error message differs from Java in that + // fields are referenced using Dart fieldnames r.t. + // proto field names. throwsA( isA<StateError>().having( (p0) => p0.message, From c2457cc7c758957ccae3a716fcf97702b19c57eb Mon Sep 17 00:00:00 2001 From: Kevin Moore <kevmoo@google.com> Date: Tue, 30 May 2023 09:16:21 -0700 Subject: [PATCH 6/6] regenerate --- protoc_plugin/lib/src/generated/dart_options.pb.dart | 2 +- protoc_plugin/lib/src/generated/descriptor.pb.dart | 2 +- protoc_plugin/lib/src/generated/descriptor.pbenum.dart | 2 +- protoc_plugin/lib/src/generated/plugin.pb.dart | 2 +- protoc_plugin/lib/src/generated/plugin.pbenum.dart | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/protoc_plugin/lib/src/generated/dart_options.pb.dart b/protoc_plugin/lib/src/generated/dart_options.pb.dart index 49a2f572d..a9c525f36 100644 --- a/protoc_plugin/lib/src/generated/dart_options.pb.dart +++ b/protoc_plugin/lib/src/generated/dart_options.pb.dart @@ -7,7 +7,7 @@ // ignore_for_file: annotate_overrides, camel_case_types // ignore_for_file: constant_identifier_names, library_prefixes // ignore_for_file: non_constant_identifier_names, prefer_final_fields -// ignore_for_file: return_of_invalid_type, unnecessary_import, unnecessary_this +// ignore_for_file: unnecessary_import, unnecessary_this, unused_import import 'dart:core' as $core; diff --git a/protoc_plugin/lib/src/generated/descriptor.pb.dart b/protoc_plugin/lib/src/generated/descriptor.pb.dart index 7bdfa7b34..90df2e82c 100644 --- a/protoc_plugin/lib/src/generated/descriptor.pb.dart +++ b/protoc_plugin/lib/src/generated/descriptor.pb.dart @@ -7,7 +7,7 @@ // ignore_for_file: annotate_overrides, camel_case_types // ignore_for_file: constant_identifier_names, library_prefixes // ignore_for_file: non_constant_identifier_names, prefer_final_fields -// ignore_for_file: return_of_invalid_type, unnecessary_import, unnecessary_this +// ignore_for_file: unnecessary_import, unnecessary_this, unused_import import 'dart:core' as $core; diff --git a/protoc_plugin/lib/src/generated/descriptor.pbenum.dart b/protoc_plugin/lib/src/generated/descriptor.pbenum.dart index fa41da747..949b9c5f3 100644 --- a/protoc_plugin/lib/src/generated/descriptor.pbenum.dart +++ b/protoc_plugin/lib/src/generated/descriptor.pbenum.dart @@ -7,7 +7,7 @@ // ignore_for_file: annotate_overrides, camel_case_types // ignore_for_file: constant_identifier_names, library_prefixes // ignore_for_file: non_constant_identifier_names, prefer_final_fields -// ignore_for_file: return_of_invalid_type, unnecessary_this +// ignore_for_file: unnecessary_import, unnecessary_this, unused_import import 'dart:core' as $core; diff --git a/protoc_plugin/lib/src/generated/plugin.pb.dart b/protoc_plugin/lib/src/generated/plugin.pb.dart index ff1ae33f5..6ac13112a 100644 --- a/protoc_plugin/lib/src/generated/plugin.pb.dart +++ b/protoc_plugin/lib/src/generated/plugin.pb.dart @@ -7,7 +7,7 @@ // ignore_for_file: annotate_overrides, camel_case_types // ignore_for_file: constant_identifier_names, library_prefixes // ignore_for_file: non_constant_identifier_names, prefer_final_fields -// ignore_for_file: return_of_invalid_type, unnecessary_import, unnecessary_this +// ignore_for_file: unnecessary_import, unnecessary_this, unused_import import 'dart:core' as $core; diff --git a/protoc_plugin/lib/src/generated/plugin.pbenum.dart b/protoc_plugin/lib/src/generated/plugin.pbenum.dart index 63e7d5e47..b70440027 100644 --- a/protoc_plugin/lib/src/generated/plugin.pbenum.dart +++ b/protoc_plugin/lib/src/generated/plugin.pbenum.dart @@ -7,7 +7,7 @@ // ignore_for_file: annotate_overrides, camel_case_types // ignore_for_file: constant_identifier_names, library_prefixes // ignore_for_file: non_constant_identifier_names, prefer_final_fields -// ignore_for_file: return_of_invalid_type, unnecessary_this +// ignore_for_file: unnecessary_import, unnecessary_this, unused_import import 'dart:core' as $core;