Turn on avoid_dynamic_calls lint, except packages/flutter tests, make appropriate changes. (#84476)
This adds avoid_dynamic_calls to the list of lints, and fixes all instances where it was violated. Importantly, this lint is NOT turned on for flutter/packages/test, because those changes are happening in another PR: #84478
This commit is contained in:
@@ -52,13 +52,14 @@ void main() {
|
||||
|
||||
expect(testLogger.statusText, isNotEmpty);
|
||||
final dynamic jsonObject = json.decode(testLogger.statusText);
|
||||
expect(jsonObject, isMap);
|
||||
expect(jsonObject, const TypeMatcher<Map<String, dynamic>>());
|
||||
if (jsonObject is Map<String, dynamic>) {
|
||||
expect(jsonObject.containsKey('android-studio-dir'), true);
|
||||
expect(jsonObject['android-studio-dir'], isNotNull);
|
||||
|
||||
expect(jsonObject.containsKey('android-studio-dir'), true);
|
||||
expect(jsonObject['android-studio-dir'], isNotNull);
|
||||
|
||||
expect(jsonObject.containsKey('android-sdk'), true);
|
||||
expect(jsonObject['android-sdk'], isNotNull);
|
||||
expect(jsonObject.containsKey('android-sdk'), true);
|
||||
expect(jsonObject['android-sdk'], isNotNull);
|
||||
}
|
||||
verifyNoAnalytics();
|
||||
}, overrides: <Type, Generator>{
|
||||
AndroidStudio: () => fakeAndroidStudio,
|
||||
|
||||
@@ -93,7 +93,7 @@ void main() {
|
||||
|
||||
expect(response['id'], 0);
|
||||
expect(response['result'], isNotEmpty);
|
||||
expect(response['result']['platforms'], <String>{'macos'});
|
||||
expect((response['result'] as Map<String, dynamic>)['platforms'], <String>{'macos'});
|
||||
await responses.close();
|
||||
await commands.close();
|
||||
}, overrides: <Type, Generator>{
|
||||
@@ -111,7 +111,7 @@ void main() {
|
||||
);
|
||||
globals.printError('daemon.logMessage test');
|
||||
final Map<String, dynamic> response = await responses.stream.firstWhere((Map<String, dynamic> map) {
|
||||
return map['event'] == 'daemon.logMessage' && map['params']['level'] == 'error';
|
||||
return map['event'] == 'daemon.logMessage' && (map['params'] as Map<String, dynamic>)['level'] == 'error';
|
||||
});
|
||||
expect(response['id'], isNull);
|
||||
expect(response['event'], 'daemon.logMessage');
|
||||
@@ -347,7 +347,7 @@ void main() {
|
||||
unawaited(output.stream
|
||||
.firstWhere((Map<String, dynamic> request) => request['method'] == 'app.exposeUrl')
|
||||
.then((Map<String, dynamic> request) {
|
||||
expect(request['params']['url'], equals(originalUrl));
|
||||
expect((request['params'] as Map<String, dynamic>)['url'], equals(originalUrl));
|
||||
input.add(<String, dynamic>{'id': request['id'], 'result': <String, dynamic>{'url': mappedUrl}});
|
||||
})
|
||||
);
|
||||
@@ -370,9 +370,10 @@ void main() {
|
||||
|
||||
commands.add(<String, dynamic>{'id': 0, 'method': 'devtools.serve'});
|
||||
final Map<String, dynamic> response = await responses.stream.firstWhere((Map<String, dynamic> response) => response['id'] == 0);
|
||||
expect(response['result'], isNotEmpty);
|
||||
expect(response['result']['host'], '127.0.0.1');
|
||||
expect(response['result']['port'], 1234);
|
||||
final Map<String, dynamic> result = response['result'] as Map<String, dynamic>;
|
||||
expect(result, isNotEmpty);
|
||||
expect(result['host'], '127.0.0.1');
|
||||
expect(result['port'], 1234);
|
||||
await responses.close();
|
||||
await commands.close();
|
||||
}, overrides: <Type, Generator>{
|
||||
@@ -390,9 +391,10 @@ void main() {
|
||||
|
||||
commands.add(<String, dynamic>{'id': 0, 'method': 'devtools.serve'});
|
||||
final Map<String, dynamic> response = await responses.stream.firstWhere((Map<String, dynamic> response) => response['id'] == 0);
|
||||
expect(response['result'], isNotEmpty);
|
||||
expect(response['result']['host'], null);
|
||||
expect(response['result']['port'], null);
|
||||
final Map<String, dynamic> result = response['result'] as Map<String, dynamic>;
|
||||
expect(result, isNotEmpty);
|
||||
expect(result['host'], null);
|
||||
expect(result['port'], null);
|
||||
await responses.close();
|
||||
await commands.close();
|
||||
}, overrides: <Type, Generator>{
|
||||
|
||||
@@ -28,6 +28,7 @@ import 'package:process/process.dart';
|
||||
import 'package:pub_semver/pub_semver.dart';
|
||||
import 'package:pubspec_parse/pubspec_parse.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
import 'package:yaml/yaml.dart';
|
||||
|
||||
import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
@@ -482,8 +483,9 @@ void main() {
|
||||
// Expect the dependency on flutter_web_plugins exists
|
||||
expect(pubspec.dependencies, contains('flutter_web_plugins'));
|
||||
// The platform is correctly registered
|
||||
expect(pubspec.flutter['plugin']['platforms']['web']['pluginClass'], 'FlutterProjectWeb');
|
||||
expect(pubspec.flutter['plugin']['platforms']['web']['fileName'], 'flutter_project_web.dart');
|
||||
final YamlMap web = ((pubspec.flutter['plugin'] as YamlMap)['platforms'] as YamlMap)['web'] as YamlMap;
|
||||
expect(web['pluginClass'], 'FlutterProjectWeb');
|
||||
expect(web['fileName'], 'flutter_project_web.dart');
|
||||
expect(logger.errorText, isNot(contains(_kNoPlatformsMessage)));
|
||||
}, overrides: <Type, Generator>{
|
||||
FeatureFlags: () => TestFeatureFlags(isWebEnabled: true),
|
||||
|
||||
@@ -90,47 +90,54 @@ void main() {
|
||||
);
|
||||
|
||||
expect(result['type'], 'apk');
|
||||
|
||||
final Map<String, dynamic> androidManifestMap = result['children'][0] as Map<String, dynamic>;
|
||||
final List<dynamic> resultChildren = result['children'] as List<dynamic>;
|
||||
final Map<String, dynamic> androidManifestMap = resultChildren[0] as Map<String, dynamic>;
|
||||
expect(androidManifestMap['n'], 'AndroidManifest.xml');
|
||||
expect(androidManifestMap['value'], 6);
|
||||
|
||||
final Map<String, dynamic> metaInfMap = result['children'][1] as Map<String, dynamic>;
|
||||
final Map<String, Object?> metaInfMap = resultChildren[1] as Map<String, Object?>;
|
||||
final List<Map<String, Object?>> metaInfMapChildren = metaInfMap['children']! as List<Map<String, Object?>>;
|
||||
expect(metaInfMap['n'], 'META-INF');
|
||||
expect(metaInfMap['value'], 10);
|
||||
final Map<String, dynamic> certRsaMap = metaInfMap['children'][0] as Map<String, dynamic>;
|
||||
final Map<String, dynamic> certRsaMap = metaInfMapChildren[0];
|
||||
expect(certRsaMap['n'], 'CERT.RSA');
|
||||
expect(certRsaMap['value'], 5);
|
||||
final Map<String, dynamic> certSfMap = metaInfMap['children'][1] as Map<String, dynamic>;
|
||||
final Map<String, dynamic> certSfMap = metaInfMapChildren[1];
|
||||
expect(certSfMap['n'], 'CERT.SF');
|
||||
expect(certSfMap['value'], 5);
|
||||
|
||||
final Map<String, dynamic> libMap = result['children'][2] as Map<String, dynamic>;
|
||||
final Map<String, Object?> libMap = resultChildren[2] as Map<String, Object?>;
|
||||
final List<Map<String, Object?>> libMapChildren = libMap['children']! as List<Map<String, Object?>>;
|
||||
expect(libMap['n'], 'lib');
|
||||
expect(libMap['value'], 12);
|
||||
final Map<String, dynamic> arm64Map = libMap['children'][0] as Map<String, dynamic>;
|
||||
final Map<String, Object?> arm64Map = libMapChildren[0];
|
||||
final List<Map<String, Object?>> arn64MapChildren = arm64Map['children']! as List<Map<String, Object?>>;
|
||||
expect(arm64Map['n'], 'arm64-v8a');
|
||||
expect(arm64Map['value'], 12);
|
||||
final Map<String, dynamic> libAppMap = arm64Map['children'][0] as Map<String, dynamic>;
|
||||
final Map<String, Object?> libAppMap = arn64MapChildren[0];
|
||||
final List<dynamic> libAppMapChildren = libAppMap['children']! as List<dynamic>;
|
||||
expect(libAppMap['n'], 'libxyzzyapp.so (Dart AOT)');
|
||||
expect(libAppMap['value'], 6);
|
||||
expect(libAppMap['children'].length, 3);
|
||||
final Map<String, dynamic> internalMap = libAppMap['children'][0] as Map<String, dynamic>;
|
||||
final Map<String, dynamic> skipMap = internalMap['children'][0] as Map<String, dynamic>;
|
||||
expect(libAppMapChildren.length, 3);
|
||||
final Map<String, Object?> internalMap = libAppMapChildren[0] as Map<String, Object?>;
|
||||
final List<dynamic> internalMapChildren = internalMap['children']! as List<dynamic>;
|
||||
final Map<String, Object?> skipMap = internalMapChildren[0] as Map<String, Object?>;
|
||||
expect(skipMap['n'], 'skip');
|
||||
expect(skipMap['value'], 2400);
|
||||
final Map<String, dynamic> subListIterableMap = internalMap['children'][1] as Map<String, dynamic>;
|
||||
final Map<String, Object?> subListIterableMap = internalMapChildren[1] as Map<String, Object?>;
|
||||
expect(subListIterableMap['n'], 'new SubListIterable.');
|
||||
expect(subListIterableMap['value'], 3560);
|
||||
final Map<String, dynamic> coreMap = libAppMap['children'][1] as Map<String, dynamic>;
|
||||
final Map<String, dynamic> rangeErrorMap = coreMap['children'][0] as Map<String, dynamic>;
|
||||
final Map<String, Object?> coreMap = libAppMapChildren[1] as Map<String, Object?>;
|
||||
final List<dynamic> coreMapChildren = coreMap['children']! as List<dynamic>;
|
||||
final Map<String, Object?> rangeErrorMap = coreMapChildren[0] as Map<String, Object?>;
|
||||
expect(rangeErrorMap['n'], 'new RangeError.range');
|
||||
expect(rangeErrorMap['value'], 3920);
|
||||
final Map<String, dynamic> stubsMap = libAppMap['children'][2] as Map<String, dynamic>;
|
||||
final Map<String, dynamic> allocateMap = stubsMap['children'][0] as Map<String, dynamic>;
|
||||
final Map<String, Object?> stubsMap = libAppMapChildren[2] as Map<String, Object?>;
|
||||
final List<dynamic> stubsMapChildren = stubsMap['children']! as List<dynamic>;
|
||||
final Map<String, Object?> allocateMap = stubsMapChildren[0] as Map<String, Object?>;
|
||||
expect(allocateMap['n'], 'Allocate ArgumentError');
|
||||
expect(allocateMap['value'], 4650);
|
||||
final Map<String, dynamic> libFlutterMap = arm64Map['children'][1] as Map<String, dynamic>;
|
||||
final Map<String, Object?> libFlutterMap = arn64MapChildren[1];
|
||||
expect(libFlutterMap['n'], 'libflutter.so (Flutter Engine)');
|
||||
expect(libFlutterMap['value'], 6);
|
||||
|
||||
|
||||
@@ -104,9 +104,10 @@ void main() {
|
||||
final Fingerprint fingerprint = Fingerprint.fromBuildInputs(const <String>['a.dart', 'b.dart'], fileSystem);
|
||||
|
||||
final Map<String, dynamic>? jsonObject = castStringKeyedMap(json.decode(fingerprint.toJson()));
|
||||
expect(jsonObject!['files'], hasLength(2));
|
||||
expect(jsonObject['files']['a.dart'], '8a21a15fad560b799f6731d436c1b698');
|
||||
expect(jsonObject['files']['b.dart'], '6f144e08b58cd0925328610fad7ac07c');
|
||||
final Map<String, dynamic> files = jsonObject!['files'] as Map<String, dynamic>;
|
||||
expect(files, hasLength(2));
|
||||
expect(files['a.dart'], '8a21a15fad560b799f6731d436c1b698');
|
||||
expect(files['b.dart'], '6f144e08b58cd0925328610fad7ac07c');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -124,10 +125,11 @@ void main() {
|
||||
});
|
||||
final Fingerprint fingerprint = Fingerprint.fromJson(jsonString);
|
||||
final Map<String, dynamic>? content = castStringKeyedMap(json.decode(fingerprint.toJson()));
|
||||
final Map<String, dynamic> files = content!['files'] as Map<String, dynamic>;
|
||||
expect(content, hasLength(1));
|
||||
expect(content!['files'], hasLength(2));
|
||||
expect(content['files']['a.dart'], '8a21a15fad560b799f6731d436c1b698');
|
||||
expect(content['files']['b.dart'], '6f144e08b58cd0925328610fad7ac07c');
|
||||
expect(files, hasLength(2));
|
||||
expect(files['a.dart'], '8a21a15fad560b799f6731d436c1b698');
|
||||
expect(files['b.dart'], '6f144e08b58cd0925328610fad7ac07c');
|
||||
});
|
||||
testWithoutContext('treats missing properties and files entries as if empty', () {
|
||||
final String jsonString = json.encode(<String, dynamic>{});
|
||||
|
||||
@@ -284,7 +284,7 @@ void main() {
|
||||
version: 1.0.0+3
|
||||
''', logger: BufferLogger.test());
|
||||
final FlutterProject project = FlutterProject(fileSystem.systemTempDirectory,manifest,manifest);
|
||||
final dynamic versionInfo = jsonDecode(project.getVersionInfo());
|
||||
final Map<String, dynamic> versionInfo = jsonDecode(project.getVersionInfo()) as Map<String, dynamic>;
|
||||
expect(versionInfo['app_name'],'test');
|
||||
expect(versionInfo['version'],'1.0.0');
|
||||
expect(versionInfo['build_number'],'3');
|
||||
|
||||
@@ -81,7 +81,7 @@ void main() {
|
||||
]);
|
||||
|
||||
// contains all of the experiments in features.dart
|
||||
expect(result.stdout.split('\n'), containsAll(<Matcher>[
|
||||
expect((result.stdout as String).split('\n'), containsAll(<Matcher>[
|
||||
for (final Feature feature in allFeatures)
|
||||
contains(feature.configSetting),
|
||||
]));
|
||||
|
||||
@@ -35,8 +35,8 @@ void main() {
|
||||
.childDirectory('.dart_tool')
|
||||
.childFile('package_config.json')
|
||||
.readAsStringSync());
|
||||
final dynamic collection = jsonContent['packages']
|
||||
.firstWhere((dynamic e) => e['name'] == 'collection');
|
||||
final Map<String, dynamic> collection = ((jsonContent as Map<String, dynamic>)['packages'] as Iterable<dynamic>)
|
||||
.firstWhere((dynamic entry) => (entry as Map<String, dynamic>)['name'] == 'collection') as Map<String, dynamic>;
|
||||
expect(
|
||||
Uri.parse(collection['rootUri'] as String).isAbsolute,
|
||||
isTrue,
|
||||
|
||||
@@ -190,6 +190,6 @@ bool _isHotReloadCompletionEvent(Map<String, dynamic> event) {
|
||||
return event != null &&
|
||||
event['event'] == 'app.progress' &&
|
||||
event['params'] != null &&
|
||||
event['params']['progressId'] == 'hot.reload' &&
|
||||
event['params']['finished'] == true;
|
||||
(event['params'] as Map<String, dynamic>)['progressId'] == 'hot.reload' &&
|
||||
(event['params'] as Map<String, dynamic>)['finished'] == true;
|
||||
}
|
||||
|
||||
@@ -387,11 +387,14 @@ abstract class FlutterTestDriver {
|
||||
await subscription.cancel();
|
||||
final StringBuffer error = StringBuffer();
|
||||
error.write('Received app.stop event while waiting for $interestingOccurrence\n\n$_errorBuffer');
|
||||
if (json['params'] != null && json['params']['error'] != null) {
|
||||
error.write('${json['params']['error']}\n\n');
|
||||
}
|
||||
if (json['params'] != null && json['params']['trace'] != null) {
|
||||
error.write('${json['params']['trace']}\n\n');
|
||||
if (json['params'] != null) {
|
||||
final Map<String, dynamic> params = json['params'] as Map<String, dynamic>;
|
||||
if (params['error'] != null) {
|
||||
error.write('${params['error']}\n\n');
|
||||
}
|
||||
if (json['params'] != null && params['trace'] != null) {
|
||||
error.write('${params['trace']}\n\n');
|
||||
}
|
||||
}
|
||||
response.completeError(Exception(error.toString()));
|
||||
}
|
||||
@@ -563,7 +566,7 @@ class FlutterRunTestDriver extends FlutterTestDriver {
|
||||
// _process.kill() (`flutter` is a shell script so _process itself is a
|
||||
// shell, not the flutter tool's Dart process).
|
||||
final Map<String, dynamic> connected = await _waitFor(event: 'daemon.connected');
|
||||
_processPid = connected['params']['pid'] as int;
|
||||
_processPid = (connected['params'] as Map<String, dynamic>)['pid'] as int;
|
||||
|
||||
// Set this up now, but we don't wait it yet. We want to make sure we don't
|
||||
// miss it while waiting for debugPort below.
|
||||
@@ -571,7 +574,7 @@ class FlutterRunTestDriver extends FlutterTestDriver {
|
||||
|
||||
if (withDebugger) {
|
||||
final Map<String, dynamic> debugPort = await _waitFor(event: 'app.debugPort', timeout: appStartTimeout);
|
||||
final String wsUriString = debugPort['params']['wsUri'] as String;
|
||||
final String wsUriString = (debugPort['params'] as Map<String, dynamic>)['wsUri'] as String;
|
||||
_vmServiceWsUri = Uri.parse(wsUriString);
|
||||
await connectToVmService(pauseOnExceptions: pauseOnExceptions);
|
||||
if (!startPaused) {
|
||||
@@ -588,7 +591,7 @@ class FlutterRunTestDriver extends FlutterTestDriver {
|
||||
|
||||
// Now await the started event; if it had already happened the future will
|
||||
// have already completed.
|
||||
_currentRunningAppId = (await started)['params']['appId'] as String;
|
||||
_currentRunningAppId = ((await started)['params'] as Map<String, dynamic>)['appId'] as String;
|
||||
prematureExitGuard.complete();
|
||||
} on Exception catch (error, stackTrace) {
|
||||
prematureExitGuard.completeError(Exception(error.toString()), stackTrace);
|
||||
@@ -618,10 +621,10 @@ class FlutterRunTestDriver extends FlutterTestDriver {
|
||||
}
|
||||
|
||||
_debugPrint('Performing ${ pause ? "paused " : "" }${ fullRestart ? "hot restart" : "hot reload" }...');
|
||||
final dynamic hotReloadResponse = await _sendRequest(
|
||||
final Map<String, dynamic> hotReloadResponse = await _sendRequest(
|
||||
'app.restart',
|
||||
<String, dynamic>{'appId': _currentRunningAppId, 'fullRestart': fullRestart, 'pause': pause, 'debounce': debounce, 'debounceDurationOverrideMs': debounceDurationOverrideMs},
|
||||
);
|
||||
) as Map<String, dynamic>;
|
||||
_debugPrint('${fullRestart ? "Hot restart" : "Hot reload"} complete.');
|
||||
|
||||
if (hotReloadResponse == null || hotReloadResponse['code'] != 0) {
|
||||
@@ -760,8 +763,9 @@ class FlutterTestTestDriver extends FlutterTestDriver {
|
||||
_processPid = version['pid'] as int;
|
||||
|
||||
if (withDebugger) {
|
||||
final Map<String, dynamic> startedProcess = await _waitFor(event: 'test.startedProcess', timeout: appStartTimeout);
|
||||
final String vmServiceHttpString = startedProcess['params']['observatoryUri'] as String;
|
||||
final Map<String, dynamic> startedProcessParams =
|
||||
(await _waitFor(event: 'test.startedProcess', timeout: appStartTimeout))['params'] as Map<String, dynamic>;
|
||||
final String vmServiceHttpString = startedProcessParams['observatoryUri'] as String;
|
||||
_vmServiceWsUri = Uri.parse(vmServiceHttpString).replace(scheme: 'ws', path: '/ws');
|
||||
await connectToVmService(pauseOnExceptions: pauseOnExceptions);
|
||||
// Allow us to run code before we start, eg. to set up breakpoints.
|
||||
@@ -824,7 +828,7 @@ Stream<String> transformToLines(Stream<List<int>> byteStream) {
|
||||
Map<String, dynamic> parseFlutterResponse(String line) {
|
||||
if (line.startsWith('[') && line.endsWith(']') && line.length > 2) {
|
||||
try {
|
||||
final Map<String, dynamic> response = castStringKeyedMap(json.decode(line)[0]);
|
||||
final Map<String, dynamic> response = castStringKeyedMap((json.decode(line) as List<dynamic>)[0]);
|
||||
return response;
|
||||
} on FormatException {
|
||||
// Not valid JSON, so likely some other output that was surrounded by [brackets]
|
||||
|
||||
@@ -19,18 +19,19 @@ void validatePubspecForPlugin({
|
||||
}) {
|
||||
final FlutterManifest manifest =
|
||||
FlutterManifest.createFromPath('$projectDir/pubspec.yaml', fileSystem: globals.fs, logger: globals.logger)!;
|
||||
final YamlMap platformsMap = YamlMap.wrap(manifest.supportedPlatforms!);
|
||||
final YamlMap platformMaps = YamlMap.wrap(manifest.supportedPlatforms!);
|
||||
for (final String platform in expectedPlatforms) {
|
||||
expect(platformsMap[platform], isNotNull);
|
||||
expect(platformsMap[platform]['pluginClass'], pluginClass);
|
||||
expect(platformMaps[platform], isNotNull);
|
||||
final YamlMap platformMap = platformMaps[platform]! as YamlMap;
|
||||
expect(platformMap['pluginClass'], pluginClass);
|
||||
if (platform == 'android') {
|
||||
expect(platformsMap[platform]['package'], androidIdentifier);
|
||||
expect(platformMap['package'], androidIdentifier);
|
||||
}
|
||||
if (platform == 'web') {
|
||||
expect(platformsMap[platform]['fileName'], webFileName);
|
||||
expect(platformMap['fileName'], webFileName);
|
||||
}
|
||||
}
|
||||
for (final String platform in unexpectedPlatforms) {
|
||||
expect(platformsMap[platform], isNull);
|
||||
expect(platformMaps[platform], isNull);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user