Skip to content

Commit 81ba7c6

Browse files
committed
ci: enforce repo-wide dart format + blame-ignore the reformat
1 parent 10e0814 commit 81ba7c6

3 files changed

Lines changed: 21 additions & 42 deletions

File tree

.git-blame-ignore-revs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Revisions for `git blame` to skip (large, mechanical changes with no logic impact).
2+
#
3+
# Enable locally once with:
4+
# git config blame.ignoreRevsFile .git-blame-ignore-revs
5+
#
6+
# GitHub honors this file automatically. List full 40-char commit SHAs only.
7+
8+
# style: apply Dart 3.12 format (tall style) — repo-wide dart_format, no logic changes
9+
10e0814088ae3b12f0cca4673f885e2828eaaa7a

.github/workflows/checks.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ jobs:
1616
- name: Set up Flutter
1717
uses: subosito/flutter-action@v2
1818
with:
19+
# Pinned so a future Flutter/Dart release can't change formatter output
20+
# and turn the format check below red on unrelated PRs. Bump deliberately
21+
# alongside a repo-wide reformat (see .git-blame-ignore-revs).
22+
flutter-version: 3.44.1
1923
channel: stable
2024
cache: true
2125

@@ -34,9 +38,8 @@ jobs:
3438
- name: Perform Flutter Analysis
3539
run: flutter analyze
3640

37-
# TODO: Restore Dart formatting check, disabled due to an issue https://github.com/singerdmx/flutter-quill/actions/runs/13355109619/job/37296760819.
38-
# - name: Check Dart code formatting
39-
# run: dart format --set-exit-if-changed .
41+
- name: Check Dart code formatting
42+
run: dart format --set-exit-if-changed .
4043

4144
- name: Preview Dart proposed changes
4245
run: dart fix --dry-run

scripts/before_push.dart

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// ignore_for_file: avoid_print
22

3-
import 'dart:convert';
43
import 'dart:io';
54

65
void 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-
7037
Future<void> runCommand(
7138
String executable,
7239
List<String> arguments, {

0 commit comments

Comments
 (0)