Skip to content

Commit ff41446

Browse files
committed
Use Dart 3.7.0, reformat.
1 parent 2a6be7e commit ff41446

27 files changed

+787
-786
lines changed

.github/workflows/dart.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,23 @@ jobs:
4040
- name: mono_repo self validate
4141
run: dart pub global run mono_repo generate --validate
4242
job_002:
43-
name: "analyze_format; linux; Dart 3.6.0; PKG: source_gen; `dart analyze`"
43+
name: "analyze_format; linux; Dart 3.7.0; PKG: source_gen; `dart analyze`"
4444
runs-on: ubuntu-latest
4545
steps:
4646
- name: Cache Pub hosted dependencies
4747
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684
4848
with:
4949
path: "~/.pub-cache/hosted"
50-
key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:source_gen;commands:analyze_1"
50+
key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.7.0;packages:source_gen;commands:analyze_1"
5151
restore-keys: |
52-
os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:source_gen
53-
os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0
52+
os:ubuntu-latest;pub-cache-hosted;sdk:3.7.0;packages:source_gen
53+
os:ubuntu-latest;pub-cache-hosted;sdk:3.7.0
5454
os:ubuntu-latest;pub-cache-hosted
5555
os:ubuntu-latest
5656
- name: Setup Dart SDK
5757
uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c
5858
with:
59-
sdk: "3.6.0"
59+
sdk: "3.7.0"
6060
- id: checkout
6161
name: Checkout repository
6262
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
@@ -177,23 +177,23 @@ jobs:
177177
- job_002
178178
- job_003
179179
job_005:
180-
name: "unit_test; linux; Dart 3.6.0; PKG: source_gen; `dart test`"
180+
name: "unit_test; linux; Dart 3.7.0; PKG: source_gen; `dart test`"
181181
runs-on: ubuntu-latest
182182
steps:
183183
- name: Cache Pub hosted dependencies
184184
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684
185185
with:
186186
path: "~/.pub-cache/hosted"
187-
key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:source_gen;commands:test_1"
187+
key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.7.0;packages:source_gen;commands:test_1"
188188
restore-keys: |
189-
os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0;packages:source_gen
190-
os:ubuntu-latest;pub-cache-hosted;sdk:3.6.0
189+
os:ubuntu-latest;pub-cache-hosted;sdk:3.7.0;packages:source_gen
190+
os:ubuntu-latest;pub-cache-hosted;sdk:3.7.0
191191
os:ubuntu-latest;pub-cache-hosted
192192
os:ubuntu-latest
193193
- name: Setup Dart SDK
194194
uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c
195195
with:
196-
sdk: "3.6.0"
196+
sdk: "3.7.0"
197197
- id: checkout
198198
name: Checkout repository
199199
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
@@ -279,13 +279,13 @@ jobs:
279279
- job_002
280280
- job_003
281281
job_008:
282-
name: "unit_test; windows; Dart 3.6.0; PKG: source_gen; `dart test`"
282+
name: "unit_test; windows; Dart 3.7.0; PKG: source_gen; `dart test`"
283283
runs-on: windows-latest
284284
steps:
285285
- name: Setup Dart SDK
286286
uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c
287287
with:
288-
sdk: "3.6.0"
288+
sdk: "3.7.0"
289289
- id: checkout
290290
name: Checkout repository
291291
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683

analysis_options.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ linter:
2929
- prefer_const_declarations
3030
- prefer_expression_function_bodies
3131
- prefer_final_locals
32-
- require_trailing_commas
3332
- sort_child_properties_last
3433
- unnecessary_await_in_return
3534
- use_full_hex_values_for_flutter_colors

source_gen/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.0.1-wip
2+
3+
- Require Dart 3.7.0
4+
15
## 2.0.0
26

37
- **Breaking Change**: Change `formatOutput` function to accept a language

source_gen/lib/builder.dart

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ Builder combiningBuilder([BuilderOptions options = BuilderOptions.empty]) {
3333
optionsMap.remove('ignore_for_file') as List? ?? <String>[],
3434
);
3535
final preamble = optionsMap.remove('preamble') as String? ?? '';
36-
final buildExtensions =
37-
validatedBuildExtensionsFrom(optionsMap, _defaultExtensions);
36+
final buildExtensions = validatedBuildExtensionsFrom(
37+
optionsMap,
38+
_defaultExtensions,
39+
);
3840

