problems method

List<String> problems({
  1. String root = '.',
  2. FileSystem fileSystem = const LocalFileSystem(),
})

The problems of the package in the directory root, the current directory by default, which is the package's own when dart test runs its tests: one line for every package and every URI of a file that breaks a rule.

It tells the module packages by their pubspecs, which it finds through the package config that dart pub get writes to .dart_tool/package_config.json in the directory of the package or, in a pub workspace, in the root of the workspace above it. Without the package config, or without the pubspec of a package it has to tell, the problems ask to run dart pub get.

Implementation

List<String> problems({
  String root = '.',
  FileSystem fileSystem = const LocalFileSystem(),
}) {
  final directory = fileSystem.directory(root);
  final pubspecFile = directory.childFile('pubspec.yaml');
  final pubspec = pubspecFile.existsSync()
      ? loadYaml(pubspecFile.readAsStringSync())
      : null;
  if (pubspec is! YamlMap || pubspec['name'] != name) {
    return ['The directory $root has no pubspec.yaml of $name.'];
  }
  Set<String> packagesOf(String section) => switch (pubspec[section]) {
        final YamlMap packages => {...packages.keys.cast<String>()},
        _ => const {},
      };
  final packages = ResolvedPackages.of(directory);
  if (packages == null) return [ResolvedPackages.missingConfig(root)];

  final code = {'smf_contracts', ...dependencies};
  final tests = {'smf_pipeline', ...testModules};
  final problems = [
    ..._dependencyProblems(code, packagesOf('dependencies')),
    ..._devDependencyProblems(
      tests,
      packagesOf('dev_dependencies'),
      packages.isModule,
    ),
    ..._libProblems(directory, code),
    ..._testProblems(directory, tests, packages.isModule),
  ];
  return [...packages.problems, ...problems];
}