Skip to content

Commit fb808b4

Browse files
author
Jonah Williams
authored
[flutter_tools] add package:http to forbidden imports test (flutter#75925)
1 parent 486ba89 commit fb808b4

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

packages/flutter_tools/lib/runner.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import 'dart:async';
88

99
import 'package:args/command_runner.dart';
10-
import 'package:http/http.dart' as http;
1110
import 'package:intl/intl.dart' as intl;
1211
import 'package:intl/intl_standalone.dart' as intl_standalone;
1312

@@ -136,7 +135,6 @@ Future<int> _handleToolError(
136135
globals.flutterUsage.sendException(error);
137136
await asyncGuard(() async {
138137
final CrashReportSender crashReportSender = CrashReportSender(
139-
client: http.Client(),
140138
usage: globals.flutterUsage,
141139
platform: globals.platform,
142140
logger: globals.logger,

packages/flutter_tools/lib/src/reporting/crash_reporting.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,12 @@ class CrashReporter {
9797
/// wish to use your own server for collecting crash reports from Flutter Tools.
9898
class CrashReportSender {
9999
CrashReportSender({
100-
@required http.Client client,
100+
http.Client client,
101101
@required Usage usage,
102102
@required Platform platform,
103103
@required Logger logger,
104104
@required OperatingSystemUtils operatingSystemUtils,
105-
}) : _client = client,
105+
}) : _client = client ?? http.Client(),
106106
_usage = usage,
107107
_platform = platform,
108108
_logger = logger,

packages/flutter_tools/test/integration.shard/forbidden_imports_test.dart

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,31 @@ void main() {
8686
}
8787
});
8888

89+
test('no unauthorized imports of package:http', () {
90+
final List<String> allowedPaths = <String>[
91+
// Used only for multi-part file uploads, which are non-trivial to reimplement.
92+
fileSystem.path.join(flutterTools, 'lib', 'src', 'reporting', 'reporting.dart'),
93+
];
94+
bool _isNotAllowed(FileSystemEntity entity) => allowedPaths.every((String path) => path != entity.path);
95+
96+
for (final String dirName in <String>['lib', 'bin']) {
97+
final Iterable<File> files = fileSystem.directory(fileSystem.path.join(flutterTools, dirName))
98+
.listSync(recursive: true)
99+
.where(_isDartFile)
100+
.where(_isNotAllowed)
101+
.map(_asFile);
102+
for (final File file in files) {
103+
for (final String line in file.readAsLinesSync()) {
104+
if (line.startsWith(RegExp(r'import.*package:http/')) &&
105+
!line.contains('ignore: package_http_import')) {
106+
final String relativePath = fileSystem.path.relative(file.path, from:flutterTools);
107+
fail("$relativePath imports 'package:http'; import 'lib/src/base/io.dart' instead");
108+
}
109+
}
110+
}
111+
}
112+
});
113+
89114
test('no unauthorized imports of test_api', () {
90115
final List<String> allowedPaths = <String>[
91116
fileSystem.path.join(flutterTools, 'lib', 'src', 'test', 'flutter_platform.dart'),

0 commit comments

Comments
 (0)