getInputs static method

FormatterInputs getInputs({
  1. List<Glob>? exclude,
  2. bool? expandCwd,
  3. bool? followLinks,
  4. String? root,
  5. @deprecated bool? collapseDirectories,
})

Builds and returns the object that contains:

  • The file paths
  • The paths that were excluded by an exclude glob
  • The paths that were skipped because they are links
  • The hidden directories(start with a '.') that were skipped

The file paths will include all .dart files in path (and its subdirectories), except any paths that match the expanded exclude globs.

By default these globs are assumed to be relative to the current working directory, but that can be overridden via root for testing purposes.

Implementation

static FormatterInputs getInputs({
  List<Glob>? exclude,
  bool? expandCwd,
  bool? followLinks,
  String? root,
  @deprecated bool? collapseDirectories,
}) {
  if (collapseDirectories != null) {
    _log.warning(
        'ignoring deprecated option "collapseDirectories": argv limitations are now solved by parallel invocations');
  }

  expandCwd ??= false;
  followLinks ??= false;

  final includedFiles = <String>{};
  exclude ??= <Glob>[];

  if (exclude.isEmpty && !expandCwd) {
    return FormatterInputs({'.'});
  }

  final dir = Directory(root ?? '.');

  for (final entry in _listSyncWithoutHidden(dir,
      recursive: true, followLinks: followLinks)) {
    final filename = p.relative(entry.path, from: dir.path);
    _log.finest('== Processing relative $filename ==\n');

    if (entry is Link) {
      _log.finer('skipping link $filename\n');
      continue;
    }

    if (entry is File && !entry.path.endsWith('.dart')) {
      _log.finest('skipping non-dart file $filename\n');
      continue;
    }

    if (exclude.any((glob) => glob.matches(filename))) {
      _log.finer('excluding $filename\n');
    } else if (entry is File) {
      _log.finest('adding $filename\n');
      includedFiles.add(filename);
    }
  }

  return FormatterInputs(includedFiles);
}