Skip to content

Commit 2b4e59a

Browse files
thomhurstclaude
andauthored
refactor: Extract duplicate dotnet format logic into helper method (#1464)
* chore: Add .worktrees/ to .gitignore for parallel development 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * refactor: Extract duplicate dotnet format logic into helper method Consolidates 4 nearly identical DotNetFormatOptions configurations into a single reusable RunDotNetFormat helper method with parameters for whitespaceOnly and verifyNoChanges variations. Fixes #1460 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 9374bfc commit 2b4e59a

1 file changed

Lines changed: 21 additions & 27 deletions

File tree

src/ModularPipelines.Build/Modules/CodeFormattedNicelyModule.cs

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,10 @@ public Task<SkipDecision> ShouldSkip(IPipelineContext context)
4444

4545
try
4646
{
47-
await context.DotNet().Format(new DotNetFormatOptions
48-
{
49-
Arguments = ["whitespace"],
50-
WorkingDirectory = context.Git().RootDirectory,
51-
VerifyNoChanges = true,
52-
Severity = "info",
53-
}, cancellationToken);
47+
await RunDotNetFormat(context, whitespaceOnly: true, verifyNoChanges: true, cancellationToken);
5448

5549
// The code hasn't been formatted nicely!
56-
return await context.DotNet().Format(new DotNetFormatOptions
57-
{
58-
WorkingDirectory = context.Git().RootDirectory,
59-
VerifyNoChanges = true,
60-
Severity = "info",
61-
}, cancellationToken);
50+
return await RunDotNetFormat(context, whitespaceOnly: false, verifyNoChanges: true, cancellationToken);
6251
}
6352
catch (Exception)
6453
{
@@ -70,20 +59,8 @@ await context.DotNet().Format(new DotNetFormatOptions
7059

7160
ArgumentNullException.ThrowIfNull(_githubSettings.Value.StandardToken);
7261

73-
await context.DotNet().Format(new DotNetFormatOptions
74-
{
75-
WorkingDirectory = context.Git().RootDirectory,
76-
VerifyNoChanges = false,
77-
Severity = "info",
78-
}, cancellationToken);
79-
80-
await context.DotNet().Format(new DotNetFormatOptions
81-
{
82-
Arguments = ["whitespace"],
83-
WorkingDirectory = context.Git().RootDirectory,
84-
VerifyNoChanges = false,
85-
Severity = "info",
86-
}, cancellationToken);
62+
await RunDotNetFormat(context, whitespaceOnly: false, verifyNoChanges: false, cancellationToken);
63+
await RunDotNetFormat(context, whitespaceOnly: true, verifyNoChanges: false, cancellationToken);
8764

8865
var branchTriggeringPullRequest = context.GitHub().EnvironmentVariables.HeadRef!;
8966

@@ -98,4 +75,21 @@ await GitHelpers.CommitAndPush(context, branchTriggeringPullRequest, DotnetForma
9875
throw new Exception("Formatting code. This run will abort. Another run will trigger with the formatted code.");
9976
}
10077
}
78+
79+
private static Task<CommandResult> RunDotNetFormat(
80+
IModuleContext context,
81+
bool whitespaceOnly,
82+
bool verifyNoChanges,
83+
CancellationToken cancellationToken)
84+
{
85+
var options = new DotNetFormatOptions
86+
{
87+
Arguments = whitespaceOnly ? ["whitespace"] : null,
88+
WorkingDirectory = context.Git().RootDirectory,
89+
VerifyNoChanges = verifyNoChanges,
90+
Severity = "info",
91+
};
92+
93+
return context.DotNet().Format(options, cancellationToken);
94+
}
10195
}

0 commit comments

Comments
 (0)