-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18840 from jmarolf/feature/add-code-cleanup-comma…
…nd-handlers
- Loading branch information
Showing
53 changed files
with
2,519 additions
and
59 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
src/Cli/dotnet/commands/dotnet-cleanup/CleanupCommandParser.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
// | ||
|
||
using System.Collections.Generic; | ||
using System.CommandLine.Parsing; | ||
|
||
using Microsoft.DotNet.Cli.Format; | ||
|
||
namespace Microsoft.DotNet.Cli | ||
{ | ||
public class FormatCommand : AbstractFormatCommand | ||
{ | ||
protected override string ParseFrom => "dotnet format"; | ||
|
||
protected override List<string> AddArgs(ParseResult parseResult) | ||
{ | ||
var dotnetFormatArgs = new List<string>(); | ||
dotnetFormatArgs.AddProjectOrSolutionDotnetFormatArgs(parseResult); | ||
dotnetFormatArgs.AddCommonDotnetFormatArgs(parseResult); | ||
dotnetFormatArgs.AddFormattingDotnetFormatArgs(parseResult); | ||
dotnetFormatArgs.AddStyleDotnetFormatArgs(parseResult); | ||
dotnetFormatArgs.AddAnalyzerDotnetFormatArgs(parseResult); | ||
return dotnetFormatArgs; | ||
} | ||
|
||
public static int Run(string[] args) => new FormatCommand().RunCommand(args); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/Cli/dotnet/commands/dotnet-format/FormatCommandParser.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
// | ||
|
||
using System.CommandLine; | ||
using System.CommandLine.Invocation; | ||
|
||
using Microsoft.DotNet.Cli.Format; | ||
using LocalizableStrings = Microsoft.DotNet.Tools.Format.LocalizableStrings; | ||
using static Microsoft.DotNet.Cli.Format.FormatCommandCommon; | ||
using System.Threading.Tasks; | ||
|
||
namespace Microsoft.DotNet.Cli | ||
{ | ||
internal static partial class FormatCommandParser | ||
{ | ||
private static readonly FormatCommandDefaultHandler s_formatCommandHandler = new(); | ||
|
||
public static Command GetCommand() | ||
{ | ||
var formatCommand = new Command("format", LocalizableStrings.Formats_code_to_match_editorconfig_settings) | ||
{ | ||
FormatWhitespaceCommandParser.GetCommand(), | ||
FormatStyleCommandParser.GetCommand(), | ||
FormatAnalyzersCommandParser.GetCommand(), | ||
DiagnosticsOption, | ||
SeverityOption, | ||
}; | ||
formatCommand.AddCommonOptions(); | ||
formatCommand.Handler = s_formatCommandHandler; | ||
return formatCommand; | ||
} | ||
|
||
class FormatCommandDefaultHandler : ICommandHandler | ||
{ | ||
public Task<int> InvokeAsync(InvocationContext context) | ||
=> Task.FromResult(new FormatCommand().FromArgs(context.ParseResult).Execute()); | ||
} | ||
} | ||
} |
171 changes: 171 additions & 0 deletions
171
src/Cli/dotnet/commands/dotnet-format/LocalizableStrings.resx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<root> | ||
<!-- | ||
Microsoft ResX Schema | ||
Version 2.0 | ||
The primary goals of this format is to allow a simple XML format | ||
that is mostly human readable. The generation and parsing of the | ||
various data types are done through the TypeConverter classes | ||
associated with the data types. | ||
Example: | ||
... ado.net/XML headers & schema ... | ||
<resheader name="resmimetype">text/microsoft-resx</resheader> | ||
<resheader name="version">2.0</resheader> | ||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> | ||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> | ||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> | ||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> | ||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> | ||
<value>[base64 mime encoded serialized .NET Framework object]</value> | ||
</data> | ||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> | ||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> | ||
<comment>This is a comment</comment> | ||
</data> | ||
There are any number of "resheader" rows that contain simple | ||
name/value pairs. | ||
Each data row contains a name, and value. The row also contains a | ||
type or mimetype. Type corresponds to a .NET class that support | ||
text/value conversion through the TypeConverter architecture. | ||
Classes that don't support this are serialized and stored with the | ||
mimetype set. | ||
The mimetype is used for serialized objects, and tells the | ||
ResXResourceReader how to depersist the object. This is currently not | ||
extensible. For a given mimetype the value must be set accordingly: | ||
Note - application/x-microsoft.net.object.binary.base64 is the format | ||
that the ResXResourceWriter will generate, however the reader can | ||
read any of the formats listed below. | ||
mimetype: application/x-microsoft.net.object.binary.base64 | ||
value : The object must be serialized with | ||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter | ||
: and then encoded with base64 encoding. | ||
mimetype: application/x-microsoft.net.object.soap.base64 | ||
value : The object must be serialized with | ||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter | ||
: and then encoded with base64 encoding. | ||
mimetype: application/x-microsoft.net.object.bytearray.base64 | ||
value : The object must be serialized into a byte array | ||
: using a System.ComponentModel.TypeConverter | ||
: and then encoded with base64 encoding. | ||
--> | ||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> | ||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> | ||
<xsd:element name="root" msdata:IsDataSet="true"> | ||
<xsd:complexType> | ||
<xsd:choice maxOccurs="unbounded"> | ||
<xsd:element name="metadata"> | ||
<xsd:complexType> | ||
<xsd:sequence> | ||
<xsd:element name="value" type="xsd:string" minOccurs="0" /> | ||
</xsd:sequence> | ||
<xsd:attribute name="name" use="required" type="xsd:string" /> | ||
<xsd:attribute name="type" type="xsd:string" /> | ||
<xsd:attribute name="mimetype" type="xsd:string" /> | ||
<xsd:attribute ref="xml:space" /> | ||
</xsd:complexType> | ||
</xsd:element> | ||
<xsd:element name="assembly"> | ||
<xsd:complexType> | ||
<xsd:attribute name="alias" type="xsd:string" /> | ||
<xsd:attribute name="name" type="xsd:string" /> | ||
</xsd:complexType> | ||
</xsd:element> | ||
<xsd:element name="data"> | ||
<xsd:complexType> | ||
<xsd:sequence> | ||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> | ||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> | ||
</xsd:sequence> | ||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> | ||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> | ||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> | ||
<xsd:attribute ref="xml:space" /> | ||
</xsd:complexType> | ||
</xsd:element> | ||
<xsd:element name="resheader"> | ||
<xsd:complexType> | ||
<xsd:sequence> | ||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> | ||
</xsd:sequence> | ||
<xsd:attribute name="name" type="xsd:string" use="required" /> | ||
</xsd:complexType> | ||
</xsd:element> | ||
</xsd:choice> | ||
</xsd:complexType> | ||
</xsd:element> | ||
</xsd:schema> | ||
<resheader name="resmimetype"> | ||
<value>text/microsoft-resx</value> | ||
</resheader> | ||
<resheader name="version"> | ||
<value>2.0</value> | ||
</resheader> | ||
<resheader name="reader"> | ||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> | ||
</resheader> | ||
<resheader name="writer"> | ||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> | ||
</resheader> | ||
<data name="Accepts_a_file_path_which_if_provided_will_produce_a_json_report_in_the_given_directory" xml:space="preserve"> | ||
<value>Accepts a file path, which if provided, will produce a json report in the given directory.</value> | ||
</data> | ||
<data name="all_files_in_the_solution_or_project" xml:space="preserve"> | ||
<value>all files in the solution or project</value> | ||
</data> | ||
<data name="A_list_of_relative_file_or_folder_paths_to_exclude_from_formatting" xml:space="preserve"> | ||
<value>A list of relative file or folder paths to exclude from formatting.</value> | ||
</data> | ||
<data name="A_list_of_relative_file_or_folder_paths_to_include_in_formatting_All_files_are_formatted_if_empty" xml:space="preserve"> | ||
<value>A list of relative file or folder paths to include in formatting. All files are formatted if empty.</value> | ||
</data> | ||
<data name="A_space_separated_list_of_diagnostic_ids_to_use_as_a_filter_when_fixing_code_style_or_3rd_party_issues" xml:space="preserve"> | ||
<value>A space separated list of diagnostic ids to use as a filter when fixing code style or 3rd party issues.</value> | ||
</data> | ||
<data name="Doesnt_execute_an_implicit_restore_before_formatting" xml:space="preserve"> | ||
<value>Doesn't execute an implicit restore before formatting.</value> | ||
</data> | ||
<data name="Formats_code_to_match_editorconfig_settings" xml:space="preserve"> | ||
<value>Formats code to match editorconfig settings.</value> | ||
</data> | ||
<data name="Format_files_generated_by_the_SDK" xml:space="preserve"> | ||
<value>Format files generated by the SDK.</value> | ||
</data> | ||
<data name="Log_all_project_or_solution_load_information_to_a_binary_log_file" xml:space="preserve"> | ||
<value>Log all project or solution load information to a binary log file.</value> | ||
</data> | ||
<data name="none" xml:space="preserve"> | ||
<value>none</value> | ||
</data> | ||
<data name="Run_3rd_party_analyzers_ and_apply_fixes" xml:space="preserve"> | ||
<value>Run 3rd party analyzers and apply fixes.</value> | ||
</data> | ||
<data name="Run_code_style_analyzers_and_apply_fixes" xml:space="preserve"> | ||
<value>Run code style analyzers and apply fixes.</value> | ||
</data> | ||
<data name="Run_whitespace_formatting" xml:space="preserve"> | ||
<value>Run whitespace formatting.</value> | ||
</data> | ||
<data name="Set_the_verbosity_level_Allowed_values_are_quiet_minimal_normal_detailed_and_diagnostic" xml:space="preserve"> | ||
<value>Set the verbosity level. Allowed values are q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic]</value> | ||
</data> | ||
<data name="The_severity_of_diagnostics_to_fix_Allowed_values_are_info_warn_and_error" xml:space="preserve"> | ||
<value>The severity of diagnostics to fix. Allowed values are info, warn, and error.</value> | ||
</data> | ||
<data name="Verify_no_formatting_changes_would_be_performed_Terminates_with_a_non_zero_exit_code_if_any_files_would_have_been_formatted" xml:space="preserve"> | ||
<value>Verify no formatting changes would be performed. Terminates with a non-zero exit code if any files would have been formatted.</value> | ||
</data> | ||
<data name="whichever_ids_are_listed_in_the_editorconfig_file" xml:space="preserve"> | ||
<value>whichever ids are listed in the editorconfig file</value> | ||
</data> | ||
</root> |
27 changes: 27 additions & 0 deletions
27
src/Cli/dotnet/commands/dotnet-format/analyzers/FormatAnalyzersCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
// | ||
|
||
using System.Collections.Generic; | ||
using System.CommandLine.Parsing; | ||
|
||
using Microsoft.DotNet.Cli.Format; | ||
|
||
namespace Microsoft.DotNet.Cli | ||
{ | ||
internal class FormatAnalyzersCommand : AbstractFormatCommand | ||
{ | ||
protected override string ParseFrom => "dotnet format analyzers"; | ||
|
||
protected override List<string> AddArgs(ParseResult parseResult) | ||
{ | ||
var dotnetFormatArgs = new List<string>(); | ||
dotnetFormatArgs.AddProjectOrSolutionDotnetFormatArgs(parseResult); | ||
dotnetFormatArgs.AddCommonDotnetFormatArgs(parseResult); | ||
dotnetFormatArgs.AddAnalyzerDotnetFormatArgs(parseResult); | ||
return dotnetFormatArgs; | ||
} | ||
|
||
public static int Run(string[] args) => new FormatAnalyzersCommand().RunCommand(args); | ||
} | ||
} |
Oops, something went wrong.