3941
final builder = CombiningBuilder(
4042
includePartName: includePartName,
@@ -75,18 +77,19 @@ class CombiningBuilder implements Builder {
7577
Set<String>? ignoreForFile,
7678
String? preamble,
7779
this.buildExtensions = _defaultExtensions,
78-
}) : _includePartName = includePartName ?? false,
79-
_ignoreForFile = ignoreForFile ?? const <String>{},
80-
_preamble = preamble ?? '';
80+
}) : _includePartName = includePartName ?? false,
81+
_ignoreForFile = ignoreForFile ?? const <String>{},
82+
_preamble = preamble ?? '';
8183

8284
@override
8385
Future<void> build(BuildStep buildStep) async {
8486
// Pattern used for `findAssets`, which must be glob-compatible
8587
final assetPath = buildStep.inputId.path;
8688
final pattern = '${p.withoutExtension(Glob.quote(assetPath))}.*$_partFiles';
8789

88-
final inputBaseName =
89-
p.basenameWithoutExtension(buildStep.inputId.pathSegments.last);
90+
final inputBaseName = p.basenameWithoutExtension(
91+
buildStep.inputId.pathSegments.last,
92+
);
9093

9194
// Pattern used to ensure items are only considered if they match
9295
// [file name without extension].[valid part id].[part file extension]
@@ -101,11 +104,12 @@ class CombiningBuilder implements Builder {
101104
].join(),
102105
);
103106

104-
final assetIds = await buildStep
105-
.findAssets(Glob(pattern))
106-
.where((id) => restrictedPattern.hasMatch(id.pathSegments.last))
107-
.toList()
108-
..sort();
107+
final assetIds =
108+
await buildStep
109+
.findAssets(Glob(pattern))
110+
.where((id) => restrictedPattern.hasMatch(id.pathSegments.last))
111+
.toList()
112+
..sort();
109113

