[pkg/modular_test] analyze with package:lints

Change-Id: I8fd66acdc2ad0c39f959785039d0001d0148f1a6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/250765
Reviewed-by: Nate Bosch <nbosch@google.com>
Commit-Queue: Devon Carew <devoncarew@google.com>
This commit is contained in:
Devon Carew 2022-07-06 21:36:40 +00:00 committed by Commit Bot
parent e499586ad6
commit c677a0c36f
15 changed files with 63 additions and 62 deletions

View file

@ -0,0 +1 @@
include: package:lints/core.yaml

View file

@ -107,8 +107,8 @@ Future<void> runSuite<T>(List<Test> tests, RunnerOptions options) async {
continue;
}
var watch = new Stopwatch()..start();
var outcome = new _TestOutcome(test.name);
var watch = Stopwatch()..start();
var outcome = _TestOutcome(test.name);
try {
await test.run();
if (options.verbose) stdout.write('pass\n');

View file

@ -58,9 +58,9 @@ class IOPipeline extends Pipeline<IOModularStep> {
final bool saveIntermediateResultsForTesting;
IOPipeline(List<IOModularStep> steps,
{this.saveIntermediateResultsForTesting: false,
bool cacheSharedModules: false})
: _registry = cacheSharedModules ? new ConfigurationRegistry() : null,
{this.saveIntermediateResultsForTesting = false,
bool cacheSharedModules = false})
: _registry = cacheSharedModules ? ConfigurationRegistry() : null,
super(steps, cacheSharedModules);
@override
@ -156,7 +156,7 @@ class IOPipeline extends Pipeline<IOModularStep> {
}
String _toFileName(Module module, DataId dataId,
{bool configSpecific: false}) {
{bool configSpecific = false}) {
var prefix =
cacheSharedModules && configSpecific && _currentConfiguration != null
? _currentConfiguration

View file

@ -112,7 +112,7 @@ Future<ModularTest> loadTest(Uri uri) async {
var sortedModules = modules.values.toList()
..sort((a, b) => a.name.compareTo(b.name));
var sortedFlags = spec.flags.toList()..sort();
return new ModularTest(sortedModules, mainModule, sortedFlags);
return ModularTest(sortedModules, mainModule, sortedFlags);
}
/// Returns all source files recursively found in a folder as relative URIs.
@ -202,7 +202,7 @@ Future<Module> _createSdkModule(Uri root) async {
}
}
}
sources..sort((a, b) => a.path.compareTo(b.path));
sources.sort((a, b) => a.path.compareTo(b.path));
return Module('sdk', [], root, sources, isSdk: true, isShared: true);
}
@ -267,7 +267,7 @@ _moduleConflict(String name, Module existing, Uri root) {
}
Never _invalidTest(String message) {
throw new InvalidTestError(message);
throw InvalidTestError(message);
}
class InvalidTestError extends Error {

View file

@ -36,8 +36,8 @@ class MemoryPipeline extends Pipeline<MemoryModularStep> {
final List<Map<Module, Map<DataId, Object>>> _resultCache;
MemoryPipeline(this._sources, List<MemoryModularStep> steps,
{bool cacheSharedModules: false})
: _registry = cacheSharedModules ? new ConfigurationRegistry() : null,
{bool cacheSharedModules = false})
: _registry = cacheSharedModules ? ConfigurationRegistry() : null,
_resultCache = cacheSharedModules ? [] : const [],
super(steps, cacheSharedModules);

View file

@ -49,13 +49,13 @@ class ModularStep {
final bool notOnSdk;
ModularStep(
{this.needsSources: true,
this.dependencyDataNeeded: const [],
this.moduleDataNeeded: const [],
this.resultData: const [],
this.onlyOnMain: false,
this.onlyOnSdk: false,
this.notOnSdk: false});
{this.needsSources = true,
this.dependencyDataNeeded = const [],
this.moduleDataNeeded = const [],
this.resultData = const [],
this.onlyOnMain = false,
this.onlyOnSdk = false,
this.notOnSdk = false});
/// Notifies that the step was not executed, but cached instead.
void notifyCached(Module module) {}

View file

@ -20,13 +20,13 @@ Future<void> runSuite(Uri suiteFolder, String suiteName, Options options,
IOPipeline pipeline) async {
var dir = Directory.fromUri(suiteFolder);
var entries = (await dir.list(recursive: false).toList())
.where((e) => e is Directory)
.map((e) => new _PipelineTest(e.uri, suiteFolder, options, pipeline))
.whereType<Directory>()
.map((e) => _PipelineTest(e.uri, suiteFolder, options, pipeline))
.toList();
await generic.runSuite(
entries,
new generic.RunnerOptions(
generic.RunnerOptions(
suiteName: suiteName,
configurationName: options.configurationName,
filter: options.filter,
@ -67,7 +67,7 @@ class Options {
bool useSdk = false;
static Options parse(List<String> args) {
var parser = new ArgParser()
var parser = ArgParser()
..addFlag('verbose',
abbr: 'v',
defaultsTo: false,

View file

@ -66,11 +66,11 @@ class Module {
Module(this.name, this.dependencies, this.rootUri, this.sources,
{this.mainSource,
this.isPackage: false,
this.isMain: false,
this.isPackage = false,
this.isMain = false,
this.packageBase,
this.isShared: false,
this.isSdk: false}) {
this.isShared = false,
this.isSdk = false}) {
if (!_validModuleName.hasMatch(name)) {
throw ArgumentError("invalid module name: $name");
}
@ -114,7 +114,7 @@ class Module {
String toString() => '[module $name]';
String debugString() {
var buffer = new StringBuffer();
var buffer = StringBuffer();
buffer.write(' ');
buffer.write(name);
buffer.write(': ');
@ -129,7 +129,7 @@ class Module {
}
}
final RegExp _validModuleName = new RegExp(r'^[a-zA-Z_][a-zA-Z0-9_]*$');
final RegExp _validModuleName = RegExp(r'^[a-zA-Z_][a-zA-Z0-9_]*$');
/// Helper to compute transitive dependencies from [module].
Set<Module> computeTransitiveDependencies(Module module) {

View file

@ -108,8 +108,7 @@ TestSpecification parseTestSpecification(String contents) {
_invalidSpecification("packages is not a map");
}
}
return new TestSpecification(
normalizedFlags, normalizedMap, normalizedPackages);
return TestSpecification(normalizedFlags, normalizedMap, normalizedPackages);
}
/// Data specifying details about a modular test including dependencies and
@ -139,7 +138,7 @@ class TestSpecification {
}
_invalidSpecification(String message) {
throw new InvalidSpecificationError(message);
throw InvalidSpecificationError(message);
}
class InvalidSpecificationError extends Error {

View file

@ -19,4 +19,5 @@ dependencies:
dev_dependencies:
async_helper: any
expect: any
lints: any
test: any

View file

@ -16,7 +16,7 @@ main() async {
uri = Directory.systemTemp.uri.resolve("io_modular_test_root$i/");
i++;
}
runPipelineTest(new IOPipelineTestStrategy(uri));
runPipelineTest(IOPipelineTestStrategy(uri));
}
/// The strategy implementation to exercise the pipeline test on a
@ -30,14 +30,14 @@ class IOPipelineTestStrategy implements PipelineTestStrategy<IOModularStep> {
@override
Future<Pipeline<IOModularStep>> createPipeline(
Map<Uri, String> sources, List<IOModularStep> steps,
{bool cacheSharedModules: false}) async {
{bool cacheSharedModules = false}) async {
await Directory.fromUri(testRootUri).create();
for (var uri in sources.keys) {
var file = new File.fromUri(uri);
var file = File.fromUri(uri);
await file.create(recursive: true);
file.writeAsStringSync(sources[uri]!);
}
return new IOPipeline(steps,
return IOPipeline(steps,
saveIntermediateResultsForTesting: true,
cacheSharedModules: cacheSharedModules);
}
@ -46,7 +46,7 @@ class IOPipelineTestStrategy implements PipelineTestStrategy<IOModularStep> {
IOModularStep createSourceOnlyStep(
{required String Function(Map<Uri, String?>) action,
required DataId resultId,
bool requestSources: true}) =>
bool requestSources = true}) =>
SourceOnlyStep(action, resultId, requestSources);
@override
@ -54,7 +54,7 @@ class IOPipelineTestStrategy implements PipelineTestStrategy<IOModularStep> {
{required String Function(String) action,
required DataId inputId,
required DataId resultId,
bool requestModuleData: true}) =>
bool requestModuleData = true}) =>
ModuleDataStep(action, inputId, resultId, requestModuleData);
@override
@ -63,7 +63,7 @@ class IOPipelineTestStrategy implements PipelineTestStrategy<IOModularStep> {
required DataId inputId,
required DataId depId,
required DataId resultId,
bool requestDependenciesData: true}) =>
bool requestDependenciesData = true}) =>
LinkStep(action, inputId, depId, resultId, requestDependenciesData);
@override
@ -72,7 +72,7 @@ class IOPipelineTestStrategy implements PipelineTestStrategy<IOModularStep> {
required DataId inputId,
required DataId depId,
required DataId resultId,
bool requestDependenciesData: true}) =>
bool requestDependenciesData = true}) =>
MainOnlyStep(action, inputId, depId, resultId, requestDependenciesData);
@override

View file

@ -59,7 +59,7 @@ Future<void> _runTest(Uri uri, String dirName, _Options options) async {
}
String _dumpAsText(ModularTest test) {
var buffer = new StringBuffer();
var buffer = StringBuffer();
bool isFirst = true;
for (var module in test.modules) {
if (isFirst) {
@ -103,7 +103,7 @@ class _Options {
String? filter;
static _Options parse(List<String> args) {
var parser = new ArgParser()
var parser = ArgParser()
..addFlag('update',
abbr: 'u',
defaultsTo: false,

View file

@ -10,7 +10,7 @@ import 'package:modular_test/src/memory_pipeline.dart';
import 'pipeline_common.dart';
main() {
runPipelineTest(new MemoryPipelineTestStrategy());
runPipelineTest(MemoryPipelineTestStrategy());
}
/// The strategy implementation to exercise the pipeline test on a
@ -23,8 +23,8 @@ class MemoryPipelineTestStrategy
@override
FutureOr<Pipeline<MemoryModularStep>> createPipeline(
Map<Uri, String> sources, List<MemoryModularStep> steps,
{bool cacheSharedModules: false}) {
return new MemoryPipeline(sources, steps,
{bool cacheSharedModules = false}) {
return MemoryPipeline(sources, steps,
cacheSharedModules: cacheSharedModules);
}
@ -32,7 +32,7 @@ class MemoryPipelineTestStrategy
MemoryModularStep createSourceOnlyStep(
{required String Function(Map<Uri, String?>) action,
required DataId resultId,
bool requestSources: true}) =>
bool requestSources = true}) =>
SourceOnlyStep(action, resultId, requestSources);
@override
@ -40,7 +40,7 @@ class MemoryPipelineTestStrategy
{required String Function(String) action,
required DataId inputId,
required DataId resultId,
bool requestModuleData: true}) =>
bool requestModuleData = true}) =>
ModuleDataStep(action, inputId, resultId, requestModuleData);
@override
@ -49,7 +49,7 @@ class MemoryPipelineTestStrategy
required DataId inputId,
required DataId depId,
required DataId resultId,
bool requestDependenciesData: true}) =>
bool requestDependenciesData = true}) =>
LinkStep(action, inputId, depId, resultId, requestDependenciesData);
@override
@ -58,7 +58,7 @@ class MemoryPipelineTestStrategy
required DataId inputId,
required DataId depId,
required DataId resultId,
bool requestDependenciesData: true}) =>
bool requestDependenciesData = true}) =>
MainOnlyStep(action, inputId, depId, resultId, requestDependenciesData);
@override

