Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI Utils: file-scoped namespaces and house-keeping #47430

Merged
merged 6 commits into from
Mar 11, 2025

Conversation

MiYanni
Copy link
Member

@MiYanni MiYanni commented Mar 10, 2025

Tip

Hide whitespace changes to review this PR.

Summary

I'm continuing doing general cleanup in the CLI codespace.

Changes

  • Used file-scoped namespaces for all .cs files in the Utils project
  • Fixed a couple of outdated namespaces
  • Renamed file to FileAccessRetrier.cs to match class name
  • Minor syntax and formatting changes

MiYanni added 4 commits March 10, 2025 15:34
… (non extension) classes to use file-scoped namespaces. Updated exclusion.dic with some more domain-specific words.
# Conflicts:
#	src/Cli/Microsoft.DotNet.Cli.Utils/EnvironmentProvider.cs
#	src/Cli/Microsoft.DotNet.Cli.Utils/GracefulException.cs
#	src/Cli/Microsoft.DotNet.Cli.Utils/MSBuildForwardingAppWithoutLogging.cs
#	src/Cli/Microsoft.TemplateEngine.Cli/TemplatePackageCoordinator.cs
#	src/Cli/dotnet/CommandFactory/CommandResolution/PackagedCommandSpecFactory.cs
#	src/Cli/dotnet/commands/dotnet-test/MSBuildUtility.cs
@MiYanni MiYanni requested review from a team and Copilot March 10, 2025 23:52
@MiYanni MiYanni requested review from a team as code owners March 10, 2025 23:52
@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Request triage from a team member label Mar 10, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Overview

This PR cleans up the CLI codespace by standardizing namespace declarations to file-scoped syntax and performing general code refactoring.

  • Converts multi-line namespace declarations into file-scoped namespaces in multiple files
  • Introduces minor refactors such as static method conversion in Command.cs and lambda expression usage in ArgumentEscaper.cs
  • Updates the DotnetFiles.cs property initialization style

Reviewed Changes

File Description
DotnetVersionFile.cs, DotDefaultPathCorrector.cs, DependencyProvider.cs, Command.cs, DebugHelper.cs, CommandUnknownException.cs, AnsiConsole.cs, ExponentialRetry.cs, EnvironmentProvider.cs, CommandResult.cs, CommandAvailableAsDotNetToolException.cs, CommandLoggingContext.cs, Constants.cs Converted to file-scoped namespaces and removed extraneous closing braces
Env.cs Refactored to use expression-bodied members with a readonly environment provider
BlockingMemoryStream.cs Changed the way the BlockingCollection is instantiated
ArgumentEscaper.cs Refactored multi-line method definitions into expression-bodied members

Copilot reviewed 93 out of 93 changed files in this pull request and generated 1 comment.

public int ExitCode { get; }
public string? StdOut { get; }
public string? StdErr { get; }
public readonly struct CommandResult(ProcessStartInfo startInfo, int exitCode, string? stdOut, string? stdErr)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we like primary constructors? 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't aware of it, but I like it

@@ -1,7 +1,9 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#if NETCOREAPP
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd personally rather let usings slide even if they aren't necessary as long as they aren't harmful for this sort of case

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There doesn't seem to be consistency as some files explicitly include usings within a #if directive (likely necessary) while others don't. I'd rather be explicit because to the IDE, this statement appears greyed out unless you have the correct directives defined based on the configuration view you're using. It is a little bit more "correct" this way.

@@ -196,7 +196,7 @@ private Task<IResponse> OnRequest(IRequest request)

default:
// If it doesn't match any of the above, throw an exception
throw new NotSupportedException(string.Format(LocalizableStrings.CmdUnsupportedMessageRequestTypeException, request.GetType()));
throw new NotSupportedException(string.Format(Microsoft.DotNet.Tools.Test.LocalizableStrings.CmdUnsupportedMessageRequestTypeException, request.GetType()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this level of specificity really needed? Seemed like there are several instances late in this PR

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LocalizableStrings exists in multiple namespaces. The change for some of the files to use the correct Utils namespace made a conflict exist. This resolves the conflict.

In this specific case, Microsoft.DotNet.Tools.Common did not have LocalizableStrings but Microsoft.DotNet.Cli.Utils does. That's why there is a conflict now as that class also exists in Microsoft.DotNet.Tools.Test. The only other way is to create a using alias for this version of that class and use that alias here.

@MiYanni MiYanni enabled auto-merge March 11, 2025 00:28
@MiYanni MiYanni merged commit c8cd570 into dotnet:main Mar 11, 2025
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-CLI untriaged Request triage from a team member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants