blob: 3e2e99618bd3ef87b8dd0b0a63e0180db9370c59 [file] [log] [blame]
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:async';
import 'dart:io';
import 'package:firehose/firehose.dart';
import '../repo_tweak.dart';
import '../utils.dart';
final _instance = ReformatTweak._();
/// Regenerate the latest configuration files for package:mono_repo.
class ReformatTweak extends RepoTweak {
factory ReformatTweak() => _instance;
: super(
id: 'reformat',
description: 'file a PR for a run of `dart format`',
bool shouldRunByDefault(Directory checkout, String repoSlug) => true;
FutureOr<FixResult> fix(Directory checkout, String repoSlug) async {
var repo = Repository(checkout);
var packages = repo.locatePackages();
final fixes = <String>[];
for (var package in packages) {
var exitCode = await runProc(
'running dart format for ${}',
['format', '.', '--set-exit-if-changed'],
throwOnFailure: false,
if (exitCode == 1) {
return fixes.isEmpty ? FixResult.noFixesMade : FixResult(fixes: fixes);