110114
final assets = await Stream.fromIterable(assetIds)
111115
.asyncMap((id) async {
@@ -124,8 +128,9 @@ class CombiningBuilder implements Builder {
124128
final partOfUri = uriOfPartial(inputLibrary, buildStep.inputId, outputId);
125129

126130
// Ensure that the input has a correct `part` statement.
127-
final libraryUnit =
128-
await buildStep.resolver.compilationUnitFor(buildStep.inputId);
131+
final libraryUnit = await buildStep.resolver.compilationUnitFor(
132+
buildStep.inputId,
133+
);
129134
final part = computePartUrl(buildStep.inputId, outputId);
130135
if (!hasExpectedPartDirective(libraryUnit, part)) {
131136
log.warning(
@@ -135,9 +140,10 @@ class CombiningBuilder implements Builder {
135140
return;
136141
}
137142

138-
final ignoreForFile = _ignoreForFile.isEmpty
139-
? ''
140-
: '\n// ignore_for_file: ${_ignoreForFile.join(', ')}\n';
143+
final ignoreForFile =
144+
_ignoreForFile.isEmpty
145+
? ''
146+
: '\n// ignore_for_file: ${_ignoreForFile.join(', ')}\n';
141147

142148
final preamble = _preamble.isEmpty ? '' : '\n$_preamble\n';
143149

source_gen/lib/src/builder.dart

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,15 @@ class _Builder extends Builder {
5757
bool? writeDescriptions,
5858
this.allowSyntaxErrors = false,
5959
BuilderOptions? options,
60-
}) : _generatedExtension = generatedExtension,
61-
buildExtensions = validatedBuildExtensionsFrom(
62-
options != null ? Map.of(options.config) : null, {
63-
'.dart': [
64-
generatedExtension,
65-
...additionalOutputExtensions,
66-
],
67-
}),
68-
_writeDescriptions = writeDescriptions ?? true,
69-
_header = (header ?? defaultFileHeader).trim() {
60+
}) : _generatedExtension = generatedExtension,
61+
buildExtensions = validatedBuildExtensionsFrom(
62+
options != null ? Map.of(options.config) : null,
63+
{
64+
'.dart': [generatedExtension, ...additionalOutputExtensions],
65+
},
66+
),
67+
_writeDescriptions = writeDescriptions ?? true,
68+
_header = (header ?? defaultFileHeader).trim() {
7069
if (_generatedExtension.isEmpty || !_generatedExtension.startsWith('.')) {
7170
throw ArgumentError.value(
7271
_generatedExtension,
@@ -102,8 +101,10 @@ class _Builder extends Builder {
102101
return;
103102
}
104103

105-
final lib = await buildStep.resolver
106-
.libraryFor(buildStep.inputId, allowSyntaxErrors: allowSyntaxErrors);
104+
final lib = await buildStep.resolver.libraryFor(
105+
buildStep.inputId,
106+
allowSyntaxErrors: allowSyntaxErrors,
107+
);
107108
await _generateForLibrary(lib, buildStep);
108109
}
109110

@@ -138,10 +139,13 @@ class _Builder extends Builder {
138139
..writeln('part of \'$partOfUri\';');
139140
final part = computePartUrl(buildStep.inputId, outputId);
140141

141-
final libraryUnit =
142-
await buildStep.resolver.compilationUnitFor(buildStep.inputId);
143-
final hasLibraryPartDirectiveWithOutputUri =
144-
hasExpectedPartDirective(libraryUnit, part);
142+
final libraryUnit = await buildStep.resolver.compilationUnitFor(
143+
buildStep.inputId,
144+
);
145+
final hasLibraryPartDirectiveWithOutputUri = hasExpectedPartDirective(
146+
libraryUnit,
147+
part,
148+
);
145149
if (!hasLibraryPartDirectiveWithOutputUri) {
146150
// TODO: Upgrade to error in a future breaking change?
147151
log.warning(
@@ -163,8 +167,9 @@ class _Builder extends Builder {
163167
..writeln()
164168
..writeln(_headerLine)
165169
..writeAll(
166-
LineSplitter.split(item.generatorDescription)
167-
.map((line) => '// $line\n'),
170+
LineSplitter.split(
171+
item.generatorDescription,
172+
).map((line) => '// $line\n'),
168173
)
169174
..writeln(_headerLine)
170175
..writeln();
@@ -176,8 +181,10 @@ class _Builder extends Builder {
176181
var genPartContent = contentBuffer.toString();
177182

178183
try {
179-
genPartContent =
180-
formatOutput(genPartContent, library.languageVersion.effective);
184+
genPartContent = formatOutput(
185+
genPartContent,
186+
library.languageVersion.effective,
187+
);
181188
} catch (e, stack) {
182189
log.severe(
183190
'''
@@ -240,10 +247,7 @@ class SharedPartBuilder extends _Builder {
240247
super.additionalOutputExtensions,
241248
super.allowSyntaxErrors,
242249
super.writeDescriptions,
243-
}) : super(
244-
generatedExtension: '.$partId.g.part',
245-
header: '',
246-
) {
250+
}) : super(generatedExtension: '.$partId.g.part', header: '') {
247251
if (!_partIdRegExp.hasMatch(partId)) {
248252
throw ArgumentError.value(
249253
partId,
@@ -304,9 +308,7 @@ class PartBuilder extends _Builder {
304308
super.header,
305309
super.allowSyntaxErrors,
306310
super.options,
307-
}) : super(
308-
generatedExtension: generatedExtension,
309-
);
311+
}) : super(generatedExtension: generatedExtension);
310312
}
311313

312314
/// A [Builder] which generates standalone Dart library files.

source_gen/lib/src/constants/revive.dart

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ Revivable reviveInstance(DartObject object, [LibraryElement? origin]) {
3535
origin ??= element!.library;
3636
var url = Uri.parse(urlOfElement(element!));
3737
if (element is FunctionElement) {
38-
return Revivable._(
39-
source: url.removeFragment(),
40-
accessor: element.name,
41-
);
38+
return Revivable._(source: url.removeFragment(), accessor: element.name);
4239
}
4340
if (element is MethodElement && element.isStatic) {
4441
return Revivable._(
@@ -68,8 +65,9 @@ Revivable reviveInstance(DartObject object, [LibraryElement? origin]) {
6865
}
6966

7067
for (final type in origin!.definingCompilationUnit.classes) {
71-
for (final e in type.fields
72-
.where((f) => f.isConst && f.computeConstantValue() == object)) {
68+
for (final e in type.fields.where(
69+
(f) => f.isConst && f.computeConstantValue() == object,
70+
)) {
7371
final result = Revivable._(
7472
source: url.removeFragment(),
7573
accessor: '${type.name}.${e.name}',

source_gen/lib/src/generated_output.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ class GeneratedOutput {
99
final String generatorDescription;
1010

1111
GeneratedOutput(Generator generator, this.output)
12-
: assert(output.isNotEmpty),
13-
// assuming length check is cheaper than simple string equality
14-
assert(output.length == output.trim().length),
15-
generatorDescription = _toString(generator);
12+
: assert(output.isNotEmpty),
13+
// assuming length check is cheaper than simple string equality
14+
assert(output.length == output.trim().length),
15+
generatorDescription = _toString(generator);
1616

1717
static String _toString(Generator generator) {
1818
final output = generator.toString();

source_gen/lib/src/library.dart

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ class LibraryReader {
3535

3636
/// All of the declarations in this library.
3737
Iterable<Element> get allElements => [
38-
element,
39-
...element.topLevelElements,
40-
...element.definingCompilationUnit.libraryImports,
41-
...element.definingCompilationUnit.libraryExports,
42-
...element.definingCompilationUnit.parts,
43-
];
38+
element,
39+
...element.topLevelElements,
40+
...element.definingCompilationUnit.libraryImports,
41+
...element.definingCompilationUnit.libraryExports,
42+
...element.definingCompilationUnit.parts,
43+
];
4444

4545
/// All of the declarations in this library annotated with [checker].
4646
Iterable<AnnotatedElement> annotatedWith(
@@ -101,9 +101,10 @@ class LibraryReader {
101101
Uri pathToUrl(dynamic toUrlOrString) {
102102
// TODO: https://github.com/dart-lang/source_gen/issues/672 - Take Object
103103
ArgumentError.checkNotNull(toUrlOrString, 'toUrlOrString');
104-
final to = toUrlOrString is Uri
105-
? toUrlOrString
106-
: Uri.parse(toUrlOrString as String);
104+
final to =
105+
toUrlOrString is Uri
106+
? toUrlOrString
107+
: Uri.parse(toUrlOrString as String);
107108
if (to.scheme == 'dart') {
108109
// Convert dart:core/map.dart to dart:core.
109110
return normalizeDartUrl(to);
@@ -131,15 +132,10 @@ class LibraryReader {
131132
return Uri(path: to.pathSegments.last);
132133
}
133134
final relative = p.toUri(
134-
p.relative(
135-
to.toString(),
136-
from: from.toString(),
137-
),
135+
p.relative(to.toString(), from: from.toString()),
138136
);
139137
// We now have a URL like "../b.dart", but we just want "b.dart".
140-
return relative.replace(
141-
pathSegments: relative.pathSegments.skip(1),
142-
);
138+
return relative.replace(pathSegments: relative.pathSegments.skip(1));
143139
}
144140
throw ArgumentError.value(to, 'to', 'Not relative to $from');
145141
}

source_gen/lib/src/output_helpers.dart

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,21 @@ Stream<String> normalizeGeneratorOutput(Object? value) {
2121
}
2222

2323
if (value is Stream) {
24-
return value.where((e) => e != null).map((e) {
25-
if (e is String) {
26-
return e.trim();
27-
}
24+
return value
25+
.where((e) => e != null)
26+
.map((e) {
27+
if (e is String) {
28+
return e.trim();
29+
}
2830

29-
throw _argError(e as Object);
30-
}).where((e) => e.isNotEmpty);
31+
throw _argError(e as Object);
32+
})
33+
.where((e) => e.isNotEmpty);
3134
}
3235
throw _argError(value);
3336
}
3437

3538
ArgumentError _argError(Object value) => ArgumentError(
36-
'Must be a String or be an Iterable/Stream containing String values. '
37-
'Found `${Error.safeToString(value)}` (${value.runtimeType}).',
38-
);
39+
'Must be a String or be an Iterable/Stream containing String values. '
40+
'Found `${Error.safeToString(value)}` (${value.runtimeType}).',
41+
);

0 commit comments

Comments
 (0)