execute method

  1. @override
Future execute(
  1. Project project
)

Implementation

@override
Future execute(Project project) {
  List<String> ext = List.from(_handlers.expand((h) => h.types));
  List<File> files = project.getSourceFiles(extensions: ext);

  int modifiedCount = 0;

  for (File file in files) {
    String ext = getFileExtension(file.path);

    if (supportsFileType(ext)) {
      String contents = file.readAsStringSync();
      String results = trim(contents, ext);
      if (contents != results) {
        project.print('trimmed ${relativePath(file)}');

        modifiedCount++;
        file.writeAsStringSync(results);
      }
    }
  }

  if (modifiedCount > 0) {
    project
        .print('$modifiedCount ${pluralize("file", modifiedCount)} changed.');
  } else {
    project.print('No files changed.');
  }

  return Future.value();
}