Skip to content

Commit e51436d

Browse files
authored
🎨 Format files (#644)
1 parent 8b5ce6d commit e51436d

21 files changed

+206
-124
lines changed

‎analysis_options.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,22 @@ analyzer:
1414
linter:
1515
rules:
1616
# always_use_package_imports: true
17-
avoid_equals_and_hash_code_on_mutable_classes: true
1817
avoid_classes_with_only_static_members: true
18+
avoid_equals_and_hash_code_on_mutable_classes: true
19+
curly_braces_in_flow_control_structures: true
1920
directives_ordering: true
2021
flutter_style_todos: true
2122
prefer_const_constructors: true
2223
prefer_const_constructors_in_immutables: true
2324
prefer_final_in_for_each: true
2425
prefer_int_literals: true
2526
prefer_single_quotes: true
26-
# require_trailing_commas: true
27-
# sort_constructors_first: true
27+
require_trailing_commas: true
28+
sort_constructors_first: true
29+
sort_unnamed_constructors_first: true
2830
unawaited_futures: true
2931
unnecessary_await_in_return: true
30-
use_to_and_as_if_applicable: true
3132
unnecessary_lambdas: true
33+
use_to_and_as_if_applicable: true
3234
use_raw_strings: true
3335
use_super_parameters: false

‎packages/command/bin/flutter_gen_command.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ void main(List<String> args) async {
4747
}
4848
} on FormatException catch (e) {
4949
stderr.writeAll(
50-
<String>[e.message, 'usage: flutter_gen [options...]', ''], '\n');
50+
<String>[e.message, 'usage: flutter_gen [options...]', ''],
51+
'\n',
52+
);
5153
return;
5254
}
5355

‎packages/command/test/flutter_gen_command_test.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ void main() {
3737
'dart',
3838
['bin/flutter_gen_command.dart', '--help'],
3939
);
40-
expect(await process.stdout.next,
41-
equals('-c, --config Set the path of pubspec.yaml.'));
40+
expect(
41+
await process.stdout.next,
42+
equals('-c, --config Set the path of pubspec.yaml.'),
43+
);
4244
final line = await process.stdout.next;
4345
expect(line.trim(), equals('(defaults to "pubspec.yaml")'));
4446
await process.shouldExit(0);

