Skip to content

Commit

Permalink
Fix SdkInitializerContext.package when calling dart format (#258)
Browse files Browse the repository at this point in the history
  • Loading branch information
passsy authored Jul 22, 2024
1 parent ea519a9 commit 50e907c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion sidekick_core/lib/src/commands/format_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class FormatCommand extends Command {
lineLength: lineLength,
files: allDartFiles,
verify: verify,
workingDirectory: package.root,
);
_verifyThrow();
return;
Expand Down Expand Up @@ -159,6 +160,7 @@ class FormatCommand extends Command {
required int lineLength,
required Iterable<File> files,
bool verify = false,
Directory? workingDirectory,
}) async {
if (verify) {
print("Verifying $name");
Expand All @@ -177,14 +179,15 @@ class FormatCommand extends Command {
'-l',
'$lineLength',
if (!verify) '--fix',
...files.map((file) => file.path),
...files.map((file) => file.absolute.path),
if (verify) '--set-exit-if-changed',
if (verify) '--output=none',
],
nothrow: verify,
// Lines like `Changed x.dart`, `Formatted x files (y changed) in z seconds`
// should only be printed when the change is actually written to the files (when verify is false)
progress: progress,
workingDirectory: workingDirectory,
);
exitCode = completion.exitCode ?? 1;
if (exitCode != 0) {
Expand Down
10 changes: 10 additions & 0 deletions sidekick_core/test/format_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ name: moshi
final runner = initializeSidekick(
dartSdkPath: systemDartSdkPath(),
);

SdkInitializerContext? sdkInitializerContext;
addSdkInitializer((context) {
sdkInitializerContext = context;
});
runner.addCommand(FormatCommand());
await runner.run(['format', '-p', 'moshi']);

Expand All @@ -136,6 +141,11 @@ name: moshi
_dartFile140,
);
expect(dir.file('moshi/lib/main.dart').readAsStringSync(), _dartFile80);
expect(sdkInitializerContext!.packageDir!.name, 'moshi');
expect(
sdkInitializerContext!.workingDirectory!.path,
dir.directory('moshi').path,
);
});
});

Expand Down

0 comments on commit 50e907c

Please sign in to comment.