Skip to content

Commit e0cbc6e

Browse files
committed
fix(tool): Fail version-check on blank lines in CHANGELOG lists
Blank lines between list items in a CHANGELOG.md file cause pub.dev to render them as separate lists, which is not the intended style for the project. This commit updates the `version-check` command to detect this pattern using a multi-line regex. If a match is found, the check fails and prints the offending lines to the console to help the author fix it. Signed-off-by: Lorenzo Croce <lorenzo.croce@arenastudios.it>
1 parent 8176ffd commit e0cbc6e

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

script/tool/lib/src/version_check_command.dart

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,9 +455,42 @@ ${indentation}The first version listed in CHANGELOG.md is $fromChangeLog.
455455
}
456456
}
457457

458+
// Check for blank lines between list items in the version section.
459+
final Match? blankLineMatch = _findBlankLineInList(lines.join('\n'));
460+
if (blankLineMatch != null) {
461+
final String offendingLines = blankLineMatch
462+
.group(0)!
463+
.split('\n')
464+
.map((String line) => '$indentation $line') // Add extra indentation
465+
.join('\n');
466+
467+
printError(
468+
'${indentation}Blank lines found between list items in CHANGELOG.\n'
469+
'${indentation}This creates multiple separate lists on pub.dev.\n'
470+
'${indentation}Remove blank lines to keep all items in a single list.\n'
471+
'${indentation}The problematic section found is:\n'
472+
'$offendingLines');
473+
return false;
474+
}
475+
458476
return true;
459477
}
460478

479+
/// Validates that there are no blank lines between list items within
480+
/// the changelog using a regex.
481+
///
482+
/// Returns the first invalid match found, or null if validation passes.
483+
Match? _findBlankLineInList(String changelogContent) {
484+
// This regex requires the multiLine flag to be true.
485+
final RegExp blankLineInListRegex = RegExp(
486+
r'(^[ \t]*[*+-].*$\n)((^[ \t]*$\n)+)(^[ \t]*[*+-].*$)',
487+
multiLine: true);
488+
489+
// If the regex finds a match, it means there is an error (a blank line
490+
// between list items).
491+
return blankLineInListRegex.firstMatch(changelogContent);
492+
}
493+
461494
Pubspec? _tryParsePubspec(RepositoryPackage package) {
462495
try {
463496
final Pubspec pubspec = package.parsePubspec();

script/tool/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: flutter_plugin_tools
22
description: Productivity and CI utils for flutter/packages
33
repository: https://github.com/flutter/packages/tree/main/script/tool
4-
version: 1.0.0
4+
version: 1.0.1
55
publish_to: none
66

77
dependencies:

0 commit comments

Comments
 (0)