Skip to content

Commit b2ffb98

Browse files
authored
Analyze and format with Dart 3.7 (#240)
1 parent ff290b5 commit b2ffb98

File tree

22 files changed

+2093
-2065
lines changed

22 files changed

+2093
-2065
lines changed

.github/workflows/dart.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,23 @@ jobs:
3939
- name: mono_repo self validate
4040
run: dart pub global run mono_repo generate --validate
4141
job_002:
42-
name: "analyzer_and_format; Dart 3.5.0; PKGS: pkgs/analysis_defaults, pkgs/dash_design, pkgs/excerpter, pkgs/inject_dartpad; `dart format --output=none --set-exit-if-changed .`, `dart analyze --fatal-infos .`"
42+
name: "analyzer_and_format; Dart 3.7.0; PKGS: pkgs/analysis_defaults, pkgs/dash_design, pkgs/excerpter, pkgs/inject_dartpad; `dart format --output=none --set-exit-if-changed .`, `dart analyze --fatal-infos .`"
4343
runs-on: ubuntu-latest
4444
steps:
4545
- name: Cache Pub hosted dependencies
4646
uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf
4747
with:
4848
path: "~/.pub-cache/hosted"
49-
key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0;packages:pkgs/analysis_defaults-pkgs/dash_design-pkgs/excerpter-pkgs/inject_dartpad;commands:format-analyze"
49+
key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.7.0;packages:pkgs/analysis_defaults-pkgs/dash_design-pkgs/excerpter-pkgs/inject_dartpad;commands:format-analyze"
5050
restore-keys: |
51-
os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0;packages:pkgs/analysis_defaults-pkgs/dash_design-pkgs/excerpter-pkgs/inject_dartpad
52-
os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0
51+
os:ubuntu-latest;pub-cache-hosted;sdk:3.7.0;packages:pkgs/analysis_defaults-pkgs/dash_design-pkgs/excerpter-pkgs/inject_dartpad
52+
os:ubuntu-latest;pub-cache-hosted;sdk:3.7.0
5353
os:ubuntu-latest;pub-cache-hosted
5454
os:ubuntu-latest
5555
- name: Setup Dart SDK
5656
uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c
5757
with:
58-
sdk: "3.5.0"
58+
sdk: "3.7.0"
5959
- id: checkout
6060
name: Checkout repository
6161
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
@@ -185,23 +185,23 @@ jobs:
185185
if: "always() && steps.pkgs_inject_dartpad_pub_upgrade.conclusion == 'success'"
186186
working-directory: pkgs/inject_dartpad
187187
job_004:
188-
name: "unit_test; Dart 3.5.0; PKG: pkgs/excerpter; `dart test`"
188+
name: "unit_test; Dart 3.7.0; PKG: pkgs/excerpter; `dart test`"
189189
runs-on: ubuntu-latest
190190
steps:
191191
- name: Cache Pub hosted dependencies
192192
uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf
193193
with:
194194
path: "~/.pub-cache/hosted"
195-
key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0;packages:pkgs/excerpter;commands:test"
195+
key: "os:ubuntu-latest;pub-cache-hosted;sdk:3.7.0;packages:pkgs/excerpter;commands:test"
196196
restore-keys: |
197-
os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0;packages:pkgs/excerpter
198-
os:ubuntu-latest;pub-cache-hosted;sdk:3.5.0
197+
os:ubuntu-latest;pub-cache-hosted;sdk:3.7.0;packages:pkgs/excerpter
198+
os:ubuntu-latest;pub-cache-hosted;sdk:3.7.0
199199
os:ubuntu-latest;pub-cache-hosted
200200
os:ubuntu-latest
201201
- name: Setup Dart SDK
202202
uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c
203203
with:
204-
sdk: "3.5.0"
204+
sdk: "3.7.0"
205205
- id: checkout
206206
name: Checkout repository
207207
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683

pkgs/analysis_defaults/lib/analysis.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ linter:
2323
- unnecessary_breaks
2424
- unnecessary_null_aware_operator_on_extension_on_nullable
2525
- use_enums
26+
- use_truncating_division

pkgs/analysis_defaults/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ description: Analysis defaults for Dart/Flutter site tools.
33
publish_to: none
44

55
environment:
6-
sdk: ^3.5.0
6+
sdk: ^3.7.0
77

88
# NOTE: Code is not allowed in this package.
99
# Do not add dependencies besides the underlying lints package.
1010
dependencies:
11-
dart_flutter_team_lints: ^3.2.1
11+
dart_flutter_team_lints: ^3.4.0

pkgs/dash_design/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ publish_to: none
55
repository: https://github.com/dart-lang/site-shared/tree/main/pkgs/dash_design
66

77
environment:
8-
sdk: ^3.5.0
8+
sdk: ^3.7.0
99

1010
dev_dependencies:
1111
analysis_defaults:

pkgs/dash_design/test/style_test.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ import 'package:test/test.dart';
1010

1111
void main() {
1212
test('Can build styles.scss file', () {
13-
final compileResult = sass.compileToResult(_stylesPath!,
14-
fatalDeprecations: sass.Deprecation.values.where((d) => !d.isFuture));
13+
final compileResult = sass.compileToResult(
14+
_stylesPath!,
15+
fatalDeprecations: sass.Deprecation.values.where((d) => !d.isFuture),
16+
);
1517
expect(compileResult.css, contains('--dash-default-font-family'));
1618
});
1719
}

pkgs/excerpter/bin/excerpter.dart

Lines changed: 55 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ Future<void> runExcerpter(final List<String> arguments) async {
2626
final excludePaths = results[_excludeOption] as List<String>? ?? const [];
2727
final plasterContent = results[_plasterContentOption] as String? ?? '...';
2828
final replaceInstructions = results[_replaceOption] as String?;
29-
final baseSourcePath =
30-
path.absolute(results[_baseSourcePathOption] as String? ?? path.current);
29+
final baseSourcePath = path.absolute(
30+
results[_baseSourcePathOption] as String? ?? path.current,
31+
);
3132

3233
if (results.rest.length != 1) {
3334
_printUsageAndExit(
@@ -36,12 +37,13 @@ Future<void> runExcerpter(final List<String> arguments) async {
3637
}
3738
final updatePath = path.absolute(results.rest.first);
3839

39-
final replaceTransforms = replaceInstructions == null
40-
? const <ReplaceTransform>[]
41-
: stringToReplaceTransforms(
42-
replaceInstructions,
43-
(e) => _printUsageAndExit(message: e),
44-
);
40+
final replaceTransforms =
41+
replaceInstructions == null
42+
? const <ReplaceTransform>[]
43+
: stringToReplaceTransforms(
44+
replaceInstructions,
45+
(e) => _printUsageAndExit(message: e),
46+
);
4547

4648
final updater = Updater(
4749
baseSourcePath: baseSourcePath,
@@ -68,11 +70,13 @@ Future<void> runExcerpter(final List<String> arguments) async {
6870
print('');
6971
}
7072

71-
print('Processed ${result.filesVisited} out of '
72-
'${result.totalFilesToVisit} files: '
73-
'${result.excerptsNeedingUpdates} out of '
74-
'${result.excerptsVisited} excerpts visited '
75-
'${result.madeUpdates ? 'were updated' : 'need to be updated'}.');
73+
print(
74+
'Processed ${result.filesVisited} out of '
75+
'${result.totalFilesToVisit} files: '
76+
'${result.excerptsNeedingUpdates} out of '
77+
'${result.excerptsVisited} excerpts visited '
78+
'${result.madeUpdates ? 'were updated' : 'need to be updated'}.',
79+
);
7680

7781
if (result.errors.length case final amountOfErrors when amountOfErrors > 0) {
7882
io.exitCode = amountOfErrors;
@@ -81,38 +85,44 @@ Future<void> runExcerpter(final List<String> arguments) async {
8185
}
8286
}
8387

84-
final _argParser = ArgParser()
85-
..addFlag(
86-
_dryRunFlag,
87-
negatable: false,
88-
help: 'If the updater should only report if excerpts need to be updated.',
89-
)
90-
..addFlag(
91-
_failOnUpdateFlag,
92-
negatable: false,
93-
help:
94-
'Report a non-zero exit code if an excerpt is or needs to be updated.',
95-
)
96-
..addMultiOption(
97-
_excludeOption,
98-
help: 'Regular expressions of paths to exclude when '
99-
'processing a directory recursively.\n'
100-
'Dot files and directories are always excluded.',
101-
)
102-
..addOption(
103-
_baseSourcePathOption,
104-
help: 'The path to the directory containing the source files that '
105-
'excerpt regions should be retrieved from.',
106-
)
107-
..addOption(
108-
_plasterContentOption,
109-
help: 'The default plaster content, such as "..." or "···".',
110-
)
111-
..addOption(
112-
_replaceOption,
113-
help: 'A replacement to run on every excerpt.\n'
114-
'Refer to the package docs for syntax help.',
115-
);
88+
final _argParser =
89+
ArgParser()
90+
..addFlag(
91+
_dryRunFlag,
92+
negatable: false,
93+
help:
94+
'If the updater should only report if excerpts need to be updated.',
95+
)
96+
..addFlag(
97+
_failOnUpdateFlag,
98+
negatable: false,
99+
help:
100+
'Report a non-zero exit code if '
101+
'an excerpt is or needs to be updated.',
102+
)
103+
..addMultiOption(
104+
_excludeOption,
105+
help:
106+
'Regular expressions of paths to exclude when '
107+
'processing a directory recursively.\n'
108+
'Dot files and directories are always excluded.',
109+
)
110+
..addOption(
111+
_baseSourcePathOption,
112+
help:
113+
'The path to the directory containing the source files that '
114+
'excerpt regions should be retrieved from.',
115+
)
116+
..addOption(
117+
_plasterContentOption,
118+
help: 'The default plaster content, such as "..." or "···".',
119+
)
120+
..addOption(
121+
_replaceOption,
122+
help:
123+
'A replacement to run on every excerpt.\n'
124+
'Refer to the package docs for syntax help.',
125+
);
116126

117127
/// Print the usage information for this command,
118128
/// optionally with the specified error [message] and [exitCode],

pkgs/excerpter/lib/src/extract.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,5 +210,6 @@ final class ExtractException implements Exception {
210210

211211
const String _entireFileRegionName = '';
212212

213-
final RegExp _docRegionDirective =
214-
RegExp(r'^.*?#(?<end>end)?docregion\s(?<regions>[a-zA-Z0-9,_\-\s]+).*?$');
213+
final RegExp _docRegionDirective = RegExp(
214+
r'^.*?#(?<end>end)?docregion\s(?<regions>[a-zA-Z0-9,_\-\s]+).*?$',
215+
);

pkgs/excerpter/lib/src/inject.dart

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,9 @@ final class FileUpdater {
111111
}
112112

113113
final lineAfterInstruction = originalLines[lineIndex];
114-
final fencedCodeBlock =
115-
_codeBlockStart.firstMatch(lineAfterInstruction);
114+
final fencedCodeBlock = _codeBlockStart.firstMatch(
115+
lineAfterInstruction,
116+
);
116117
if (fencedCodeBlock == null) {
117118
reportError(
118119
'An inject instruction must be followed by a code block '
@@ -206,13 +207,15 @@ final class FileUpdater {
206207
}
207208

208209
// Add back the indentation from the file and any from the instruction.
209-
updatedLines =
210-
IndentTransform(instructionIndent + (instruction.indentBy ?? 0))
211-
.transform(updatedLines);
210+
updatedLines = IndentTransform(
211+
instructionIndent + (instruction.indentBy ?? 0),
212+
).transform(updatedLines);
212213

213214
final updatedExcerpt = updatedLines.join('\n');
214-
if (!(const IterableEquality<String>()
215-
.equals(oldLines, updatedLines))) {
215+
if (!(const IterableEquality<String>().equals(
216+
oldLines,
217+
updatedLines,
218+
))) {
216219
excerptsUpdated.add((
217220
instructionLine: instructionLineNumber,
218221
updated: updatedExcerpt,
@@ -308,11 +311,13 @@ final RegExp _instructionPattern = RegExp(
308311

309312
final RegExp _instructionStart = RegExp(r'^<\?code-excerpt');
310313

311-
final RegExp _codeBlockStart =
312-
RegExp(r'^\s*(?<backticks>`{3,})(?<language>\S+).*?$');
314+
final RegExp _codeBlockStart = RegExp(
315+
r'^\s*(?<backticks>`{3,})(?<language>\S+).*?$',
316+
);
313317

314-
final RegExp _splitArgs =
315-
RegExp(r'(?<arg>[-\w]+)\s*(=\s*"(?<value>.*?)"\s*)\s*');
318+
final RegExp _splitArgs = RegExp(
319+
r'(?<arg>[-\w]+)\s*(=\s*"(?<value>.*?)"\s*)\s*',
320+
);
316321

317322
/// A code excerpt set or injection instruction
318323
/// found in a file being processed.
@@ -340,21 +345,20 @@ sealed class _Instruction {
340345

341346
if (path == null) {
342347
if (argumentPairs.length != 1) {
343-
reportError(
344-
'A set instruction must have only one argument specified.',
345-
);
348+
reportError('A set instruction must have only one argument specified.');
346349
}
347350
final argName = argumentPairs.first.arg;
348351
final argValue = argumentPairs.first.value;
349352
return switch (argName) {
350353
'path-base' => _SetPathBaseInstruction(argValue),
351354
'plaster' => _SetPlasterInstruction(argValue),
352355
'replace' => _SetFileReplaceInstruction(
353-
stringToReplaceTransforms(argValue, reportError)),
356+
stringToReplaceTransforms(argValue, reportError),
357+
),
354358
_ => reportError(
355-
'A set instruction can only specify the '
356-
'`path-base`, `plaster`, and `replace` arguments.',
357-
),
359+
'A set instruction can only specify the '
360+
'`path-base`, `plaster`, and `replace` arguments.',
361+
),
358362
};
359363
}
360364

@@ -461,9 +465,7 @@ final class _InjectInstruction extends _Instruction {
461465
final indentBy = indentByString == null ? null : int.parse(indentByString);
462466

463467
if (indentBy != null && indentBy < 0) {
464-
reportError(
465-
'The `indent-by` argument must be positive.',
466-
);
468+
reportError('The `indent-by` argument must be positive.');
467469
}
468470

469471
return _InjectInstruction(

0 commit comments

Comments
 (0)