‎packages/core/lib/flutter_generator.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ class FlutterGenerator {
2525

2626
Future<void> build({Config? config, FileWriter? writer}) async {
2727
config ??= loadPubspecConfigOrNull(pubspecFile, buildFile: buildFile);
28-
if (config == null) return;
28+
if (config == null) {
29+
return;
30+
}
2931

3032
final flutter = config.pubspec.flutter;
3133
final flutterGen = config.pubspec.flutterGen;

‎packages/core/lib/generators/assets_generator.dart

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,23 @@ Future<String> generateAssets(
5959
}
6060

6161
final integrations = <Integration>[
62-
ImageIntegration(config.packageParameterLiteral,
63-
parseMetadata: config.flutterGen.parseMetadata),
62+
ImageIntegration(
63+
config.packageParameterLiteral,
64+
parseMetadata: config.flutterGen.parseMetadata,
65+
),
6466
if (config.flutterGen.integrations.flutterSvg)
65-
SvgIntegration(config.packageParameterLiteral,
66-
parseMetadata: config.flutterGen.parseMetadata),
67+
SvgIntegration(
68+
config.packageParameterLiteral,
69+
parseMetadata: config.flutterGen.parseMetadata,
70+
),
6771
if (config.flutterGen.integrations.rive)
68-
RiveIntegration(config.packageParameterLiteral),
72+
RiveIntegration(
73+
config.packageParameterLiteral,
74+
),
6975
if (config.flutterGen.integrations.lottie)
70-
LottieIntegration(config.packageParameterLiteral),
76+
LottieIntegration(
77+
config.packageParameterLiteral,
78+
),
7179
];
7280

7381
// Warn for deprecated configs.
@@ -198,13 +206,16 @@ List<FlavoredAsset> _getAssetRelativePathList(
198206
}
199207
final assetAbsolutePath = join(rootPath, tempAsset.path);
200208
if (FileSystemEntity.isDirectorySync(assetAbsolutePath)) {
201-
assetRelativePathList.addAll(Directory(assetAbsolutePath)
202-
.listSync()
203-
.whereType<File>()
204-
.map(
205-
(e) => tempAsset.copyWith(path: relative(e.path, from: rootPath)),
206-
)
207-
.toList());
209+
assetRelativePathList.addAll(
210+
Directory(assetAbsolutePath)
211+
.listSync()
212+
.whereType<File>()
213+
.map(
214+
(file) =>
215+
tempAsset.copyWith(path: relative(file.path, from: rootPath)),
216+
)
217+
.toList(),
218+
);
208219
} else if (FileSystemEntity.isFileSync(assetAbsolutePath)) {
209220
assetRelativePathList.add(
210221
tempAsset.copyWith(path: relative(assetAbsolutePath, from: rootPath)),
@@ -376,15 +387,17 @@ Future<String> _dotDelimiterStyleDefinition(
376387
// Add this directory reference to Assets class
377388
// if we are not under the default asset folder
378389
if (dirname(assetType.path) == '.') {
379-
assetsStaticStatements.add(_Statement(
380-
type: className,
381-
filePath: assetType.posixStylePath,
382-
name: assetType.baseName.camelCase(),
383-
value: '$className()',
384-
isConstConstructor: true,
385-
isDirectory: true,
386-
needDartDoc: true,
387-
));
390+
assetsStaticStatements.add(
391+
_Statement(
392+
type: className,
393+
filePath: assetType.posixStylePath,
394+
name: assetType.baseName.camelCase(),
395+
value: '$className()',
396+
isConstConstructor: true,
397+
isDirectory: true,
398+
needDartDoc: true,
399+
),
400+
);
388401
}
389402
}
390403

@@ -470,10 +483,13 @@ String _flatStyleAssetsClassDefinition(
470483
List<_Statement> statements,
471484
String? packageName,
472485
) {
473-
final statementsBlock =
474-
statements.map((statement) => '''${statement.toDartDocString()}
486+
final statementsBlock = statements
487+
.map(
488+
(statement) => '''${statement.toDartDocString()}
475489
${statement.toStaticFieldString()}
476-
''').join('\n');
490+
''',
491+
)
492+
.join('\n');
477493
final valuesBlock = _assetValuesDefinition(statements, static: true);
478494
return _assetsClassDefinition(
479495
className,
@@ -506,7 +522,9 @@ String _assetValuesDefinition(
506522
bool static = false,
507523
}) {
508524
final values = statements.where((element) => !element.isDirectory);
509-
if (values.isEmpty) return '';
525+
if (values.isEmpty) {
526+
return '';
527+
}
510528
final names = values.map((value) => value.name).join(', ');
511529
final type = values.every((element) => element.type == values.first.type)
512530
? values.first.type

‎packages/core/lib/generators/colors_generator.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ String generateColors(
1818
) {
1919
if (colorsConfig.inputs.isEmpty) {
2020
throw const InvalidSettingsException(
21-
'The value of "flutter_gen/colors:" is incorrect.');
21+
'The value of "flutter_gen/colors:" is incorrect.',
22+
);
2223
}
2324

2425
final buffer = StringBuffer();
@@ -39,9 +40,10 @@ String generateColors(
3940
final data = colorFile.file.readAsStringSync();
4041
if (colorFile.isXml) {
4142
colorList.addAll(
42-
XmlDocument.parse(data).findAllElements('color').map((element) {
43-
return _Color.fromXmlElement(element);
44-
}));
43+
XmlDocument.parse(data).findAllElements('color').map((element) {
44+
return _Color.fromXmlElement(element);
45+
}),
46+
);
4547
} else {
4648
throw 'Not supported file type ${colorFile.mime}.';
4749
}

‎packages/core/lib/generators/fonts_generator.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ String generateFonts(
3939
final fontsConfig = config.flutterGen.fonts;
4040
if (fonts.isEmpty) {
4141
throw InvalidSettingsException(
42-
'The value of "flutter/fonts:" is incorrect.');
42+
'The value of "flutter/fonts:" is incorrect.',
43+
);
4344
}
4445

4546
final buffer = StringBuffer();

‎packages/core/lib/generators/generator_helper.dart

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,17 @@ String sBuildDeprecation(
6767
'```yaml',
6868
'flutter_gen:',
6969
...migration,
70-
'```'
70+
'```',
7171
];
7272

7373
final longestLineLength = lines
74-
.map((line) => line
75-
.split('\n')
76-
.sorted((a, b) => b.length.compareTo(b.length))
77-
.first
78-
.length)
74+
.map(
75+
(line) => line
76+
.split('\n')
77+
.sorted((a, b) => b.length.compareTo(b.length))
78+
.first
79+
.length,
80+
)
7981
.sorted((a, b) => b.compareTo(a))
8082
.first;
8183

‎packages/core/lib/generators/integrations/integration.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ const String deprecationMessagePackage =
5555
/// Currently only contains the width and height, but could contain more in
5656
/// future.
5757
class ImageMetadata {
58+
const ImageMetadata(this.width, this.height);
59+
5860
final double width;
5961
final double height;
60-
61-
const ImageMetadata(this.width, this.height);
6262
}

‎packages/core/lib/settings/asset_type.dart

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -142,26 +142,32 @@ extension AssetTypeIterable on Iterable<AssetType> {
142142
String Function(String) style, {
143143
bool justBasename = false,
144144
}) {
145-
List<UniqueAssetType> assets = map((e) => UniqueAssetType(
146-
assetType: e,
147-
style: style,
148-
needExtension: false,
149-
suffix: '',
150-
basenameOnly: justBasename,
151-
)).toList();
145+
List<UniqueAssetType> assets = map(
146+
(e) => UniqueAssetType(
147+
assetType: e,
148+
style: style,
149+
needExtension: false,
150+
suffix: '',
151+
basenameOnly: justBasename,
152+
),
153+
).toList();
152154

153155
while (true) {
154156
// Check if we have any name collisions.
155-
final dups = assets.groupBy((e) => e.name).values;
157+
final duplicates = assets.groupBy((e) => e.name).values;
156158

157159
// No more duplicates, so we can bail.
158-
if (dups.every((list) => list.length == 1)) break;
160+
if (duplicates.every((list) => list.length == 1)) {
161+
break;
162+
}
159163

160164
// Otherwise start to process the list and mutate the assets as needed.
161-
assets = dups
165+
assets = duplicates
162166
.map((list) {
163-
assert(list.isNotEmpty,
164-
'The groupBy list of assets should not be empty.');
167+
assert(
168+
list.isNotEmpty,
169+
'The groupBy list of assets should not be empty.',
170+
);
165171

166172
// Check the first element in the list. Since we grouped by each
167173
// list element should have the same name.
@@ -190,7 +196,9 @@ extension AssetTypeIterable on Iterable<AssetType> {
190196
list.forEachIndexed((asset, index) {
191197
// Shouldn't need to mutate the first item (unless it's an invalid
192198
// identifer).
193-
if (index == 0 && isValidIdentifer) return;
199+
if (index == 0 && isValidIdentifer) {
200+
return;
201+
}
194202

195203
// Append a extra suffixes to each item so they hopefully become unique
196204
suffix = '${suffix}_';
@@ -203,8 +211,10 @@ extension AssetTypeIterable on Iterable<AssetType> {
203211
.toList();
204212
}
205213

206-
assert(assets.map((e) => e.name).distinct().length == assets.length,
207-
'There are duplicate names in the asset list.');
214+
assert(
215+
assets.map((e) => e.name).distinct().length == assets.length,
216+
'There are duplicate names in the asset list.',
217+
);
208218

209219
return assets;
210220
}

0 commit comments

Comments
 (0)