Skip to content

Commit d8fbeb4

Browse files
committed
style: lint
1 parent f1ee8e6 commit d8fbeb4

11 files changed

+209
-162
lines changed

analysis_options.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
include: package:very_good_analysis/analysis_options.6.0.0.yaml
2+
13
analyzer:
24
enable-experiment:
35
- macros

melos.yaml

+23-9
Original file line numberDiff line numberDiff line change
@@ -35,49 +35,63 @@ scripts:
3535
run: melos exec -c 1 -- flutter pub outdated
3636

3737
fmt:
38-
description: format
38+
description: Format
3939
run: |
4040
melos fix && \
4141
melos fmt:dart
4242
4343
fmt:dry:
44-
description: format (dry-run)
44+
description: Format (dry-run)
4545
run: |
4646
melos fix:dry && \
4747
melos fmt:dart:dry
4848
4949
fmt:dart:
50-
description: format dart
50+
description: Format dart
5151
run: melos exec -c 1 --fail-fast -- dart format --enable-experiment=macros .
5252

5353
fmt:dart:dry:
54-
description: format dart (dry-run)
54+
description: Format dart (dry-run)
5555
run: melos exec -c 1 --fail-fast -- dart format --set-exit-if-changed --enable-experiment=macros .
5656

5757
fix:
58-
description: fix dart
58+
description: Fix dart
5959
run: melos exec -c 1 --fail-fast -- dart fix --apply --enable-experiment=macros
6060

6161
fix:dry:
62-
description: fix dart (dry-run)
62+
description: Fix dart (dry-run)
6363
run: melos exec -c 1 --fail-fast -- dart fix --dry-run --enable-experiment=macros
6464

65+
lint:
66+
description: Lint
67+
run: |
68+
melos lint:dart && \
69+
melos lint:flutter
70+
71+
lint:dart:
72+
description: Lint with dart
73+
run: melos exec -c 1 --scope="thema" -- dart analyze --fatal-infos --fatal-warnings
74+
75+
lint:flutter:
76+
description: Lint with flutter
77+
run: melos exec -c 1 --scope="thema_test" -- flutter analyze --fatal-infos --fatal-warnings
78+
6579
test:
6680
description: Run tests
6781
run: melos exec -c 1 --scope="thema_test" -- flutter test --enable-experiment=macros
6882
packageFilters:
6983
dependsOn: flutter_test
7084

7185
build:example:
72-
description: build on thema_example
86+
description: Build on thema_example
7387
run: |
7488
melos build:example:android && \
7589
melos build:example:ios
7690
7791
build:example:android:
78-
description: build android on thema_example
92+
description: Build android on thema_example
7993
run: melos exec -c 1 --scope="thema_example" -- flutter build appbundle
8094

8195
build:example:ios:
82-
description: build ios on thema_example
96+
description: Build ios on thema_example
8397
run: melos exec -c 1 --scope="thema_example" -- flutter build ios --no-codesign

packages/thema/example/lib/gradient_color.dart

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore_for_file: public_member_api_docs
2+
13
import 'dart:collection';
24

35
import 'package:flutter/material.dart';

packages/thema/example/lib/main.dart

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore_for_file: public_member_api_docs
2+
13
import 'package:flutter/material.dart';
24

