mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
[flutter_tools] add package:http to forbidden imports test (#75925)
This commit is contained in:
parent
486ba89318
commit
fb808b40f9
@ -7,7 +7,6 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:args/command_runner.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:intl/intl.dart' as intl;
|
||||
import 'package:intl/intl_standalone.dart' as intl_standalone;
|
||||
|
||||
@ -136,7 +135,6 @@ Future<int> _handleToolError(
|
||||
globals.flutterUsage.sendException(error);
|
||||
await asyncGuard(() async {
|
||||
final CrashReportSender crashReportSender = CrashReportSender(
|
||||
client: http.Client(),
|
||||
usage: globals.flutterUsage,
|
||||
platform: globals.platform,
|
||||
logger: globals.logger,
|
||||
|
@ -97,12 +97,12 @@ class CrashReporter {
|
||||
/// wish to use your own server for collecting crash reports from Flutter Tools.
|
||||
class CrashReportSender {
|
||||
CrashReportSender({
|
||||
@required http.Client client,
|
||||
http.Client client,
|
||||
@required Usage usage,
|
||||
@required Platform platform,
|
||||
@required Logger logger,
|
||||
@required OperatingSystemUtils operatingSystemUtils,
|
||||
}) : _client = client,
|
||||
}) : _client = client ?? http.Client(),
|
||||
_usage = usage,
|
||||
_platform = platform,
|
||||
_logger = logger,
|
||||
|
@ -86,6 +86,31 @@ void main() {
|
||||
}
|
||||
});
|
||||
|
||||
test('no unauthorized imports of package:http', () {
|
||||
final List<String> allowedPaths = <String>[
|
||||
// Used only for multi-part file uploads, which are non-trivial to reimplement.
|
||||
fileSystem.path.join(flutterTools, 'lib', 'src', 'reporting', 'reporting.dart'),
|
||||
];
|
||||
bool _isNotAllowed(FileSystemEntity entity) => allowedPaths.every((String path) => path != entity.path);
|
||||
|
||||
for (final String dirName in <String>['lib', 'bin']) {
|
||||
final Iterable<File> files = fileSystem.directory(fileSystem.path.join(flutterTools, dirName))
|
||||
.listSync(recursive: true)
|
||||
.where(_isDartFile)
|
||||
.where(_isNotAllowed)
|
||||
.map(_asFile);
|
||||
for (final File file in files) {
|
||||
for (final String line in file.readAsLinesSync()) {
|
||||
if (line.startsWith(RegExp(r'import.*package:http/')) &&
|
||||
!line.contains('ignore: package_http_import')) {
|
||||
final String relativePath = fileSystem.path.relative(file.path, from:flutterTools);
|
||||
fail("$relativePath imports 'package:http'; import 'lib/src/base/io.dart' instead");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('no unauthorized imports of test_api', () {
|
||||
final List<String> allowedPaths = <String>[
|
||||
fileSystem.path.join(flutterTools, 'lib', 'src', 'test', 'flutter_platform.dart'),
|
||||
|
Loading…
Reference in New Issue
Block a user