11// ignore_for_file: avoid_print
22
3- import 'dart:convert' ;
43import 'dart:io' ;
54
65void main () async {
@@ -12,21 +11,12 @@ void main() async {
1211
1312 await runCommand ('dart' , ['fix' , '--apply' ]);
1413
15- // Format only files that are modified but not yet committed, to avoid
16- // reformatting the entire repository (e.g. after a Dart SDK formatter
17- // update changes the default formatting style).
18- final changedDartFiles = await uncommittedDartFiles ();
19- if (changedDartFiles.isEmpty) {
20- print ('No modified Dart files to format; skipping `dart format`.' );
21- } else {
22- await runCommand ('dart' , ['format' , ...changedDartFiles]);
23-
24- await runCommand ('dart' , [
25- 'format' ,
26- '--set-exit-if-changed' ,
27- ...changedDartFiles,
28- ]);
29- }
14+ // Format the whole repository, then assert it is fully formatted (mirrors the
15+ // CI `dart format --set-exit-if-changed .` check). The repo is kept in canonical
16+ // style by a one-off reformat + the pinned-version CI check, so this no longer
17+ // needs to scope to changed files only.
18+ await runCommand ('dart' , ['format' , '.' ]);
19+ await runCommand ('dart' , ['format' , '--set-exit-if-changed' , '.' ]);
3020
3121 await runCommand ('flutter' , [
3222 'build' ,
@@ -44,29 +34,6 @@ void main() async {
4434 print ('Checks completed.' );
4535}
4636
47- /// Returns the repo-relative paths of Dart files that are modified but not yet
48- /// committed: tracked changes (staged or unstaged) relative to `HEAD` , plus
49- /// untracked files. Deleted files are excluded so they aren't passed to
50- /// `dart format` .
51- Future <List <String >> uncommittedDartFiles () async {
52- final tracked = await Process .run ('git' , ['diff' , '--name-only' , 'HEAD' ]);
53- final untracked = await Process .run ('git' , [
54- 'ls-files' ,
55- '--others' ,
56- '--exclude-standard' ,
57- ]);
58-
59- final paths = < String > {
60- ...const LineSplitter ().convert (tracked.stdout as String ),
61- ...const LineSplitter ().convert (untracked.stdout as String ),
62- };
63-
64- return paths
65- .where ((path) => path.endsWith ('.dart' ))
66- .where ((path) => File (path).existsSync ())
67- .toList ();
68- }
69-
7037Future <void > runCommand (
7138 String executable,
7239 List <String > arguments, {
0 commit comments