35
void main() {

packages/thema/example/lib/theme.dart

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import 'package:thema/thema.dart';
1+
// ignore_for_file: public_member_api_docs
2+
23
import 'package:flutter/material.dart';
4+
import 'package:thema/thema.dart';
35
import 'package:thema_example/gradient_color.dart';
46

57
// WORKAROUND:

packages/thema/example/pubspec.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ dependencies:
1010
sdk: flutter
1111
thema:
1212
path: ..
13+
14+
dev_dependencies:
15+
very_good_analysis: 6.0.0

packages/thema/lib/src/thema.dart

+65-47
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import 'package:macros/macros.dart';
66
final _flutterMaterial = Uri.parse('package:flutter/material.dart');
77
final _dartCore = Uri.parse('dart:core');
88

9+
/// A macro that generates a `ThemeExtension` class for a given class.
910
macro class Thema
1011
implements ClassTypesMacro, ClassDeclarationsMacro, ClassDefinitionMacro {
12+
/// Creates a new instance of `Thema`.
1113
const Thema();
1214

1315
@override
@@ -16,6 +18,7 @@ macro class Thema
1618
ClassTypeBuilder builder,
1719
) async {
1820
final superType =
21+
// ignore: deprecated_member_use
1922
await builder.resolveIdentifier(_flutterMaterial, 'ThemeExtension');
2023
final superTypeCode = NamedTypeAnnotationCode(
2124
name: superType,
@@ -60,15 +63,17 @@ macro class Thema
6063
required MemberDeclarationBuilder builder,
6164
}) async {
6265
final fields = await builder.fieldsOf(clazz);
63-
final hasUnexpectedFields = fields.any((field) =>
64-
field.hasAbstract ||
65-
field.hasConst ||
66-
field.hasExternal ||
67-
!field.hasFinal ||
68-
field.hasInitializer ||
69-
field.hasLate ||
70-
field.hasStatic ||
71-
field.type.isNullable);
66+
final hasUnexpectedFields = fields.any(
67+
(field) =>
68+
field.hasAbstract ||
69+
field.hasConst ||
70+
field.hasExternal ||
71+
!field.hasFinal ||
72+
field.hasInitializer ||
73+
field.hasLate ||
74+
field.hasStatic ||
75+
field.type.isNullable,
76+
);
7277
if (hasUnexpectedFields) {
7378
builder.report(
7479
Diagnostic(
@@ -90,11 +95,13 @@ macro class Thema
9095
}) async {
9196
final fields = await builder.fieldsOf(clazz);
9297
final constructorParameterCodes = fields
93-
.map((field) => RawCode.fromParts([
94-
'required',
95-
' ',
96-
field.identifier,
97-
]))
98+
.map(
99+
(field) => RawCode.fromParts([
100+
'required',
101+
' ',
102+
field.identifier,
103+
]),
104+
)
98105
.toList();
99106
final constructorName = clazz.identifier.name;
100107
final constructorCode = DeclarationCode.fromParts(
@@ -135,6 +142,7 @@ macro class Thema
135142
required MemberDeclarationBuilder builder,
136143
}) async {
137144
final doubleIdentifier =
145+
// ignore: deprecated_member_use
138146
await builder.resolveIdentifier(_dartCore, 'double');
139147
final leapFirstParameterCode = ParameterCode(
140148
keywords: ['covariant'],
@@ -181,24 +189,26 @@ macro class Thema
181189
return RawCode.fromParts([
182190
'$fieldName:',
183191
' ',
184-
'$fieldName',
192+
fieldName,
185193
' ?? ',
186194
field.identifier,
187195
]);
188196
},
189197
).toList();
190-
final copyWithFunctionBodyCode = FunctionBodyCode.fromParts([
191-
'{',
192-
RawCode.fromParts([
193-
'return',
194-
' ',
195-
clazz.identifier,
196-
'(',
197-
]).indent(size: 4),
198-
...instancePareterCodes.trailingComma().indent(size: 6),
199-
');'.indent(size: 4),
200-
'}'.indent(),
201-
].joinAsCode('\n'));
198+
final copyWithFunctionBodyCode = FunctionBodyCode.fromParts(
199+
[
200+
'{',
201+
RawCode.fromParts([
202+
'return',
203+
' ',
204+
clazz.identifier,
205+
'(',
206+
]).indent(size: 4),
207+
...instancePareterCodes.trailingComma().indent(size: 6),
208+
');'.indent(size: 4),
209+
'}'.indent(),
210+
].joinAsCode('\n'),
211+
);
202212

203213
final builder =
204214
await typeDefinisionBuilder.buildMethod(copyWithDeclaration.identifier);
@@ -221,8 +231,10 @@ macro class Thema
221231
name: 'other',
222232
);
223233
final themeExtensionIdentifier = await typeDefinisionBuilder
234+
// ignore: deprecated_member_use
224235
.resolveIdentifier(_flutterMaterial, 'ThemeExtension');
225236
final doubleIdentifier =
237+
// ignore: deprecated_member_use
226238
await typeDefinisionBuilder.resolveIdentifier(_dartCore, 'double');
227239
final leapSecondParameterCode = ParameterCode(
228240
type: NamedTypeAnnotationCode(name: doubleIdentifier),
@@ -243,7 +255,8 @@ macro class Thema
243255
'$fieldName:',
244256
' ',
245257
field.identifier,
246-
'.lerp(${leapFirstParameterCode.name}.$fieldName, ${leapSecondParameterCode.name})',
258+
// ignore: lines_longer_than_80_chars
259+
'.lerp(${leapFirstParameterCode.name}.$fieldName, ${leapSecondParameterCode.name},)',
247260
],
248261
);
249262
}
@@ -254,28 +267,33 @@ macro class Thema
254267
fieldTypeCode,
255268
'.lerp(',
256269
field.identifier,
270+
// ignore: lines_longer_than_80_chars
257271
', ${leapFirstParameterCode.name}.$fieldName, ${leapSecondParameterCode.name})!',
258272
],
259273
);
260274
}),
261275
);
262-
final leapFunctionBodyCode = FunctionBodyCode.fromParts([
263-
'{',
264-
RawCode.fromParts([
265-
'if (${leapFirstParameterCode.name} == null) {'.indent(size: 4),
266-
'return this;'.indent(size: 6),
267-
'}'.indent(size: 4),
268-
].joinAsCode('\n')),
269-
RawCode.fromParts([
270-
'return',
271-
' ',
272-
clazz.identifier,
273-
'(',
274-
]).indent(size: 4),
275-
...instancePareterCodes.trailingComma().indent(size: 6),
276-
');'.indent(size: 4),
277-
'}'.indent(),
278-
].joinAsCode('\n'));
276+
final leapFunctionBodyCode = FunctionBodyCode.fromParts(
277+
[
278+
'{',
279+
RawCode.fromParts(
280+
[
281+
'if (${leapFirstParameterCode.name} == null) {'.indent(size: 4),
282+
'return this;'.indent(size: 6),
283+
'}'.indent(size: 4),
284+
].joinAsCode('\n'),
285+
),
286+
RawCode.fromParts([
287+
'return',
288+
' ',
289+
clazz.identifier,
290+
'(',
291+
]).indent(size: 4),
292+
...instancePareterCodes.trailingComma().indent(size: 6),
293+
');'.indent(size: 4),
294+
'}'.indent(),
295+
].joinAsCode('\n'),
296+
);
279297

