Skip to content

Commit 6d974f0

Browse files
authored
Enable trailing commas lint (#387)
1 parent b72d480 commit 6d974f0

20 files changed

+321
-203
lines changed

analysis_options.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,4 @@ linter:
119119
- use_string_buffers
120120
- valid_regexps
121121
- void_checks
122+
- require_trailing_commas

mono_repo/build.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@ targets:
1313
options:
1414
any_map: true
1515
checked: true
16+
source_gen:combining_builder:
17+
options:
18+
ignore_for_file:
19+
- require_trailing_commas

mono_repo/lib/src/commands/github/github_yaml.dart

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ Map<String, String> generateGitHubYml(
2727

2828
final allJobStages = {for (var job in jobs) job.stageName};
2929
final orderedStages = calculateOrderedStages(
30-
rootConfig, rootConfig.monoConfig.githubConditionalStages)
31-
..add(_onCompletionStage);
30+
rootConfig,
31+
rootConfig.monoConfig.githubConditionalStages,
32+
)..add(_onCompletionStage);
3233

3334
final output = <String, String>{};
3435

@@ -201,24 +202,26 @@ Iterable<_MapEntryWithStage> _listJobs(
201202
if (mergeStages.contains(first.job.stageName)) {
202203
final packages = entry.value.map((t) => t.job.package).toList()..sort();
203204
yield jobEntry(
204-
first.jobYaml(
205+
first.jobYaml(
206+
rootConfig,
207+
packages: packages,
208+
oneOs: differentOperatingSystems.length == 1,
209+
oneSdk: differentSdks.length == 1,
210+
onePackage: differentPackages.length == 1,
211+
),
212+
first.job.stageName,
213+
);
214+
} else {
215+
yield* entry.value.map(
216+
(e) => jobEntry(
217+
e.jobYaml(
205218
rootConfig,
206-
packages: packages,
207219
oneOs: differentOperatingSystems.length == 1,
208220
oneSdk: differentSdks.length == 1,
209221
onePackage: differentPackages.length == 1,
210222
),
211-
first.job.stageName);
212-
} else {
213-
yield* entry.value.map(
214-
(e) => jobEntry(
215-
e.jobYaml(
216-
rootConfig,
217-
oneOs: differentOperatingSystems.length == 1,
218-
oneSdk: differentSdks.length == 1,
219-
onePackage: differentPackages.length == 1,
220-
),
221-
e.job.stageName),
223+
e.job.stageName,
224+
),
222225
);
223226
}
224227
}
@@ -227,9 +230,12 @@ Iterable<_MapEntryWithStage> _listJobs(
227230
// appropriate `needs` config to each.
228231
if (onCompletionJobs != null && onCompletionJobs.isNotEmpty) {
229232
for (var jobConfig in onCompletionJobs) {
230-
yield jobEntry({
231-
...jobConfig,
232-
}, _onCompletionStage);
233+
yield jobEntry(
234+
{
235+
...jobConfig,
236+
},
237+
_onCompletionStage,
238+
);
233239
}
234240
}
235241
}
@@ -265,24 +271,28 @@ extension on CIJobEntry {
265271
for (var package in packages) {
266272
final pubStepId = '${package.replaceAll('/', '_')}_'
267273
'pub_${rootConfig.monoConfig.pubAction}';
268-
commandEntries.add(_CommandEntry(
269-
'$package; $pubCommand',
270-
pubCommand,
271-
id: pubStepId,
272-
// Run this regardless of the success of other steps other than the
273-
// pub step.
274-
ifCondition: "always() && steps.checkout.conclusion == 'success'",
275-
workingDirectory: package,
276-
));
277-
for (var i = 0; i < commands.length; i++) {
278-
commandEntries.add(_CommandEntry(
279-
'$package; ${job.tasks[i].command}',
280-
_commandForOs(job.tasks[i].command),
274+
commandEntries.add(
275+
_CommandEntry(
276+
'$package; $pubCommand',
277+
pubCommand,
278+
id: pubStepId,
281279
// Run this regardless of the success of other steps other than the
282280
// pub step.
283-
ifCondition: "always() && steps.$pubStepId.conclusion == 'success'",
281+
ifCondition: "always() && steps.checkout.conclusion == 'success'",
284282
workingDirectory: package,
285-
));
283+
),
284+
);
285+
for (var i = 0; i < commands.length; i++) {
286+
commandEntries.add(
287+
_CommandEntry(
288+
'$package; ${job.tasks[i].command}',
289+
_commandForOs(job.tasks[i].command),
290+
// Run this regardless of the success of other steps other than the
291+
// pub step.
292+
ifCondition: "always() && steps.$pubStepId.conclusion == 'success'",
293+
workingDirectory: package,
294+
),
295+
);
286296
}
287297
}
288298

mono_repo/lib/src/commands/mono_repo_command.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const recursiveFlag = 'recursive';
1111

1212
abstract class MonoRepoCommand extends Command<void> {
1313
RootConfig rootConfig() => RootConfig(
14-
rootDirectory: p.current,
15-
recursive: globalResults![recursiveFlag] as bool);
14+
rootDirectory: p.current,
15+
recursive: globalResults![recursiveFlag] as bool,
16+
);
1617
}

mono_repo/lib/src/commands/presubmit.dart

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,31 @@ class PresubmitCommand extends MonoRepoCommand {
2525

2626
PresubmitCommand() {
2727
argParser
28-
..addMultiOption('package',
29-
help: 'The package(s) to run on, defaults to all packages', abbr: 'p')
30-
..addMultiOption('task',
31-
help: 'The task(s) to run, defaults to all tasks', abbr: 't')
32-
..addOption('sdk',
33-
help: 'Which sdk to use for match tasks, defaults to current sdk',
34-
defaultsTo: _currentSdk);
28+
..addMultiOption(
29+
'package',
30+
help: 'The package(s) to run on, defaults to all packages',
31+
abbr: 'p',
32+
)
33+
..addMultiOption(
34+
'task',
35+
help: 'The task(s) to run, defaults to all tasks',
36+
abbr: 't',
37+
)
38+
..addOption(
39+
'sdk',
40+
help: 'Which sdk to use for match tasks, defaults to current sdk',
41+
defaultsTo: _currentSdk,
42+
);
3543
}
3644

3745
@override
3846
Future<void> run() async {
39-
final passed = await presubmit(rootConfig(),
40-
packages: argResults!['package'] as List<String>,
41-
tasks: argResults!['task'] as List<String>,
42-
sdkToRun: argResults!['sdk'] as String);
47+
final passed = await presubmit(
48+
rootConfig(),
49+
packages: argResults!['package'] as List<String>,
50+
tasks: argResults!['task'] as List<String>,
51+
sdkToRun: argResults!['sdk'] as String,
52+
);
4353

4454
// Set a bad exit code if it failed.
4555
if (!passed) exitCode = 1;
@@ -100,12 +110,14 @@ Future<bool> presubmit(
100110
// Status of the presubmit.
101111
var passed = true;
102112
for (var package in packages) {
103-
final config = rootConfig.singleWhere((pkg) => pkg.relativePath == package,
104-
orElse: () {
105-
throw UserException(
106-
'Unrecognized package `$package`, known packages are:\n'
107-
'${rootConfig.map((pkg) => ' ${pkg.relativePath}').join('\n')}');
108-
});
113+
final config = rootConfig.singleWhere(
114+
(pkg) => pkg.relativePath == package,
115+
orElse: () {
116+
throw UserException(
117+
'Unrecognized package `$package`, known packages are:\n'
118+
'${rootConfig.map((pkg) => ' ${pkg.relativePath}').join('\n')}');
119+
},
120+
);
109121

110122
print(styleBold.wrap(package));
111123
for (var job in config.jobs) {
@@ -122,8 +134,11 @@ Future<bool> presubmit(
122134
continue;
123135
}
124136

125-
final result = await Process.run(ciScriptPath, [taskKey],
126-
environment: {'PKGS': package});
137+
final result = await Process.run(
138+
ciScriptPath,
139+
[taskKey],
140+
environment: {'PKGS': package},
141+
);
127142
if (result.exitCode == 0) {
128143
print(green.wrap(' success'));
129144
} else {

mono_repo/lib/src/commands/pub.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,12 @@ Future<void> pub(RootConfig rootConfig, List<String> args) async {
6565
);
6666
final workingDir = p.join(rootConfig.rootDirectory, dir);
6767

68-
final proc = await Process.start(executable, packageArgs,
69-
mode: ProcessStartMode.inheritStdio, workingDirectory: workingDir);
68+
final proc = await Process.start(
69+
executable,
70+
packageArgs,
71+
mode: ProcessStartMode.inheritStdio,
72+
workingDirectory: workingDir,
73+
);
7074

7175
final exit = await proc.exitCode;
7276

mono_repo/lib/src/github_config.g.dart

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mono_repo/lib/src/mono_config.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ class MonoConfig {
185185
/// Parses the `stages` key from a CI config map, into a Map from stage name
186186
/// to [ConditionalStage] instance.
187187
Map<String, ConditionalStage> _readConditionalStages(
188-
Map<dynamic, dynamic> ciJson) {
188+
Map<dynamic, dynamic> ciJson,
189+
) {
189190
final conditionalStages = <String, ConditionalStage>{};
190191
final rawValue = ciJson['stages'];
191192
if (rawValue != null) {

mono_repo/lib/src/mono_config.g.dart

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mono_repo/lib/src/package_config.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,10 @@ class Task {
489489
}
490490

491491
static List<String> _commandValue(
492-
PackageFlavor flavor, String name, String? args) {
492+
PackageFlavor flavor,
493+
String name,
494+
String? args,
495+
) {
493496
switch (name) {
494497
case 'format':
495498
return [

0 commit comments

Comments
 (0)