mirror of
https://github.com/flutter/packages.git
synced 2026-03-13 10:40:37 +08:00
Makes the analysis options changes described in
https://github.com/flutter/flutter/issues/178827:
- Adding
[omit_obvious_local_variable_types](https://dart.dev/tools/linter-rules/omit_obvious_local_variable_types)
- Adding
[specify_nonobvious_local_variable_types](https://dart.dev/tools/linter-rules/specify_nonobvious_local_variable_types)
- Adding
[specify_nonobvious_property_types](https://dart.dev/tools/linter-rules/specify_nonobvious_property_types)
- Adding
[type_annotate_public_apis](https://dart.dev/tools/linter-rules/type_annotate_public_apis)
- Removing
[always_specify_types](https://dart.dev/tools/linter-rules/always_specify_types)
After those changes, makes the following repo-wide changes:
- `dart fix --apply` in all packages and in script/tool/
- `dart format` in all packages and in script/tool/
- `update-excerpts` repo tooling command to update excerpts based on the
changes to their sources
Also updates the min Flutter/Dart SDK version to 3.35/3.9 for the
following packages, to avoid `analyze` failures in the `N-2` legacy
analysis run due to what appears to be a 3.9 change in what the Dart
analyzer continues to be an obvious local type in loop iterations:
- go_router
- google_fonts
- google_identity_services_web
- google_maps_flutter_web
- local_auth_platform_interface
- metrics_center
- multicast_dns
- pigeon
- rfw
- shared_preferences
- two_dimensional_scrollables
- vector_graphics_compiler
- mustache_template
- path_parsing
Because this is causing a significant amount of format churn already, I
took this opportunity to update the repository tooling to a min Dart SDK
of 3.8 (the N-2 stable version, so the earliest version we need the
tooling to support) to pick up the new format style, so the amount of
automated formatter change is higher in script/tool/ than in the
packages.
This does contain two manual changes (other than the repo tooling min
version):
-
d700b45c7d
changes `dynamic` to `Object?` in a few places where `dynamic` caused
analyzer warnings under the new rule set.
- Updates the repo tooling to ignore `.dart_tool/` when looking for
unexpected local `analysis_options.yaml` files, to fix issues running
the repo tool's `analyze` command locally based on recent changes in
`dart` behavior.
This does not include any CHANGELOG or version updates; even though we
normally version any changes to production code, mass automated changes
like this aren't worth the churn of releasing. This includes changes to
lib/example/main.dart and to README.md excerpts; while the style changes
will be user-visible on pub.dev, it's fine for those changes to wait for
the next release of each package.
Part of https://github.com/flutter/flutter/issues/178827
389 lines
10 KiB
Dart
389 lines
10 KiB
Dart
// Copyright 2013 The Flutter Authors
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import 'package:args/command_runner.dart';
|
|
import 'package:file/file.dart';
|
|
import 'package:flutter_plugin_tools/src/common/core.dart';
|
|
import 'package:flutter_plugin_tools/src/custom_test_command.dart';
|
|
import 'package:git/git.dart';
|
|
import 'package:test/test.dart';
|
|
|
|
import 'mocks.dart';
|
|
import 'util.dart';
|
|
|
|
void main() {
|
|
late MockPlatform mockPlatform;
|
|
late Directory packagesDir;
|
|
late RecordingProcessRunner processRunner;
|
|
late CommandRunner<void> runner;
|
|
|
|
group('posix', () {
|
|
setUp(() {
|
|
mockPlatform = MockPlatform();
|
|
final GitDir gitDir;
|
|
(:packagesDir, :processRunner, gitProcessRunner: _, :gitDir) =
|
|
configureBaseCommandMocks(platform: mockPlatform);
|
|
final analyzeCommand = CustomTestCommand(
|
|
packagesDir,
|
|
processRunner: processRunner,
|
|
platform: mockPlatform,
|
|
gitDir: gitDir,
|
|
);
|
|
|
|
runner = CommandRunner<void>(
|
|
'custom_test_command',
|
|
'Test for custom_test_command',
|
|
);
|
|
runner.addCommand(analyzeCommand);
|
|
});
|
|
|
|
test('runs both new and legacy when both are present', () async {
|
|
final RepositoryPackage package = createFakePackage(
|
|
'a_package',
|
|
packagesDir,
|
|
extraFiles: <String>['tool/run_tests.dart', 'run_tests.sh'],
|
|
);
|
|
|
|
final List<String> output = await runCapturingPrint(runner, <String>[
|
|
'custom-test',
|
|
]);
|
|
|
|
expect(
|
|
processRunner.recordedCalls,
|
|
containsAll(<ProcessCall>[
|
|
ProcessCall(
|
|
package.directory.childFile('run_tests.sh').path,
|
|
const <String>[],
|
|
package.path,
|
|
),
|
|
ProcessCall('dart', const <String>[
|
|
'run',
|
|
'tool/run_tests.dart',
|
|
], package.path),
|
|
]),
|
|
);
|
|
|
|
expect(
|
|
output,
|
|
containsAllInOrder(<Matcher>[contains('Ran for 1 package(s)')]),
|
|
);
|
|
});
|
|
|
|
test('runs when only new is present', () async {
|
|
final RepositoryPackage package = createFakePackage(
|
|
'a_package',
|
|
packagesDir,
|
|
extraFiles: <String>['tool/run_tests.dart'],
|
|
);
|
|
|
|
final List<String> output = await runCapturingPrint(runner, <String>[
|
|
'custom-test',
|
|
]);
|
|
|
|
expect(
|
|
processRunner.recordedCalls,
|
|
containsAll(<ProcessCall>[
|
|
ProcessCall('dart', const <String>[
|
|
'run',
|
|
'tool/run_tests.dart',
|
|
], package.path),
|
|
]),
|
|
);
|
|
|
|
expect(
|
|
output,
|
|
containsAllInOrder(<Matcher>[contains('Ran for 1 package(s)')]),
|
|
);
|
|
});
|
|
|
|
test('runs pub get before running Dart test script', () async {
|
|
final RepositoryPackage package = createFakePackage(
|
|
'a_package',
|
|
packagesDir,
|
|
extraFiles: <String>['tool/run_tests.dart'],
|
|
);
|
|
|
|
await runCapturingPrint(runner, <String>['custom-test']);
|
|
|
|
expect(
|
|
processRunner.recordedCalls,
|
|
containsAll(<ProcessCall>[
|
|
ProcessCall('dart', const <String>['pub', 'get'], package.path),
|
|
ProcessCall('dart', const <String>[
|
|
'run',
|
|
'tool/run_tests.dart',
|
|
], package.path),
|
|
]),
|
|
);
|
|
});
|
|
|
|
test('runs when only legacy is present', () async {
|
|
final RepositoryPackage package = createFakePackage(
|
|
'a_package',
|
|
packagesDir,
|
|
extraFiles: <String>['run_tests.sh'],
|
|
);
|
|
|
|
final List<String> output = await runCapturingPrint(runner, <String>[
|
|
'custom-test',
|
|
]);
|
|
|
|
expect(
|
|
processRunner.recordedCalls,
|
|
containsAll(<ProcessCall>[
|
|
ProcessCall(
|
|
package.directory.childFile('run_tests.sh').path,
|
|
const <String>[],
|
|
package.path,
|
|
),
|
|
]),
|
|
);
|
|
|
|
expect(
|
|
output,
|
|
containsAllInOrder(<Matcher>[contains('Ran for 1 package(s)')]),
|
|
);
|
|
});
|
|
|
|
test('skips when neither is present', () async {
|
|
createFakePackage('a_package', packagesDir);
|
|
|
|
final List<String> output = await runCapturingPrint(runner, <String>[
|
|
'custom-test',
|
|
]);
|
|
|
|
expect(processRunner.recordedCalls, isEmpty);
|
|
|
|
expect(
|
|
output,
|
|
containsAllInOrder(<Matcher>[contains('Skipped 1 package(s)')]),
|
|
);
|
|
});
|
|
|
|
test('fails if new fails', () async {
|
|
createFakePackage(
|
|
'a_package',
|
|
packagesDir,
|
|
extraFiles: <String>['tool/run_tests.dart', 'run_tests.sh'],
|
|
);
|
|
|
|
processRunner.mockProcessesForExecutable['dart'] = <FakeProcessInfo>[
|
|
FakeProcessInfo(MockProcess(), <String>['pub', 'get']),
|
|
FakeProcessInfo(MockProcess(exitCode: 1), <String>['test']),
|
|
];
|
|
|
|
Error? commandError;
|
|
final List<String> output = await runCapturingPrint(
|
|
runner,
|
|
<String>['custom-test'],
|
|
errorHandler: (Error e) {
|
|
commandError = e;
|
|
},
|
|
);
|
|
|
|
expect(commandError, isA<ToolExit>());
|
|
expect(
|
|
output,
|
|
containsAllInOrder(<Matcher>[
|
|
contains('The following packages had errors:'),
|
|
contains('a_package'),
|
|
]),
|
|
);
|
|
});
|
|
|
|
test('fails if pub get fails', () async {
|
|
createFakePackage(
|
|
'a_package',
|
|
packagesDir,
|
|
extraFiles: <String>['tool/run_tests.dart', 'run_tests.sh'],
|
|
);
|
|
|
|
processRunner.mockProcessesForExecutable['dart'] = <FakeProcessInfo>[
|
|
FakeProcessInfo(MockProcess(exitCode: 1), <String>['pub', 'get']),
|
|
];
|
|
|
|
Error? commandError;
|
|
final List<String> output = await runCapturingPrint(
|
|
runner,
|
|
<String>['custom-test'],
|
|
errorHandler: (Error e) {
|
|
commandError = e;
|
|
},
|
|
);
|
|
|
|
expect(commandError, isA<ToolExit>());
|
|
expect(
|
|
output,
|
|
containsAllInOrder(<Matcher>[
|
|
contains('The following packages had errors:'),
|
|
contains(
|
|
'a_package:\n'
|
|
' Unable to get script dependencies',
|
|
),
|
|
]),
|
|
);
|
|
});
|
|
|
|
test('fails if legacy fails', () async {
|
|
final RepositoryPackage package = createFakePackage(
|
|
'a_package',
|
|
packagesDir,
|
|
extraFiles: <String>['tool/run_tests.dart', 'run_tests.sh'],
|
|
);
|
|
|
|
processRunner.mockProcessesForExecutable[package.directory
|
|
.childFile('run_tests.sh')
|
|
.path] = <FakeProcessInfo>[
|
|
FakeProcessInfo(MockProcess(exitCode: 1)),
|
|
];
|
|
|
|
Error? commandError;
|
|
final List<String> output = await runCapturingPrint(
|
|
runner,
|
|
<String>['custom-test'],
|
|
errorHandler: (Error e) {
|
|
commandError = e;
|
|
},
|
|
);
|
|
|
|
expect(commandError, isA<ToolExit>());
|
|
expect(
|
|
output,
|
|
containsAllInOrder(<Matcher>[
|
|
contains('The following packages had errors:'),
|
|
contains('a_package'),
|
|
]),
|
|
);
|
|
});
|
|
});
|
|
|
|
group('Windows', () {
|
|
setUp(() {
|
|
mockPlatform = MockPlatform(isWindows: true);
|
|
final GitDir gitDir;
|
|
(:packagesDir, :processRunner, gitProcessRunner: _, :gitDir) =
|
|
configureBaseCommandMocks(platform: mockPlatform);
|
|
final analyzeCommand = CustomTestCommand(
|
|
packagesDir,
|
|
processRunner: processRunner,
|
|
platform: mockPlatform,
|
|
gitDir: gitDir,
|
|
);
|
|
|
|
runner = CommandRunner<void>(
|
|
'custom_test_command',
|
|
'Test for custom_test_command',
|
|
);
|
|
runner.addCommand(analyzeCommand);
|
|
});
|
|
|
|
test('runs new and skips old when both are present', () async {
|
|
final RepositoryPackage package = createFakePackage(
|
|
'a_package',
|
|
packagesDir,
|
|
extraFiles: <String>['tool/run_tests.dart', 'run_tests.sh'],
|
|
);
|
|
|
|
final List<String> output = await runCapturingPrint(runner, <String>[
|
|
'custom-test',
|
|
]);
|
|
|
|
expect(
|
|
processRunner.recordedCalls,
|
|
containsAll(<ProcessCall>[
|
|
ProcessCall('dart', const <String>[
|
|
'run',
|
|
'tool/run_tests.dart',
|
|
], package.path),
|
|
]),
|
|
);
|
|
|
|
expect(
|
|
output,
|
|
containsAllInOrder(<Matcher>[contains('Ran for 1 package(s)')]),
|
|
);
|
|
});
|
|
|
|
test('runs when only new is present', () async {
|
|
final RepositoryPackage package = createFakePackage(
|
|
'a_package',
|
|
packagesDir,
|
|
extraFiles: <String>['tool/run_tests.dart'],
|
|
);
|
|
|
|
final List<String> output = await runCapturingPrint(runner, <String>[
|
|
'custom-test',
|
|
]);
|
|
|
|
expect(
|
|
processRunner.recordedCalls,
|
|
containsAll(<ProcessCall>[
|
|
ProcessCall('dart', const <String>[
|
|
'run',
|
|
'tool/run_tests.dart',
|
|
], package.path),
|
|
]),
|
|
);
|
|
|
|
expect(
|
|
output,
|
|
containsAllInOrder(<Matcher>[contains('Ran for 1 package(s)')]),
|
|
);
|
|
});
|
|
|
|
test('skips package when only legacy is present', () async {
|
|
createFakePackage(
|
|
'a_package',
|
|
packagesDir,
|
|
extraFiles: <String>['run_tests.sh'],
|
|
);
|
|
|
|
final List<String> output = await runCapturingPrint(runner, <String>[
|
|
'custom-test',
|
|
]);
|
|
|
|
expect(processRunner.recordedCalls, isEmpty);
|
|
|
|
expect(
|
|
output,
|
|
containsAllInOrder(<Matcher>[
|
|
contains('run_tests.sh is not supported on Windows'),
|
|
contains('Skipped 1 package(s)'),
|
|
]),
|
|
);
|
|
});
|
|
|
|
test('fails if new fails', () async {
|
|
createFakePackage(
|
|
'a_package',
|
|
packagesDir,
|
|
extraFiles: <String>['tool/run_tests.dart', 'run_tests.sh'],
|
|
);
|
|
|
|
processRunner.mockProcessesForExecutable['dart'] = <FakeProcessInfo>[
|
|
FakeProcessInfo(MockProcess(), <String>['pub', 'get']),
|
|
FakeProcessInfo(MockProcess(exitCode: 1), <String>['test']),
|
|
];
|
|
|
|
Error? commandError;
|
|
final List<String> output = await runCapturingPrint(
|
|
runner,
|
|
<String>['custom-test'],
|
|
errorHandler: (Error e) {
|
|
commandError = e;
|
|
},
|
|
);
|
|
|
|
expect(commandError, isA<ToolExit>());
|
|
expect(
|
|
output,
|
|
containsAllInOrder(<Matcher>[
|
|
contains('The following packages had errors:'),
|
|
contains('a_package'),
|
|
]),
|
|
);
|
|
});
|
|
});
|
|
}
|