From a820015bb5077525e964272978574f3c7b2f4584 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Fri, 16 Jan 2026 04:56:01 -0800 Subject: [PATCH] [wasm_builder] enable and fix some new lints dart_flutter_team_lints is more thorough and used in most ecosystem packages I ignored some of the ones with the most violations Change-Id: I825203b1a60ed44d6190aaa59bfce2a18af8bc82 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/473540 Reviewed-by: Martin Kustermann Commit-Queue: Martin Kustermann --- pkg/wasm_builder/analysis_options.yaml | 10 ++++- pkg/wasm_builder/lib/src/builder/builder.dart | 34 ++++++++-------- .../lib/src/builder/instructions.dart | 4 +- pkg/wasm_builder/lib/src/builder/types.dart | 4 +- pkg/wasm_builder/lib/src/builder/util.dart | 4 +- pkg/wasm_builder/lib/src/ir/data_segment.dart | 2 +- pkg/wasm_builder/lib/src/ir/function.dart | 2 +- pkg/wasm_builder/lib/src/ir/global.dart | 2 +- pkg/wasm_builder/lib/src/ir/imports.dart | 15 ++++--- pkg/wasm_builder/lib/src/ir/instructions.dart | 4 +- pkg/wasm_builder/lib/src/ir/ir.dart | 40 +++++++++---------- pkg/wasm_builder/lib/src/ir/module.dart | 2 +- pkg/wasm_builder/lib/src/ir/table.dart | 2 +- pkg/wasm_builder/lib/src/ir/tags.dart | 2 +- pkg/wasm_builder/lib/src/ir/type.dart | 2 +- .../lib/src/serialize/deserializer.dart | 2 +- .../lib/src/serialize/printer.dart | 6 +-- .../lib/src/serialize/serialize.dart | 2 +- pkg/wasm_builder/lib/wasm_builder.dart | 4 +- 19 files changed, 75 insertions(+), 68 deletions(-) diff --git a/pkg/wasm_builder/analysis_options.yaml b/pkg/wasm_builder/analysis_options.yaml index 572dd239d09..ba8959be9a5 100644 --- a/pkg/wasm_builder/analysis_options.yaml +++ b/pkg/wasm_builder/analysis_options.yaml @@ -1 +1,9 @@ -include: package:lints/recommended.yaml +include: package:dart_flutter_team_lints/analysis_options.yaml + +analyzer: + errors: + lines_longer_than_80_chars: ignore + omit_local_variable_types: ignore + only_throw_errors: ignore + prefer_const_constructors: ignore + prefer_single_quotes: ignore diff --git a/pkg/wasm_builder/lib/src/builder/builder.dart b/pkg/wasm_builder/lib/src/builder/builder.dart index 6e154b505c4..8ecf568d02c 100644 --- a/pkg/wasm_builder/lib/src/builder/builder.dart +++ b/pkg/wasm_builder/lib/src/builder/builder.dart @@ -4,30 +4,30 @@ import '../ir/ir.dart' as ir; -export 'data_segments.dart' show DataSegmentsBuilder; export 'data_segment.dart' show DataSegmentBuilder; -export 'exports.dart' show ExportsBuilder; -export 'globals.dart' show GlobalsBuilder; -export 'global.dart' show GlobalBuilder; -export 'functions.dart' show FunctionsBuilder; -export 'function.dart' show FunctionBuilder; +export 'data_segments.dart' show DataSegmentsBuilder; export 'elements.dart' show ElementsBuilder; -export 'memories.dart' show MemoriesBuilder; -export 'module.dart' show ModuleBuilder; -export 'tables.dart' show TablesBuilder; -export 'table.dart' show TableBuilder; -export 'tags.dart' show TagsBuilder; -export 'types.dart' show TypesBuilder; +export 'exports.dart' show ExportsBuilder; +export 'function.dart' show FunctionBuilder; +export 'functions.dart' show FunctionsBuilder; +export 'global.dart' show GlobalBuilder; +export 'globals.dart' show GlobalsBuilder; export 'instructions.dart' show - InstructionsBuilder, - Label, - ValidationError, - TryTableCatch, Catch, CatchAll, + CatchAllRef, CatchRef, - CatchAllRef; + InstructionsBuilder, + Label, + TryTableCatch, + ValidationError; +export 'memories.dart' show MemoriesBuilder; +export 'module.dart' show ModuleBuilder; +export 'table.dart' show TableBuilder; +export 'tables.dart' show TablesBuilder; +export 'tags.dart' show TagsBuilder; +export 'types.dart' show TypesBuilder; mixin Builder { T? _built; diff --git a/pkg/wasm_builder/lib/src/builder/instructions.dart b/pkg/wasm_builder/lib/src/builder/instructions.dart index faf024efd6c..b949aed4a76 100644 --- a/pkg/wasm_builder/lib/src/builder/instructions.dart +++ b/pkg/wasm_builder/lib/src/builder/instructions.dart @@ -4,9 +4,9 @@ // ignore_for_file: non_constant_identifier_names +import '../../source_map.dart'; import '../ir/ir.dart' as ir; import 'builder.dart'; -import '../../source_map.dart'; // TODO(joshualitt): Suggested further optimizations: // 1) Add size estimates to `_Instruction`, and then remove logic where we @@ -319,7 +319,7 @@ class InstructionsBuilder with Builder { } /// Marks a region in the instruction stream (defined by instructions emitted - /// by [fun]) which will be updated in the link phase via the [linkFun]. + /// by `fun`) which will be updated in the link phase via the `linkFun`. InstructionsBuilder? createPatchableRegion( List inputs, List outputs) { assert(_verifyTypes(inputs, outputs, trace: [''])); diff --git a/pkg/wasm_builder/lib/src/builder/types.dart b/pkg/wasm_builder/lib/src/builder/types.dart index 3ea4ad617ca..eae0ad5907c 100644 --- a/pkg/wasm_builder/lib/src/builder/types.dart +++ b/pkg/wasm_builder/lib/src/builder/types.dart @@ -225,7 +225,7 @@ class _RecGroupBuilder { final usedGroups = >[]; for (final group in _allRecursiveGroups) { - if (group.any((type) => allUsedTypes.contains(type))) { + if (group.any(allUsedTypes.contains)) { usedGroups.add(group); } } @@ -355,7 +355,7 @@ class _RecursionGroupKey { int get hashCode => Object.hash(groupLength, lengthOfFirstStruct); @override - bool operator ==(other) { + bool operator ==(Object other) { if (other is! _RecursionGroupKey) return false; if (groupLength != other.groupLength) return false; if (lengthOfFirstStruct != other.lengthOfFirstStruct) return false; diff --git a/pkg/wasm_builder/lib/src/builder/util.dart b/pkg/wasm_builder/lib/src/builder/util.dart index 701303c0f7b..96e9fa516d2 100644 --- a/pkg/wasm_builder/lib/src/builder/util.dart +++ b/pkg/wasm_builder/lib/src/builder/util.dart @@ -13,7 +13,7 @@ int _finalizeIndexables(int index, Iterable indexables) { } List _finalizeIndexablesAndBuild( - int index, Iterable indexableBuilders) { + int index, Iterable> indexableBuilders) { final built = []; for (final f in indexableBuilders) { f.finalizableIndex.finalize(index++); @@ -24,7 +24,7 @@ List _finalizeIndexablesAndBuild( /// Finalizes imports before iterating through a list of builders and building. List finalizeImportsAndBuilders( - Iterable imported, Iterable builders) { + Iterable imported, Iterable> builders) { int index = _finalizeIndexables(0, imported); return _finalizeIndexablesAndBuild(index, builders); } diff --git a/pkg/wasm_builder/lib/src/ir/data_segment.dart b/pkg/wasm_builder/lib/src/ir/data_segment.dart index ead81bf133b..7ff840e2c59 100644 --- a/pkg/wasm_builder/lib/src/ir/data_segment.dart +++ b/pkg/wasm_builder/lib/src/ir/data_segment.dart @@ -4,8 +4,8 @@ import 'dart:typed_data'; -import '../serialize/serialize.dart'; import '../serialize/printer.dart'; +import '../serialize/serialize.dart'; import 'ir.dart'; abstract class BaseDataSegment { diff --git a/pkg/wasm_builder/lib/src/ir/function.dart b/pkg/wasm_builder/lib/src/ir/function.dart index bc1cbd2315f..4d438655924 100644 --- a/pkg/wasm_builder/lib/src/ir/function.dart +++ b/pkg/wasm_builder/lib/src/ir/function.dart @@ -2,8 +2,8 @@ // 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 '../serialize/serialize.dart'; import '../serialize/printer.dart'; +import '../serialize/serialize.dart'; import 'ir.dart'; /// A local variable defined in a function. diff --git a/pkg/wasm_builder/lib/src/ir/global.dart b/pkg/wasm_builder/lib/src/ir/global.dart index e654db3779a..4ffea794ed5 100644 --- a/pkg/wasm_builder/lib/src/ir/global.dart +++ b/pkg/wasm_builder/lib/src/ir/global.dart @@ -2,8 +2,8 @@ // 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 '../serialize/serialize.dart'; import '../serialize/printer.dart'; +import '../serialize/serialize.dart'; import 'ir.dart'; /// An (imported or defined) global variable. diff --git a/pkg/wasm_builder/lib/src/ir/imports.dart b/pkg/wasm_builder/lib/src/ir/imports.dart index 6749590e21c..2a3bbd53c95 100644 --- a/pkg/wasm_builder/lib/src/ir/imports.dart +++ b/pkg/wasm_builder/lib/src/ir/imports.dart @@ -25,14 +25,13 @@ class Imports { } Imports.deserialized(this.all, this.functions, this.tags, this.globals, - this.tables, this.memories) { - assert(all.length == - (functions.length + - tags.length + - globals.length + - tables.length + - memories.length)); - } + this.tables, this.memories) + : assert(all.length == + (functions.length + + tags.length + + globals.length + + tables.length + + memories.length)); } /// Any import (function, table, memory or global). diff --git a/pkg/wasm_builder/lib/src/ir/instructions.dart b/pkg/wasm_builder/lib/src/ir/instructions.dart index 13d038481d9..b5720b51f9d 100644 --- a/pkg/wasm_builder/lib/src/ir/instructions.dart +++ b/pkg/wasm_builder/lib/src/ir/instructions.dart @@ -3,8 +3,8 @@ // BSD-style license that can be found in the LICENSE file. import '../../source_map.dart'; -import '../serialize/serialize.dart'; import '../serialize/printer.dart'; +import '../serialize/serialize.dart'; import 'ir.dart'; class Instructions implements Serializable { @@ -27,7 +27,7 @@ class Instructions implements Serializable { /// A string trace. late final trace = _traceLines.join(); - /// Mappings for the instructions in [_instructions] to their source code. + /// Mappings for the instructions in `_instructions` to their source code. /// /// Since we add mappings as we generate instructions, this will be sorted /// based on [SourceMapping.instructionOffset]. diff --git a/pkg/wasm_builder/lib/src/ir/ir.dart b/pkg/wasm_builder/lib/src/ir/ir.dart index 481c4a7fa66..ef7225df28d 100644 --- a/pkg/wasm_builder/lib/src/ir/ir.dart +++ b/pkg/wasm_builder/lib/src/ir/ir.dart @@ -6,34 +6,33 @@ // TODO(joshualitt): Make all of the ir types full immutable. library; -export 'data_segments.dart' show DataSegments; export 'data_segment.dart' show BaseDataSegment, DataSegment; +export 'data_segments.dart' show DataSegments; +export 'element.dart' + show + ActiveElementSegment, + ActiveExpressionElementSegment, + ActiveFunctionElementSegment, + DeclarativeElementSegment, + ElementSegment; +export 'elements.dart' show Elements; export 'exports.dart' show Export, Exportable, Exports; export 'finalizable.dart' show Finalizable, FinalizableIndex; -export 'indexable.dart' show Indexable; -export 'imports.dart' show Import, Imports; -export 'globals.dart' show Globals; -export 'global.dart' show DefinedGlobal, Global, ImportedGlobal, GlobalExport; -export 'functions.dart' show Functions; export 'function.dart' - show BaseFunction, DefinedFunction, ImportedFunction, Local, FunctionExport; + show BaseFunction, DefinedFunction, FunctionExport, ImportedFunction, Local; +export 'functions.dart' show Functions; +export 'global.dart' show DefinedGlobal, Global, GlobalExport, ImportedGlobal; +export 'globals.dart' show Globals; +export 'imports.dart' show Import, Imports; +export 'indexable.dart' show Indexable; +export 'instruction.dart'; +export 'instructions.dart' show Instructions; export 'memories.dart' show Memories; export 'memory.dart' show DefinedMemory, ImportedMemory, Memory, MemoryExport; export 'module.dart' show Module; -export 'tables.dart' show Tables; -export 'elements.dart' show Elements; -export 'element.dart' - show - ElementSegment, - ActiveElementSegment, - ActiveFunctionElementSegment, - ActiveExpressionElementSegment, - DeclarativeElementSegment; export 'table.dart' show DefinedTable, ImportedTable, Table, TableExport; -export 'tags.dart' show DefinedTag, ImportedTag, Tag, Tags, TagExport; -export 'types.dart' show Types; -export 'instructions.dart' show Instructions; -export 'instruction.dart'; +export 'tables.dart' show Tables; +export 'tags.dart' show DefinedTag, ImportedTag, Tag, TagExport, Tags; export 'type.dart' show ArrayType, @@ -49,3 +48,4 @@ export 'type.dart' StorageType, StructType, ValueType; +export 'types.dart' show Types; diff --git a/pkg/wasm_builder/lib/src/ir/module.dart b/pkg/wasm_builder/lib/src/ir/module.dart index 5edc7ab0627..06850acce41 100644 --- a/pkg/wasm_builder/lib/src/ir/module.dart +++ b/pkg/wasm_builder/lib/src/ir/module.dart @@ -4,8 +4,8 @@ import 'dart:typed_data'; -import '../serialize/serialize.dart'; import '../serialize/printer.dart'; +import '../serialize/serialize.dart'; import 'ir.dart'; /// A logically const wasm module ready to encode. Created with `ModuleBuilder`. diff --git a/pkg/wasm_builder/lib/src/ir/table.dart b/pkg/wasm_builder/lib/src/ir/table.dart index 23d35b57a6a..64e6fe2165d 100644 --- a/pkg/wasm_builder/lib/src/ir/table.dart +++ b/pkg/wasm_builder/lib/src/ir/table.dart @@ -2,8 +2,8 @@ // 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 '../serialize/serialize.dart'; import '../serialize/printer.dart'; +import '../serialize/serialize.dart'; import 'ir.dart'; /// An (imported or defined) table. diff --git a/pkg/wasm_builder/lib/src/ir/tags.dart b/pkg/wasm_builder/lib/src/ir/tags.dart index 3851a7da9fe..03007ae7864 100644 --- a/pkg/wasm_builder/lib/src/ir/tags.dart +++ b/pkg/wasm_builder/lib/src/ir/tags.dart @@ -2,8 +2,8 @@ // 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 '../serialize/serialize.dart'; import '../serialize/printer.dart'; +import '../serialize/serialize.dart'; import 'ir.dart'; /// An exported tag from the current module. diff --git a/pkg/wasm_builder/lib/src/ir/type.dart b/pkg/wasm_builder/lib/src/ir/type.dart index 1393b5aa458..405d21d1811 100644 --- a/pkg/wasm_builder/lib/src/ir/type.dart +++ b/pkg/wasm_builder/lib/src/ir/type.dart @@ -2,8 +2,8 @@ // 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 '../serialize/serialize.dart'; import '../serialize/printer.dart'; +import '../serialize/serialize.dart'; // Representations of all Wasm types. diff --git a/pkg/wasm_builder/lib/src/serialize/deserializer.dart b/pkg/wasm_builder/lib/src/serialize/deserializer.dart index ad16384f5af..96773c0e97e 100644 --- a/pkg/wasm_builder/lib/src/serialize/deserializer.dart +++ b/pkg/wasm_builder/lib/src/serialize/deserializer.dart @@ -40,7 +40,7 @@ class Deserializer { } while ((byte & 0x80) != 0); if ((shift < 64) && ((byte & 0x40) != 0)) { - result |= (~0 << shift); + result |= ~0 << shift; } return result; diff --git a/pkg/wasm_builder/lib/src/serialize/printer.dart b/pkg/wasm_builder/lib/src/serialize/printer.dart index b1cac77cc53..16837942d86 100644 --- a/pkg/wasm_builder/lib/src/serialize/printer.dart +++ b/pkg/wasm_builder/lib/src/serialize/printer.dart @@ -2,8 +2,8 @@ // 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:typed_data'; import 'dart:collection'; +import 'dart:typed_data'; import '../ir/ir.dart' as ir; @@ -209,7 +209,7 @@ class ModulePrinter { mp.writeln('(module \$${_module.moduleName}'); mp.withIndent(() { final groups = _module.types.recursionGroups - .where((group) => group.any((t) => _types.containsKey(t))) + .where((group) => group.any(_types.containsKey)) .toList(); if (settings.printInSortedOrder) { groups.sort((a, b) { @@ -228,7 +228,7 @@ class ModulePrinter { } for (final group in groups) { - final filtered = group.where((t) => _types.containsKey(t)).toList(); + final filtered = group.where(_types.containsKey).toList(); if (filtered.isNotEmpty) { if (filtered.length == 1) { mp.write(_types[filtered.single]!); diff --git a/pkg/wasm_builder/lib/src/serialize/serialize.dart b/pkg/wasm_builder/lib/src/serialize/serialize.dart index f762b548f9e..032159f7038 100644 --- a/pkg/wasm_builder/lib/src/serialize/serialize.dart +++ b/pkg/wasm_builder/lib/src/serialize/serialize.dart @@ -2,6 +2,6 @@ // 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. -export 'serializer.dart' show Serializable, Serializer; export 'deserializer.dart' show Deserializer; export 'sections.dart'; +export 'serializer.dart' show Serializable, Serializer; diff --git a/pkg/wasm_builder/lib/wasm_builder.dart b/pkg/wasm_builder/lib/wasm_builder.dart index 80ee196f088..a303fc426c8 100644 --- a/pkg/wasm_builder/lib/wasm_builder.dart +++ b/pkg/wasm_builder/lib/wasm_builder.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. -export 'src/ir/ir.dart' - hide Catch, CatchAll, CatchRef, CatchAllRef, TryTableCatch; export 'src/builder/builder.dart'; +export 'src/ir/ir.dart' + hide Catch, CatchAll, CatchAllRef, CatchRef, TryTableCatch; export 'src/serialize/serialize.dart';