Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to latest lints #967

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ analyzer:
strict-casts: true
errors:
lines_longer_than_80_chars: ignore
inference_failure_on_function_invocation: ignore
inference_failure_on_collection_literal: ignore

linter:
rules:
- avoid_bool_literals_in_conditional_expressions
- comment_references
- prefer_final_in_for_each
- prefer_final_locals
- prefer_relative_imports
- use_super_parameters
2 changes: 1 addition & 1 deletion api_benchmark/lib/benchmarks/get_strings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class GetStringsBenchmark extends Benchmark {
String get measureSampleUnits => 'string reads/ms';

static const $id = BenchmarkID.GET_STRINGS;
static final $type = BenchmarkType($id, $create);
static final $type = const BenchmarkType($id, $create);

static GetStringsBenchmark $create(Request r) {
assert(r.params.hasMessageCount());
Expand Down
2 changes: 1 addition & 1 deletion api_benchmark/lib/benchmarks/has_strings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class HasStringsBenchmark extends Benchmark {
String get measureSampleUnits => 'string reads/ms';

static const $id = BenchmarkID.HAS_STRINGS;
static final $type = BenchmarkType($id, $create);
static final $type = const BenchmarkType($id, $create);

static HasStringsBenchmark $create(Request r) {
assert(r.params.hasMessageCount());
Expand Down
2 changes: 1 addition & 1 deletion api_benchmark/lib/benchmarks/int32_json.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class Int32Benchmark extends Benchmark {
String get measureSampleUnits => 'int32 reads/ms';

static const $id = BenchmarkID.READ_INT32_FIELDS_JSON;
static final $type = BenchmarkType($id, $create);
static final $type = const BenchmarkType($id, $create);

static Int32Benchmark $create(Request r) {
assert(r.params.hasInt32FieldCount());
Expand Down
2 changes: 1 addition & 1 deletion api_benchmark/lib/benchmarks/int64_json.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Int64Benchmark extends Benchmark {
String get measureSampleUnits => 'int64 reads/ms';

static const $id = BenchmarkID.READ_INT64_FIELDS_JSON;
static final $type = BenchmarkType($id, $create);
static final $type = const BenchmarkType($id, $create);

static Int64Benchmark $create(Request r) {
assert(r.params.hasInt64FieldCount());
Expand Down
2 changes: 1 addition & 1 deletion api_benchmark/lib/benchmarks/repeated_int32_json.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class RepeatedInt32Benchmark extends Benchmark {
String get measureSampleUnits => 'int32 reads/ms';

static const $id = BenchmarkID.READ_INT32_REPEATED_JSON;
static final $type = BenchmarkType($id, $create);
static final $type = const BenchmarkType($id, $create);
static RepeatedInt32Benchmark $create(Request r) {
assert(r.params.hasInt32RepeatCount());
assert(r.params.hasMessageCount());
Expand Down
2 changes: 1 addition & 1 deletion api_benchmark/lib/benchmarks/repeated_int64_json.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class RepeatedInt64Benchmark extends Benchmark {
String get measureSampleUnits => 'int64 reads/ms';

static const $id = BenchmarkID.READ_INT64_REPEATED_JSON;
static final $type = BenchmarkType($id, $create);
static final $type = const BenchmarkType($id, $create);
static RepeatedInt64Benchmark $create(Request r) {
assert(r.params.hasInt64RepeatCount());
assert(r.params.hasMessageCount());
Expand Down
2 changes: 1 addition & 1 deletion api_benchmark/lib/benchmarks/repeated_string_json.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class RepeatedStringBenchmark extends Benchmark {
String get measureSampleUnits => 'string reads/ms';

static const $id = BenchmarkID.READ_STRING_REPEATED_JSON;
static final $type = BenchmarkType($id, $create);
static final $type = const BenchmarkType($id, $create);

static RepeatedStringBenchmark $create(Request r) {
assert(r.params.hasStringFieldCount());
Expand Down
2 changes: 1 addition & 1 deletion api_benchmark/lib/benchmarks/set_strings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class SetStringsBenchmark extends Benchmark {
String get measureSampleUnits => 'string writes/ms';

static const $id = BenchmarkID.SET_STRINGS;
static final $type = BenchmarkType($id, $create);
static final $type = const BenchmarkType($id, $create);

static SetStringsBenchmark $create(Request r) {
assert(r.params.hasMessageCount());
Expand Down
2 changes: 1 addition & 1 deletion api_benchmark/lib/benchmarks/string_json.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class StringBenchmark extends Benchmark {
String get measureSampleUnits => 'string reads/ms';

static const $id = BenchmarkID.READ_STRING_FIELDS_JSON;
static final $type = BenchmarkType($id, $create);
static final $type = const BenchmarkType($id, $create);

static StringBenchmark $create(Request r) {
assert(r.params.hasStringFieldCount());
Expand Down
10 changes: 5 additions & 5 deletions api_benchmark/lib/dashboard_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ Choose baseline: <select class="dv-menu"></select>
factory DashboardView() {
final elt = _template.clone(true) as Element;
Element? find(String q) => elt.querySelector(q);
_Button button(q) => _Button(find(q) as ButtonElement);
_Label label(q) => _Label(find(q) as HtmlElement?);
_Menu menu(q) => _Menu(find(q) as SelectElement);
_JsonView json(q) => _JsonView(find(q) as DivElement?);
_Button button(String q) => _Button(find(q) as ButtonElement);
_Label label(String q) => _Label(find(q) as HtmlElement?);
_Menu menu(String q) => _Menu(find(q) as SelectElement);
_JsonView json(String q) => _JsonView(find(q) as DivElement?);
return DashboardView._raw(
elt as DivElement,
button('.dv-run')
Expand Down Expand Up @@ -295,7 +295,7 @@ class _Label {

class _Button {
final ButtonElement elt;
final _clicks = StreamController.broadcast();
final _clicks = StreamController<bool>.broadcast();
String? _renderedLabel;
bool? _renderedEnabled;

Expand Down
2 changes: 1 addition & 1 deletion api_benchmark/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dev_dependencies:
build: ^2.0.0
build_runner: ^2.0.6
build_web_compilers: ^4.0.0
dart_flutter_team_lints: ^1.0.0
dart_flutter_team_lints: ^3.0.0
glob: ^2.0.0
protoc_plugin:
path: "../protoc_plugin"
Expand Down
2 changes: 1 addition & 1 deletion api_benchmark/tool/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class _BenchmarkBuilder implements Builder {

await buildStep.writeAsString(
AssetId(buildStep.inputId.package, 'web/data/data.json'),
JsonEncoder.withIndent(' ').convert(data));
const JsonEncoder.withIndent(' ').convert(data));
}

@override
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dependencies:

dev_dependencies:
args: ^2.3.1
dart_flutter_team_lints: ^1.0.0
dart_flutter_team_lints: ^3.0.0
path: ^1.8.2
pool: ^1.5.1
protoc_plugin:
Expand Down
2 changes: 1 addition & 1 deletion protobuf/lib/meta.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/// Provides metadata about GeneratedMessage and ProtobufEnum to
/// dart-protoc-plugin. (Experimental API; subject to change.)
/// @nodoc
library protobuf.meta;
library;

// ignore_for_file: constant_identifier_names

Expand Down
4 changes: 2 additions & 2 deletions protobuf/lib/src/protobuf/builder_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class BuilderInfo {
// For well-known types.
final Object? Function(GeneratedMessage message, TypeRegistry typeRegistry)?
toProto3Json;
final Function(GeneratedMessage targetMessage, Object json,
final Object? Function(GeneratedMessage targetMessage, Object json,
TypeRegistry typeRegistry, JsonParsingContext context)? fromProto3Json;
final CreateBuilderFunc? createEmptyInstance;

Expand All @@ -66,7 +66,7 @@ class BuilderInfo {
{String? protoName}) {
final index = byIndex.length;
final fieldInfo = (tagNumber == 0)
? FieldInfo.dummy(index)
? FieldInfo<void>.dummy(index)
: FieldInfo<T>(name, tagNumber, index, fieldType!,
defaultOrMaker: defaultOrMaker,
subBuilder: subBuilder,
Expand Down
2 changes: 1 addition & 1 deletion protobuf/lib/src/protobuf/coded_buffer_reader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class CodedBufferReader {

bool isAtEnd() => _bufferPos >= _currentLimit;

void _withLimit(int byteLimit, Function() callback) {
void _withLimit(int byteLimit, void Function() callback) {
if (byteLimit < 0) {
throw ArgumentError(
'CodedBufferReader encountered an embedded string or message'
Expand Down
2 changes: 1 addition & 1 deletion protobuf/lib/src/protobuf/coded_buffer_writer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class CodedBufferWriter {
/// more efficiently.
ByteData? _outputChunkAsByteData;

/// Array of pairs <Uint8List chunk, int bytesInChunk> - chunks are
/// Array of pairs `<Uint8List chunk, int bytesInChunk>` - chunks are
/// pushed into this array once they are full.
final List<dynamic> _outputChunks = <dynamic>[];

Expand Down
2 changes: 1 addition & 1 deletion protobuf/lib/src/protobuf/exceptions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ CodedBufferReader was allowed to parse only $truncatedSize bytes.
''');

InvalidProtocolBufferException.wrongAnyMessage(
String anyTypeName, unpackerTypeName)
String anyTypeName, String unpackerTypeName)
: this._('''
The type of the Any message ($anyTypeName) does not match the given
unpacker ($unpackerTypeName).
Expand Down
6 changes: 3 additions & 3 deletions protobuf/lib/src/protobuf/extension_field_set.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class _ExtensionFieldSet {

/// Sets a value for a non-repeated extension that has already been added.
/// Does error-checking.
void _setField(int tagNumber, value) {
void _setField(int tagNumber, Object? value) {
final fi = _getInfoOrNull(tagNumber);
if (fi == null) {
throw ArgumentError(
Expand All @@ -98,7 +98,7 @@ class _ExtensionFieldSet {

/// Sets a non-repeated value and extension.
/// Overwrites any existing extension.
void _setFieldAndInfo(Extension fi, value) {
void _setFieldAndInfo(Extension fi, Object? value) {
_ensureWritable();
if (fi.isRepeated) {
throw ArgumentError(_parent._setFieldFailedMessage(
Expand Down Expand Up @@ -129,7 +129,7 @@ class _ExtensionFieldSet {
_info[fi.tagNumber] = fi;
}

void _setFieldUnchecked(Extension fi, value) {
void _setFieldUnchecked(Extension fi, Object? value) {
// If there was already an unknown field with the same tag number,
// overwrite it.
_parent._unknownFields?.clearField(fi.tagNumber);
Expand Down
4 changes: 2 additions & 2 deletions protobuf/lib/src/protobuf/field_error.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ part of '../../protobuf.dart';
///
/// For enums, group, and message fields, this check is only approximate,
/// because the exact type isn't included in [fieldType].
String? _getFieldError(int fieldType, var value) {
String? _getFieldError(int fieldType, Object? value) {
switch (PbFieldType._baseType(fieldType)) {
case PbFieldType._BOOL_BIT:
if (value is! bool) return 'not type bool';
Expand Down Expand Up @@ -130,7 +130,7 @@ void _checkUnsigned32(Object? val) {
}
}

RangeError _createFieldRangeError(val, String wantedType) =>
RangeError _createFieldRangeError(Object val, String wantedType) =>
RangeError('Value ($val) is not $wantedType');

bool _isSigned32(int value) => (-2147483648 <= value) && (value <= 2147483647);
Expand Down
13 changes: 7 additions & 6 deletions protobuf/lib/src/protobuf/field_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,17 @@ class FieldInfo<T> {

/// Returns true if the field's value is okay to transmit.
/// That is, it doesn't contain any required fields that aren't initialized.
bool _hasRequiredValues(value) {
bool _hasRequiredValues(Object? value) {
if (value == null) return !isRequired; // missing is okay if optional
if (!_isGroupOrMessage(type)) return true; // primitive and present

if (!isRepeated) {
// A required message: recurse.
final GeneratedMessage message = value;
final message = value as GeneratedMessage;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see #712. We should revert all changes that converts implicit casts to explicit casts.

return message._fieldSet._hasRequiredValues();
}

final List<GeneratedMessage> list = value;
final list = value as List<GeneratedMessage>;
if (list.isEmpty) return true;

// For message types that (recursively) contain no required fields,
Expand All @@ -184,17 +184,18 @@ class FieldInfo<T> {
}

/// Appends the dotted path to each required field that's missing a value.
void _appendInvalidFields(List<String> problems, value, String prefix) {
void _appendInvalidFields(
List<String> problems, Object? value, String prefix) {
if (value == null) {
if (isRequired) problems.add('$prefix$name');
} else if (!_isGroupOrMessage(type)) {
// primitive and present
} else if (!isRepeated) {
// Required message/group: recurse.
final GeneratedMessage message = value;
final message = value as GeneratedMessage;
message._fieldSet._appendInvalidFields(problems, '$prefix$name.');
} else {
final List<GeneratedMessage> list = value;
final list = value as List<GeneratedMessage>;
if (list.isEmpty) return;

// For message types that (recursively) contain no required fields,
Expand Down
Loading