flutter/packages/flutter_tools/test/src/pubspec_schema.dart
Greg Spencer 88f3811055
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
2021-06-14 14:16:57 -07:00

38 lines
1.4 KiB
Dart

// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter_tools/src/flutter_manifest.dart';
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
import 'package:yaml/yaml.dart';
import 'common.dart';
/// Check if the pubspec.yaml file under the `projectDir` is valid for a plugin project.
void validatePubspecForPlugin({
required String projectDir,
required String pluginClass,
required List<String> expectedPlatforms,
List<String> unexpectedPlatforms = const <String>[],
String? androidIdentifier,
String? webFileName,
}) {
final FlutterManifest manifest =
FlutterManifest.createFromPath('$projectDir/pubspec.yaml', fileSystem: globals.fs, logger: globals.logger)!;
final YamlMap platformMaps = YamlMap.wrap(manifest.supportedPlatforms!);
for (final String platform in expectedPlatforms) {
expect(platformMaps[platform], isNotNull);
final YamlMap platformMap = platformMaps[platform]! as YamlMap;
expect(platformMap['pluginClass'], pluginClass);
if (platform == 'android') {
expect(platformMap['package'], androidIdentifier);
}
if (platform == 'web') {
expect(platformMap['fileName'], webFileName);
}
}
for (final String platform in unexpectedPlatforms) {
expect(platformMaps[platform], isNull);
}
}