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

Use var/final consistently across repository #2502

Merged
merged 2 commits into from
Oct 3, 2024
Merged
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
9 changes: 5 additions & 4 deletions _analysis_config/lib/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@ linter:
- join_return_with_assignment
- library_names
- literal_only_boolean_expressions
- omit_local_variable_types
- only_throw_errors
- package_api_docs
- package_prefixed_library_names
# - prefer_final_locals
# - prefer_relative_imports
- prefer_final_in_for_each
- prefer_final_locals
- prefer_single_quotes
# - prefer_relative_imports
- prefer_void_to_null
- test_types_in_equals
- throw_in_finally
- omit_local_variable_types
- only_throw_errors
- unawaited_futures
- unnecessary_lambdas
- unnecessary_parenthesis
Expand Down
1 change: 0 additions & 1 deletion dwds/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ analyzer:
linter:
rules:
- always_use_package_imports
- prefer_final_locals
- require_trailing_commas
2 changes: 1 addition & 1 deletion dwds/debug_extension/web/detector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void _detectMultipleDartAppsCallback(
List<dynamic> mutations,
MutationObserver observer,
) {
for (var mutation in mutations) {
for (final mutation in mutations) {
if (_isMultipleAppsMutation(mutation)) {
_sendMessageToBackgroundScript(
type: MessageType.multipleAppsDetected,
Expand Down
2 changes: 1 addition & 1 deletion dwds/lib/src/debugging/classes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ClassHelper extends Domain {
classRefForString,
classRefForUnknown,
];
for (var classRef in staticClasses) {
for (final classRef in staticClasses) {
final classId = classRef.id;
if (classId != null) {
_classes[classId] = Class(
Expand Down
2 changes: 1 addition & 1 deletion dwds/lib/src/debugging/dart_scope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Future<List<Property>> visibleVariables({

// Iterate to least specific scope last to help preserve order in the local
// variables view when stepping.
for (var scope in filterScopes(frame).reversed) {
for (final scope in filterScopes(frame).reversed) {
final objectId = scope.object.objectId;
if (objectId != null) {
final properties = await inspector.getProperties(objectId);
Expand Down
8 changes: 4 additions & 4 deletions dwds/lib/src/debugging/inspector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ class AppInspector implements AppInspectorInterface {
// breakpoints. This is because the token positions are derived from the
// DDC source maps which Chrome also uses.
final tokenPositions = <int>[
for (var location in mappedLocations) location.tokenPos,
for (final location in mappedLocations) location.tokenPos,
];
tokenPositions.sort();

Expand Down Expand Up @@ -710,11 +710,11 @@ class AppInspector implements AppInspectorInterface {
// for them.
final userLibraries =
_userLibraryUris(isolate.libraries ?? <LibraryRef>[]);
for (var uri in userLibraries) {
for (final uri in userLibraries) {
final parts = scripts[uri];
final scriptRefs = [
ScriptRef(uri: uri, id: createId()),
for (var part in parts ?? []) ScriptRef(uri: part, id: createId()),
for (final part in parts ?? []) ScriptRef(uri: part, id: createId()),
];
final libraryRef = await _libraryHelper.libraryRefFor(uri);
final libraryId = libraryRef?.id;
Expand All @@ -723,7 +723,7 @@ class AppInspector implements AppInspectorInterface {
libraryId,
() => <ScriptRef>[],
);
for (var scriptRef in scriptRefs) {
for (final scriptRef in scriptRefs) {
final scriptId = scriptRef.id;
final scriptUri = scriptRef.uri;
if (scriptId != null && scriptUri != null) {
Expand Down
2 changes: 1 addition & 1 deletion dwds/lib/src/debugging/libraries.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class LibraryHelper extends Domain {
final libraries = await globalToolConfiguration.loadStrategy
.metadataProviderFor(inspector.appConnection.request.entrypointPath)
.libraries;
for (var library in libraries) {
for (final library in libraries) {
_libraryRefsById[library] =
LibraryRef(id: library, name: library, uri: library);
}
Expand Down
16 changes: 8 additions & 8 deletions dwds/lib/src/debugging/location.dart
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ class Locations {
int column,
) {
Location? bestLocation;
for (var location in locations) {
for (final location in locations) {
if (location.dartLocation.line == line &&
location.dartLocation.column >= column) {
bestLocation ??= location;
Expand Down Expand Up @@ -255,7 +255,7 @@ class Locations {
) {
column ??= 0;
Location? bestLocation;
for (var location in locations) {
for (final location in locations) {
if (location.jsLocation.compareToLine(line, column) <= 0) {
bestLocation ??= location;
if (location.jsLocation.compareTo(bestLocation.jsLocation) > 0) {
Expand All @@ -277,16 +277,16 @@ class Locations {
tokenPosTable = <List<int>>[];
final locations = await locationsForDart(serverPath);
final lineNumberToLocation = <int, Set<Location>>{};
for (var location in locations) {
for (final location in locations) {
lineNumberToLocation
.putIfAbsent(location.dartLocation.line, () => <Location>{})
.add(location);
}
for (var lineNumber in lineNumberToLocation.keys) {
for (final lineNumber in lineNumberToLocation.keys) {
final locations = lineNumberToLocation[lineNumber]!;
tokenPosTable.add([
lineNumber,
for (var location in locations) ...[
for (final location in locations) ...[
location.tokenPos,
location.dartLocation.column,
],
Expand Down Expand Up @@ -341,8 +341,8 @@ class Locations {
final mapping = parse(sourceMapContents);
if (mapping is SingleMapping) {
// Create TokenPos for each entry in the source map.
for (var lineEntry in mapping.lines) {
for (var entry in lineEntry.entries) {
for (final lineEntry in mapping.lines) {
for (final entry in lineEntry.entries) {
final location = _locationForSourceMapEntry(
lineEntry: lineEntry,
entry: entry,
Expand All @@ -357,7 +357,7 @@ class Locations {
}
}
}
for (var location in result) {
for (final location in result) {
_sourceToLocation
.putIfAbsent(
location.dartLocation.uri.serverPath,
Expand Down
4 changes: 2 additions & 2 deletions dwds/lib/src/debugging/metadata/module_metadata.dart
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class ModuleMetadata {
'\n ${ModuleMetadataVersion.previous.version}');
}

for (var l in _readRequiredList(json, 'libraries')) {
for (final l in _readRequiredList(json, 'libraries')) {
addLibrary(LibraryMetadata.fromJson(l as Map<String, dynamic>));
}
}
Expand All @@ -173,7 +173,7 @@ class ModuleMetadata {
'closureName': closureName,
'sourceMapUri': sourceMapUri,
'moduleUri': moduleUri,
'libraries': [for (var lib in libraries.values) lib.toJson()],
'libraries': [for (final lib in libraries.values) lib.toJson()],
'soundNullSafety': soundNullSafety,
};
}
Expand Down
8 changes: 4 additions & 4 deletions dwds/lib/src/debugging/metadata/provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class MetadataProvider {
final merged = await _assetReader.metadataContents(serverPath);
if (merged != null) {
_addSdkMetadata();
for (var contents in merged.split('\n')) {
for (final contents in merged.split('\n')) {
try {
if (contents.isEmpty ||
contents.startsWith('// intentionally empty:')) {
Expand Down Expand Up @@ -227,15 +227,15 @@ class MetadataProvider {
_modulePathToModule[modulePath] = metadata.name;
_moduleToModulePath[metadata.name] = modulePath;

for (var library in metadata.libraries.values) {
for (final library in metadata.libraries.values) {
if (library.importUri.startsWith('file:/')) {
throw AbsoluteImportUriException(library.importUri);
}
_libraries.add(library.importUri);
_scripts[library.importUri] = [];

_scriptToModule[library.importUri] = metadata.name;
for (var path in library.partUris) {
for (final path in library.partUris) {
// Parts in metadata are relative to the library Uri directory.
final partPath = p.url.join(p.dirname(library.importUri), path);
_scripts[library.importUri]!.add(partPath);
Expand All @@ -247,7 +247,7 @@ class MetadataProvider {
void _addSdkMetadata() {
final moduleName = 'dart_sdk';

for (var lib in sdkLibraries) {
for (final lib in sdkLibraries) {
_libraries.add(lib);
_scripts[lib] = [];
_scriptToModule[lib] = moduleName;
Expand Down
4 changes: 2 additions & 2 deletions dwds/lib/src/debugging/modules.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Modules {
final libraryToScripts = await provider.scripts;
final scriptToModule = await provider.scriptToModule;

for (var library in libraryToScripts.keys) {
for (final library in libraryToScripts.keys) {
final scripts = libraryToScripts[library]!;
final libraryServerPath = library.startsWith('dart:')
? library
Expand All @@ -93,7 +93,7 @@ class Modules {
_sourceToLibrary[libraryServerPath] = Uri.parse(library);
_libraryToModule[library] = module;

for (var script in scripts) {
for (final script in scripts) {
final scriptServerPath = script.startsWith('dart:')
? script
: DartUri(script, _root).serverPath;
Expand Down
2 changes: 1 addition & 1 deletion dwds/lib/src/debugging/skip_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class SkipLists {
final ranges = <Map<String, dynamic>>[];
var startLine = 0;
var startColumn = 0;
for (var location in sortedLocations) {
for (final location in sortedLocations) {
var endLine = location.jsLocation.line;
var endColumn = location.jsLocation.column;
// Stop before the known location.
Expand Down
2 changes: 1 addition & 1 deletion dwds/lib/src/dwds_vm_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ class DwdsVmClient {
return <String, Object>{
'result': <String, Object>{
'views': <Object>[
for (var isolate in isolates ?? [])
for (final isolate in isolates ?? [])
<String, Object>{
'id': isolate.id,
'isolate': isolate.toJson(),
Expand Down
10 changes: 5 additions & 5 deletions dwds/lib/src/handlers/dev_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ class DevHandler {
};

Future<void> close() => _closed ??= () async {
for (var sub in _subs) {
for (final sub in _subs) {
await sub.cancel();
}
for (var handler in _sseHandlers.values) {
for (final handler in _sseHandlers.values) {
handler.shutdown();
}
await Future.wait(
Expand All @@ -123,7 +123,7 @@ class DevHandler {

void _emitBuildResults(BuildResult result) {
if (result.status != BuildStatus.succeeded) return;
for (var injectedConnection in _injectedConnections) {
for (final injectedConnection in _injectedConnections) {
injectedConnection.sink.add(jsonEncode(serializers.serialize(result)));
}
}
Expand All @@ -137,7 +137,7 @@ class DevHandler {
ExecutionContext? executionContext;
WipConnection? tabConnection;
final appInstanceId = appConnection.request.instanceId;
for (var tab in await chromeConnection.getTabs()) {
for (final tab in await chromeConnection.getTabs()) {
if (tab.isChromeExtension || tab.isBackgroundPage) continue;

final connection = tabConnection = await tab.connect();
Expand All @@ -162,7 +162,7 @@ class DevHandler {
// before events are received.
safeUnawaited(Future.microtask(connection.runtime.enable));

await for (var contextId in contextIds) {
await for (final contextId in contextIds) {
final result = await connection.sendCommand('Runtime.evaluate', {
'expression': r'window["$dartAppInstanceId"];',
'contextId': contextId,
Expand Down
6 changes: 3 additions & 3 deletions dwds/lib/src/loaders/build_runner_require.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class BuildRunnerRequireStrategyProvider {
}

return {
for (var entry in digests.entries)
for (final entry in digests.entries)
if (modules.containsKey(entry.key))
modules[entry.key]!: entry.value as String,
};
Expand All @@ -88,7 +88,7 @@ class BuildRunnerRequireStrategyProvider {
) async {
final modulePathToModule = await metadataProvider.modulePathToModule;
final relativePath = stripLeadingSlashes(serverPath);
for (var e in modulePathToModule.entries) {
for (final e in modulePathToModule.entries) {
if (stripTopLevelDirectory(e.key) == relativePath) {
return e.value;
}
Expand Down Expand Up @@ -129,7 +129,7 @@ class BuildRunnerRequireStrategyProvider {
) async {
final modules = await metadataProvider.modules;
final result = <String, ModuleInfo>{};
for (var module in modules) {
for (final module in modules) {
final serverPath = await _serverPathForModule(metadataProvider, module);
if (serverPath == null) {
_logger.warning('No module info found for module $module');
Expand Down
2 changes: 1 addition & 1 deletion dwds/lib/src/loaders/frontend_server_ddc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class FrontendServerDdcStrategyProvider {
) async {
final modules = await metadataProvider.moduleToModulePath;
final result = <String, ModuleInfo>{};
for (var module in modules.keys) {
for (final module in modules.keys) {
final modulePath = modules[module]!;
result[module] = ModuleInfo(
// TODO: Save locations of full kernel files in ddc metadata.
Expand Down
2 changes: 1 addition & 1 deletion dwds/lib/src/loaders/frontend_server_require.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class FrontendServerRequireStrategyProvider {
) async {
final modules = await metadataProvider.moduleToModulePath;
final result = <String, ModuleInfo>{};
for (var module in modules.keys) {
for (final module in modules.keys) {
final modulePath = modules[module]!;
result[module] = ModuleInfo(
// TODO: Save locations of full kernel files in ddc metadata.
Expand Down
2 changes: 1 addition & 1 deletion dwds/lib/src/readers/frontend_server_asset_reader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class FrontendServerAssetReader implements AssetReader {
final sourceContents = map.readAsBytesSync();
final sourceInfo =
jsonDecode(json.readAsStringSync()) as Map<String, dynamic>;
for (var key in sourceInfo.keys) {
for (final key in sourceInfo.keys) {
final info = sourceInfo[key];
_mapContents[key] = utf8.decode(
sourceContents
Expand Down
2 changes: 1 addition & 1 deletion dwds/lib/src/servers/extension_debugger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class ExtensionDebugger implements RemoteDebugger {
_notificationController.sink.add(WipEvent(map));
}
} else if (message is BatchedEvents) {
for (var event in message.events) {
for (final event in message.events) {
final map = {
'method': json.decode(event.method),
'params': json.decode(event.params),
Expand Down
2 changes: 1 addition & 1 deletion dwds/lib/src/services/batched_expression_evaluator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class BatchedExpressionEvaluator extends ExpressionEvaluator {
Map<String, String>? scope;
var currentRequests = <EvaluateRequest>[];

for (var request in requests) {
for (final request in requests) {
libraryUri ??= request.libraryUri;
isolateId ??= request.isolateId;
scope ??= request.scope;
Expand Down
8 changes: 4 additions & 4 deletions dwds/lib/src/services/chrome_proxy_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ class ChromeProxyService implements VmServiceInterface {
// TODO: We shouldn't need to fire these events since they exist on the
// isolate, but devtools doesn't recognize extensions after a page refresh
// otherwise.
for (var extensionRpc in inspector.isolate.extensionRPCs ?? []) {
for (final extensionRpc in inspector.isolate.extensionRPCs ?? []) {
_streamNotify(
'Isolate',
Event(
Expand Down Expand Up @@ -411,7 +411,7 @@ class ChromeProxyService implements VmServiceInterface {
if (!_isIsolateRunning) return;
final isolate = inspector.isolate;

for (var breakpoint in isolate.breakpoints?.toList() ?? []) {
for (final breakpoint in isolate.breakpoints?.toList() ?? []) {
await (await debuggerFuture).removeBreakpoint(breakpoint.id);
}
}
Expand Down Expand Up @@ -1429,7 +1429,7 @@ ${globalToolConfiguration.loadStrategy.loadModuleSnippet}("dart_sdk").developer.
/// Parses the [BatchedDebugEvents] and emits corresponding Dart VM Service
/// protocol [Event]s.
void parseBatchedDebugEvents(BatchedDebugEvents debugEvents) {
for (var debugEvent in debugEvents.events) {
for (final debugEvent in debugEvents.events) {
parseDebugEvent(debugEvent);
}
}
Expand Down Expand Up @@ -1590,7 +1590,7 @@ ${globalToolConfiguration.loadStrategy.loadModuleSnippet}("dart_sdk").developer.

Map<String, RemoteObject> _fetchAbbreviatedLogParams(Map? logObject) {
final logParams = <String, RemoteObject>{};
for (dynamic property in logObject?['preview']?['properties'] ?? []) {
for (final dynamic property in logObject?['preview']?['properties'] ?? []) {
if (property is Map<String, dynamic> && property['name'] != null) {
logParams[property['name'] as String] = RemoteObject(property);
}
Expand Down
Loading
Loading