Skip to content

Commit 3d3ab7b

Browse files
[tool] Allow blank lines in federated package changes (#8468)
Currently the special-casing for allowing comment-only changes to other packages in a plugin group as part of a single PR, which is necessary for some changes to add `// ignore` directives, allows comment lines, but not blank lines. Blank lines should be allowed since they are safe, and are expected for certain changes (notably, temporary file-level ignores).
1 parent e8f1f63 commit 3d3ab7b

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

script/tool/lib/src/federation_safety_check_command.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,18 +212,19 @@ class FederationSafetyCheckCommand extends PackageLoopingCommand {
212212
Future<bool> _changeIsCommentOnly(
213213
GitVersionFinder git, String repoPath) async {
214214
final List<String> diff = await git.getDiffContents(targetPath: repoPath);
215-
final RegExp changeLine = RegExp(r'^[+-] ');
215+
final RegExp changeLine = RegExp(r'^[+-]');
216216
// This will not catch /**/-style comments, but false negatives are fine
217217
// (and in practice, we almost never use that comment style in Dart code).
218218
final RegExp commentLine = RegExp(r'^[+-]\s*//');
219+
final RegExp blankLine = RegExp(r'^[+-]\s*$');
219220
bool foundComment = false;
220221
for (final String line in diff) {
221222
if (!changeLine.hasMatch(line) ||
222223
line.startsWith('--- ') ||
223224
line.startsWith('+++ ')) {
224225
continue;
225226
}
226-
if (!commentLine.hasMatch(line)) {
227+
if (!(commentLine.hasMatch(line) || blankLine.hasMatch(line))) {
227228
return false;
228229
}
229230
foundComment = true;

script/tool/test/federation_safety_check_command_test.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,10 +446,12 @@ diff --git a/packages/foo/foo_bar/lib/foo.dart b/packages/foo/foo_bar/lib/foo.da
446446
index abc123..def456 100644
447447
--- a/packages/foo/foo_bar/lib/foo.dart
448448
+++ b/packages/foo/foo_bar/lib/foo.dart
449-
@@ -51,6 +51,7 @@ Future<bool> launchUrl(
449+
@@ -51,6 +51,9 @@ Future<bool> launchUrl(
450450
}
451451
452452
void foo() {
453+
+ // blank lines should also be allowed as part of comment changes.
454+
+
453455
+ // ignore: exhaustive_cases
454456
switch(a_foo) {
455457
case a:

0 commit comments

Comments
 (0)