View file

@ -29,14 +29,14 @@ abstract class PipelineTestStrategy<S extends ModularStep> {
/// by other methods in this strategy to ensure they are compatible with to
/// the pipeline created here.
FutureOr<Pipeline<S>> createPipeline(Map<Uri, String> sources, List<S> steps,
{bool cacheSharedModules: false});
{bool cacheSharedModules = false});
/// Create a step that applies [action] on all input files of the module, and
/// emits a result with the given [id]
S createSourceOnlyStep(
{required String Function(Map<Uri, String?>) action,
required DataId resultId,
bool requestSources: true});
bool requestSources = true});
/// Create a step that applies [action] on the module [inputId] data, and
/// emits a result with the given [resultId].
@ -44,7 +44,7 @@ abstract class PipelineTestStrategy<S extends ModularStep> {
{required String Function(String) action,
required DataId inputId,
required DataId resultId,
bool requestModuleData: true});
bool requestModuleData = true});
/// Create a step that applies [action] on the module [inputId] data and the
/// the [depId] data of dependencies and finally emits a result with the given
@ -56,7 +56,7 @@ abstract class PipelineTestStrategy<S extends ModularStep> {
required DataId inputId,
required DataId depId,
required DataId resultId,
bool requestDependenciesData: true});
bool requestDependenciesData = true});
/// Create a step that applies [action] only on the main module [inputId] data
/// and the [depId] data of transitive dependencies and finally emits a
@ -69,7 +69,7 @@ abstract class PipelineTestStrategy<S extends ModularStep> {
required DataId inputId,
required DataId depId,
required DataId resultId,
bool requestDependenciesData: true});
bool requestDependenciesData = true});
/// Create a step that applies [action1] and [action2] on the module [inputId]
/// data, and emits two results with the given [result1Id] and [result2Id].
@ -315,8 +315,8 @@ runPipelineTest<S extends ModularStep>(PipelineTestStrategy<S> testStrategy) {
test('no reuse of existing results if not caching', () async {
int i = 1;
const counterId = const DataId("counter");
const linkId = const DataId("link");
const counterId = DataId("counter");
const linkId = DataId("link");
// This step is not idempotent, we do this purposely to test whether caching
// is taking place.
var counterStep = testStrategy.createSourceOnlyStep(
@ -347,8 +347,8 @@ runPipelineTest<S extends ModularStep>(PipelineTestStrategy<S> testStrategy) {
test('caching reuses existing results for the same configuration', () async {
int i = 1;
const counterId = const DataId("counter");
const linkId = const DataId("link");
const counterId = DataId("counter");
const linkId = DataId("link");
var counterStep = testStrategy.createSourceOnlyStep(
action: (_) => '${i++}', resultId: counterId);
var linkStep = testStrategy.createLinkStep(
@ -377,8 +377,8 @@ runPipelineTest<S extends ModularStep>(PipelineTestStrategy<S> testStrategy) {
test('no reuse of existing results on different configurations', () async {
int i = 1;
const counterId = const DataId("counter");
const linkId = const DataId("link");
const counterId = DataId("counter");
const linkId = DataId("link");
// This step is not idempotent, we do this purposely to test whether caching
// is taking place.
var counterStep = testStrategy.createSourceOnlyStep(
@ -420,7 +420,7 @@ DataId _uppercaseId = const DataId("uppercase");
DataId _joinId = const DataId("join");
String _concat(Map<Uri, String?> sources) {
var buffer = new StringBuffer();
var buffer = StringBuffer();
sources.forEach((uri, contents) {
buffer.write("$uri: $contents\n");
});
@ -431,7 +431,7 @@ String _lowercase(String contents) => contents.toLowerCase();
String _uppercase(String contents) => contents.toUpperCase();
String _replaceAndJoin(String moduleData, List<String?> depContents) {
var buffer = new StringBuffer();
var buffer = StringBuffer();
depContents.forEach(buffer.writeln);
buffer.write(moduleData.replaceAll(".dart:", ""));
return '$buffer';

View file

@ -72,7 +72,7 @@ main() {
}
validateSteps(List<ModularStep> steps) {
new _NoopPipeline(steps);
_NoopPipeline(steps);
}
/// An implementation of [Pipeline] that simply validates the steps, but doesn't