Skip to content

Commit 64d2e1f

Browse files
committed
format
1 parent 2285870 commit 64d2e1f

12 files changed

+459
-319
lines changed

script/tool/lib/src/branch_for_batch_release_command.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ class BranchForBatchReleaseCommand extends PackageCommand {
117117
List<PendingChangelogEntry> pendingChangelogEntries,
118118
Version oldVersion,
119119
) {
120-
final List<String> changelogs = <String>[];
120+
final changelogs = <String>[];
121121
int versionIndex = VersionChange.skip.index;
122-
for (final PendingChangelogEntry entry in pendingChangelogEntries) {
122+
for (final entry in pendingChangelogEntries) {
123123
changelogs.add(entry.changelog);
124124
versionIndex = math.min(versionIndex, entry.version.index);
125125
}

script/tool/lib/src/common/ci_config.dart

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class CIConfig {
2020

2121
_checkCIConfigEntries(loaded, syntax: _validCIConfigSyntax);
2222

23-
bool isBatchRelease = false;
23+
var isBatchRelease = false;
2424
final Object? release = loaded['release'];
2525
if (release is Map) {
2626
isBatchRelease = release['batch'] == true;
@@ -31,36 +31,44 @@ class CIConfig {
3131

3232
static const Map<String, Object?> _validCIConfigSyntax = <String, Object?>{
3333
'release': <String, Object?>{
34-
'batch': <bool>{true, false}
34+
'batch': <bool>{true, false},
3535
},
3636
};
3737

3838
/// Returns true if the package is configured for batch release.
3939
final bool isBatchRelease;
4040

41-
static void _checkCIConfigEntries(YamlMap config,
42-
{required Map<String, Object?> syntax, String configPrefix = ''}) {
41+
static void _checkCIConfigEntries(
42+
YamlMap config, {
43+
required Map<String, Object?> syntax,
44+
String configPrefix = '',
45+
}) {
4346
for (final MapEntry<Object?, Object?> entry in config.entries) {
4447
if (!syntax.containsKey(entry.key)) {
4548
throw FormatException(
46-
'Unknown key `${entry.key}` in config${_formatConfigPrefix(configPrefix)}, the possible keys are ${syntax.keys.toList()}');
49+
'Unknown key `${entry.key}` in config${_formatConfigPrefix(configPrefix)}, the possible keys are ${syntax.keys.toList()}',
50+
);
4751
} else {
4852
final Object syntaxValue = syntax[entry.key]!;
49-
final String newConfigPrefix = configPrefix.isEmpty
53+
final newConfigPrefix = configPrefix.isEmpty
5054
? entry.key! as String
5155
: '$configPrefix.${entry.key}';
5256
if (syntaxValue is Set) {
5357
if (!syntaxValue.contains(entry.value)) {
5458
throw FormatException(
55-
'Invalid value `${entry.value}` for key${_formatConfigPrefix(newConfigPrefix)}, the possible values are ${syntaxValue.toList()}');
59+
'Invalid value `${entry.value}` for key${_formatConfigPrefix(newConfigPrefix)}, the possible values are ${syntaxValue.toList()}',
60+
);
5661
}
5762
} else if (entry.value is! YamlMap) {
5863
throw FormatException(
59-
'Invalid value `${entry.value}` for key${_formatConfigPrefix(newConfigPrefix)}, the value must be a map');
64+
'Invalid value `${entry.value}` for key${_formatConfigPrefix(newConfigPrefix)}, the value must be a map',
65+
);
6066
} else {
61-
_checkCIConfigEntries(entry.value! as YamlMap,
62-
syntax: syntaxValue as Map<String, Object?>,
63-
configPrefix: newConfigPrefix);
67+
_checkCIConfigEntries(
68+
entry.value! as YamlMap,
69+
syntax: syntaxValue as Map<String, Object?>,
70+
configPrefix: newConfigPrefix,
71+
);
6472
}
6573
}
6674
}

script/tool/lib/src/common/pending_changelog_entry.dart

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,11 @@ enum VersionChange {
5555
/// Represents a single entry in the pending changelog.
5656
class PendingChangelogEntry {
5757
/// Creates a new pending changelog entry.
58-
PendingChangelogEntry(
59-
{required this.changelog, required this.version, required this.file});
60-
61-
/// The template file name used to draft a pending changelog file.
62-
/// This file will not be picked up by the batch release process.
63-
static const String _batchReleaseChangelogTemplateFileName = 'template.yaml';
64-
65-
/// Returns true if the file is a template file.
66-
static bool isTemplate(File file) {
67-
return p.basename(file.path) == _batchReleaseChangelogTemplateFileName;
68-
}
58+
PendingChangelogEntry({
59+
required this.changelog,
60+
required this.version,
61+
required this.file,
62+
});
6963

7064
/// Creates a PendingChangelogEntry from a YAML string.
7165
///
@@ -74,17 +68,19 @@ class PendingChangelogEntry {
7468
final dynamic yaml = loadYaml(yamlContent);
7569
if (yaml is! YamlMap) {
7670
throw FormatException(
77-
'Expected a YAML map, but found ${yaml.runtimeType}.');
71+
'Expected a YAML map, but found ${yaml.runtimeType}.',
72+
);
7873
}
7974

8075
final dynamic changelogYaml = yaml['changelog'];
8176
if (changelogYaml is! String) {
8277
throw FormatException(
83-
'Expected "changelog" to be a string, but found ${changelogYaml.runtimeType}.');
78+
'Expected "changelog" to be a string, but found ${changelogYaml.runtimeType}.',
79+
);
8480
}
8581
final String changelog = changelogYaml.trim();
8682

87-
final String? versionString = yaml['version'] as String?;
83+
final versionString = yaml['version'] as String?;
8884
if (versionString == null) {
8985
throw const FormatException('Missing "version" key.');
9086
}
@@ -95,7 +91,19 @@ class PendingChangelogEntry {
9591
);
9692

9793
return PendingChangelogEntry(
98-
changelog: changelog, version: version, file: file);
94+
changelog: changelog,
95+
version: version,
96+
file: file,
97+
);
98+
}
99+
100+
/// The template file name used to draft a pending changelog file.
101+
/// This file will not be picked up by the batch release process.
102+
static const String _batchReleaseChangelogTemplateFileName = 'template.yaml';
103+
104+
/// Returns true if the file is a template file.
105+
static bool isTemplate(File file) {
106+
return p.basename(file.path) == _batchReleaseChangelogTemplateFileName;
99107
}
100108

101109
/// The changelog messages for this entry.

script/tool/lib/src/common/repository_package.dart

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import 'package:file/file.dart';
66
import 'package:path/path.dart' as p;
77
import 'package:pubspec_parse/pubspec_parse.dart';
8-
import 'package:yaml/yaml.dart';
98

109
import 'ci_config.dart';
1110
import 'core.dart';
@@ -247,36 +246,41 @@ class RepositoryPackage {
247246
/// Throws if the folder does not exist, or if any of the files are not
248247
/// valid changelog entries.
249248
List<PendingChangelogEntry> getPendingChangelogs() {
250-
final List<PendingChangelogEntry> entries = <PendingChangelogEntry>[];
249+
final entries = <PendingChangelogEntry>[];
251250

252251
final Directory pendingChangelogsDir = pendingChangelogsDirectory;
253252
if (!pendingChangelogsDir.existsSync()) {
254253
throw FormatException(
255-
'No pending_changelogs folder found for $displayName.');
254+
'No pending_changelogs folder found for $displayName.',
255+
);
256256
}
257257

258-
final List<File> allFiles =
259-
pendingChangelogsDir.listSync().whereType<File>().toList();
258+
final List<File> allFiles = pendingChangelogsDir
259+
.listSync()
260+
.whereType<File>()
261+
.toList();
260262

261-
final List<File> pendingChangelogFiles = <File>[];
262-
for (final File file in allFiles) {
263+
final pendingChangelogFiles = <File>[];
264+
for (final file in allFiles) {
263265
final String basename = p.basename(file.path);
264266
if (basename.endsWith('.yaml')) {
265267
if (!PendingChangelogEntry.isTemplate(file)) {
266268
pendingChangelogFiles.add(file);
267269
}
268270
} else {
269271
throw FormatException(
270-
'Found non-YAML file in pending_changelogs: ${file.path}');
272+
'Found non-YAML file in pending_changelogs: ${file.path}',
273+
);
271274
}
272275
}
273276

274-
for (final File file in pendingChangelogFiles) {
277+
for (final file in pendingChangelogFiles) {
275278
try {
276279
entries.add(PendingChangelogEntry.parse(file.readAsStringSync(), file));
277280
} on FormatException catch (e) {
278281
throw FormatException(
279-
'Malformed pending changelog file: ${file.path}\n$e');
282+
'Malformed pending changelog file: ${file.path}\n$e',
283+
);
280284
}
281285
}
282286
return entries;

script/tool/lib/src/repo_package_info_check_command.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,11 @@ class RepoPackageInfoCheckCommand extends PackageLoopingCommand {
161161
} else {
162162
if (package.pendingChangelogsDirectory.existsSync()) {
163163
printError(
164-
'${indentation}Package does not use batch release but has pending changelogs.');
164+
'${indentation}Package does not use batch release but has pending changelogs.',
165+
);
165166
errors.add(
166-
'Package does not use batch release but has pending changelogs.');
167+
'Package does not use batch release but has pending changelogs.',
168+
);
167169
}
168170
}
169171

script/tool/lib/src/version_check_command.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ class VersionCheckCommand extends PackageLoopingCommand {
230230
final bool hasPostReleaseLabel = _prLabels.contains(
231231
'post-release-${pubspec.name}',
232232
);
233-
bool versionChanged = false;
233+
bool versionChanged;
234234

235235
if (usesBatchRelease && !hasPostReleaseLabel) {
236236
versionChanged = await _validateBatchRelease(

script/tool/test/common/ci_config_test.dart

Lines changed: 54 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
// found in the LICENSE file.
44

55
import 'package:file/file.dart';
6-
import 'package:flutter_plugin_tools/src/common/ci_config.dart';
7-
import 'package:flutter_plugin_tools/src/common/repository_package.dart';
86
import 'package:test/test.dart';
97

108
import '../util.dart';
@@ -19,18 +17,24 @@ void main() {
1917

2018
group('CIConfig', () {
2119
test('file', () async {
22-
final RepositoryPackage plugin =
23-
createFakePlugin('a_plugin', packagesDir);
20+
final RepositoryPackage plugin = createFakePlugin(
21+
'a_plugin',
22+
packagesDir,
23+
);
2424

2525
final File ciConfigFile = plugin.ciConfigFile;
2626

2727
expect(
28-
ciConfigFile.path, plugin.directory.childFile('ci_config.yaml').path);
28+
ciConfigFile.path,
29+
plugin.directory.childFile('ci_config.yaml').path,
30+
);
2931
});
3032

3133
test('parsing', () async {
32-
final RepositoryPackage plugin =
33-
createFakePlugin('a_plugin', packagesDir);
34+
final RepositoryPackage plugin = createFakePlugin(
35+
'a_plugin',
36+
packagesDir,
37+
);
3438
plugin.ciConfigFile.writeAsStringSync('''
3539
release:
3640
batch: true
@@ -43,56 +47,76 @@ release:
4347
});
4448

4549
test('parsing missing file returns null', () async {
46-
final RepositoryPackage plugin =
47-
createFakePlugin('a_plugin', packagesDir);
50+
final RepositoryPackage plugin = createFakePlugin(
51+
'a_plugin',
52+
packagesDir,
53+
);
4854

4955
final CIConfig? config = plugin.parseCIConfig();
5056

5157
expect(config, isNull);
5258
});
5359

5460
test('parsing invalid file throws', () async {
55-
final RepositoryPackage plugin =
56-
createFakePlugin('a_plugin', packagesDir);
61+
final RepositoryPackage plugin = createFakePlugin(
62+
'a_plugin',
63+
packagesDir,
64+
);
5765
plugin.ciConfigFile.writeAsStringSync('not a map');
5866

5967
expect(
60-
() => plugin.parseCIConfig(),
61-
throwsA(isA<FormatException>().having(
62-
(FormatException e) => e.message,
63-
'message',
64-
contains('Root of ci_config.yaml must be a map'))));
68+
() => plugin.parseCIConfig(),
69+
throwsA(
70+
isA<FormatException>().having(
71+
(FormatException e) => e.message,
72+
'message',
73+
contains('Root of ci_config.yaml must be a map'),
74+
),
75+
),
76+
);
6577
});
6678

6779
test('reports unknown keys', () {
68-
final RepositoryPackage plugin =
69-
createFakePlugin('a_plugin', packagesDir);
80+
final RepositoryPackage plugin = createFakePlugin(
81+
'a_plugin',
82+
packagesDir,
83+
);
7084
plugin.ciConfigFile.writeAsStringSync('''
7185
foo: bar
7286
''');
7387

7488
expect(
75-
() => plugin.parseCIConfig(),
76-
throwsA(isA<FormatException>().having(
77-
(FormatException e) => e.message,
78-
'message',
79-
contains('Unknown key `foo` in config'))));
89+
() => plugin.parseCIConfig(),
90+
throwsA(
91+
isA<FormatException>().having(
92+
(FormatException e) => e.message,
93+
'message',
94+
contains('Unknown key `foo` in config'),
95+
),
96+
),
97+
);
8098
});
8199

82100
test('reports invalid values', () {
83-
final RepositoryPackage plugin =
84-
createFakePlugin('a_plugin', packagesDir);
101+
final RepositoryPackage plugin = createFakePlugin(
102+
'a_plugin',
103+
packagesDir,
104+
);
85105
plugin.ciConfigFile.writeAsStringSync('''
86106
release:
87107
batch: not-a-bool
88108
''');
89109

90110
expect(
91-
() => plugin.parseCIConfig(),
92-
throwsA(isA<FormatException>().having(
93-
(FormatException e) => e.message,
94-
'message',
95-
contains('Invalid value `not-a-bool` for key `release.batch`'))));
111+
() => plugin.parseCIConfig(),
112+
throwsA(
113+
isA<FormatException>().having(
114+
(FormatException e) => e.message,
115+
'message',
116+
contains('Invalid value `not-a-bool` for key `release.batch`'),
117+
),
118+
),
119+
);
96120
});
97121
});
98122
}

script/tool/test/common/package_state_utils_test.dart

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -547,20 +547,24 @@ void main() {
547547
});
548548

549549
test('detects pending changelog changes for batch release', () async {
550-
final RepositoryPackage package =
551-
createFakePackage('a_package', packagesDir);
550+
final RepositoryPackage package = createFakePackage(
551+
'a_package',
552+
packagesDir,
553+
);
552554
package.ciConfigFile.writeAsStringSync('''
553555
release:
554556
batch: true
555557
''');
556558

557-
const List<String> changedFiles = <String>[
559+
const changedFiles = <String>[
558560
'packages/a_package/pending_changelogs/some_change.yaml',
559561
];
560562

561-
final PackageChangeState state = await checkPackageChangeState(package,
562-
changedPaths: changedFiles,
563-
relativePackagePath: 'packages/a_package/');
563+
final PackageChangeState state = await checkPackageChangeState(
564+
package,
565+
changedPaths: changedFiles,
566+
relativePackagePath: 'packages/a_package/',
567+
);
564568

565569
expect(state.hasChanges, true);
566570
expect(state.hasChangelogChange, true);

0 commit comments

Comments
 (0)