280298
final builder =
281299
await typeDefinisionBuilder.buildMethod(leapDeclaration.identifier);
@@ -294,12 +312,12 @@ extension _Indent<T extends Object> on T {
294312

295313
extension _Indents<T extends Object> on List<T> {
296314
List<Code> indent({int size = 2}) {
297-
return this.map((element) => element.indent(size: size)).toList();
315+
return map((element) => element.indent(size: size)).toList();
298316
}
299317
}
300318

301319
extension _Commas<T extends Object> on List<T> {
302320
List<Code> trailingComma() {
303-
return this.map((element) => RawCode.fromParts([element, ','])).toList();
321+
return map((element) => RawCode.fromParts([element, ','])).toList();
304322
}
305323
}

packages/thema/pubspec.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ environment:
2222
dependencies:
2323
collection: ^1.18.0
2424
macros: ^0.1.0
25+
26+
dev_dependencies:
27+
very_good_analysis: 6.0.0

packages/thema_test/pubspec.yaml

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ environment:
88
dependencies:
99
flutter:
1010
sdk: flutter
11-
12-
dev_dependencies:
1311
thema:
1412
path: ../thema
13+
14+
dev_dependencies:
1515
flutter_test:
1616
sdk: flutter
17+
very_good_analysis: 6.0.0

0 commit comments

Comments
 (0)