Skip to content

Commit

Permalink
Add fix prefix to options
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeRobich committed Sep 9, 2020
1 parent 4a7c816 commit 2753226
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 40 deletions.
8 changes: 4 additions & 4 deletions .vscode/launch.json
Expand Up @@ -43,15 +43,15 @@
"justMyCode": false
},
{
"name": "format format.sln --style warn --check",
"name": "format format.sln --fix-style warn --check",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/artifacts/bin/dotnet-format/Debug/netcoreapp2.1/dotnet-format.dll",
"args": [
"format.sln",
"--style",
"--fix-style",
"warn",
"-v",
"diag",
Expand All @@ -64,15 +64,15 @@
"justMyCode": false
},
{
"name": "format format.sln --analyzers warn --check",
"name": "format format.sln --fix-analyzers warn --check",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/artifacts/bin/dotnet-format/Debug/netcoreapp2.1/dotnet-format.dll",
"args": [
"format.sln",
"--analyzers",
"--fix-analyzers",
"warn",
"-v",
"diag",
Expand Down
32 changes: 16 additions & 16 deletions README.md
Expand Up @@ -72,9 +72,9 @@ Arguments:

Options:
--folder, -f Whether to treat the `<workspace>` argument as a simple folder of files.
--whitespace, -w Run whitespace formatting. Run by default when not applying fixes.
--style, -s <severity> Run code style analyzers and apply fixes.
--analyzers, -a <severity> Run 3rd party analyzers and apply fixes.
--fix-whitespace, -w Run whitespace formatting. Run by default when not applying fixes.
--fix-style, -s <severity> Run code style analyzers and apply fixes.
--fix-analyzers, -a <severity> Run 3rd party analyzers and apply fixes.
--include <include> A list of relative file or folder paths to include in formatting. All files are formatted if empty.
--exclude <exclude> A list of relative file or folder paths to exclude from formatting.
--check Formats files without saving changes to disk. Terminates with a non-zero exit code if any files were formatted.
Expand All @@ -85,19 +85,19 @@ Options:

Add `format` after `dotnet` and before the command arguments that you want to run:

| Examples | Description |
| ---------------------------------------------------------- |---------------------------------------------------------------------------------------------- |
| dotnet **format** | Formats the project or solution in the current directory. |
| dotnet **format** &lt;workspace&gt; | Formats a specific project or solution. |
| dotnet **format** &lt;workspace&gt; -f | Formats a particular folder and subfolders. |
| dotnet **format** &lt;workspace&gt; --style warn | Fixes codestyle analyzer warnings. |
| dotnet **format** &lt;workspace&gt; --whitespace --style | Formats and fixes codestyle analyzer errors. |
| dotnet **format** &lt;workspace&gt; --analyzers | Fixes 3rd party analyzer errors. |
| dotnet **format** &lt;workspace&gt; -wsa | Formats, fixes codestyle errors, and fixes 3rd party analyzer errors. |
| dotnet **format** -v diag | Formats with very verbose logging. |
| dotnet **format** --include Programs.cs Utility\Logging.cs | Formats the files Program.cs and Utility\Logging.cs |
| dotnet **format** --check | Formats but does not save. Returns a non-zero exit code if any files would have been changed. |
| dotnet **format** --report &lt;report-path&gt; | Formats and saves a json report file to the given directory. |
| Examples | Description |
| ---------------------------------------------------------------- |---------------------------------------------------------------------------------------------- |
| dotnet **format** | Formats the project or solution in the current directory. |
| dotnet **format** &lt;workspace&gt; | Formats a specific project or solution. |
| dotnet **format** &lt;workspace&gt; -f | Formats a particular folder and subfolders. |
| dotnet **format** &lt;workspace&gt; --fix-style warn | Fixes only codestyle analyzer warnings. |
| dotnet **format** &lt;workspace&gt; --fix-whitespace --fix-style | Formats and fixes codestyle analyzer errors. |
| dotnet **format** &lt;workspace&gt; --fix-analyzers | Fixes only 3rd party analyzer errors. |
| dotnet **format** &lt;workspace&gt; -wsa | Formats, fixes codestyle errors, and fixes 3rd party analyzer errors. |
| dotnet **format** -v diag | Formats with very verbose logging. |
| dotnet **format** --include Programs.cs Utility\Logging.cs | Formats the files Program.cs and Utility\Logging.cs |
| dotnet **format** --check | Formats but does not save. Returns a non-zero exit code if any files would have been changed. |
| dotnet **format** --report &lt;report-path&gt; | Formats and saves a json report file to the given directory. |

### How To Uninstall

Expand Down
14 changes: 7 additions & 7 deletions docs/README.md
Expand Up @@ -45,7 +45,7 @@ dotnet-format ./format.sln
Running the whitespace formatter along with code-style analysis.

```console
dotnet-format ./format.sln --whitespace --style
dotnet-format ./format.sln --fix-whitespace --fix-style
```

### Running analysis
Expand All @@ -54,33 +54,33 @@ dotnet-format ./format.sln --whitespace --style

Running codestyle analysis requires the use of a MSBuild solution or project file as the workspace. Enforces the .NET [Language conventions](https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-language-conventions?view=vs-2019) and [Naming conventions](https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-naming-conventions?view=vs-2019).

- `--style <severity>` - Runs analysis and attempts to fix issues with severity equal or greater than specified. If severity is not specified then severity defaults to error.
- `--fix-style <severity>` - Runs analysis and attempts to fix issues with severity equal or greater than specified. If severity is not specified then severity defaults to error.

*Example:*

Run analysis against the format solution and fix errors.
Run code-style analysis against the format solution and fix errors.

```console
dotnet-format ./format.sln --style
dotnet-format ./format.sln --fix-style
```

Run analysis against the dotnet-format project and fix warnings and errors.

```console
dotnet-format ./src/dotnet-format.csproj --style warn
dotnet-format ./src/dotnet-format.csproj --fix-style warn
```

Errors when used with the `--folder` option. Analysis requires a MSBuild solution or project.

```console
dotnet-format ./src --folder --style
dotnet-format ./src --folder --fix-style
```

#### 3rd party analysis

Running 3rd party analysis requires the use of a MSBuild solution or project file as the workspace. 3rd party analyzers are discovered from the `<PackageReferences>` specified in the workspace project files.

- `--analyzers <severity>` - Runs analysis and attempts to fix issues with severity equal or greater than specified. If no severity is specified then this defaults to error.
- `--fix-analyzers <severity>` - Runs analysis and attempts to fix issues with severity equal or greater than specified. If no severity is specified then this defaults to error.

### Filter files to format

Expand Down
6 changes: 3 additions & 3 deletions docs/Supported-.editorconfig-options.md
Expand Up @@ -12,10 +12,10 @@ The dotnet-format global tool supports the core set of [EditorConfig options](ht

[*] The options `trim_trailing_whitespace` and `max_line_length` are not supported. Currently insignificant whitespace is **always** removed by the formatter.

[**] [Formatting conventions](https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-formatting-conventions?view=vs-2019) are enforced by default. Use the `--style` option to enforce [Language conventions](https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-language-conventions?view=vs-2019) and [Naming conventions](https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-naming-conventions?view=vs-2019).
[**] [Formatting conventions](https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-formatting-conventions?view=vs-2019) are enforced by default. Use the `--fix-style` option to enforce [Language conventions](https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-language-conventions?view=vs-2019) and [Naming conventions](https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-naming-conventions?view=vs-2019).

## Removing unnecessary imports
In order to remove unnecessary imports the IDE0005 (unnecessary import) diagnostic id must be configured in your .editorconfig. When running dotnet-format pass the `--style` option and specify a severity that includes the configured IDE0005 severity.
In order to remove unnecessary imports the IDE0005 (unnecessary import) diagnostic id must be configured in your .editorconfig. When running dotnet-format pass the `--fix-style` option and specify a severity that includes the configured IDE0005 severity.

*Example:*

Expand All @@ -29,5 +29,5 @@ dotnet_diagnostic.IDE0005.severity = warning

command
```console
dotnet-format ./format.sln --style warn
dotnet-format ./format.sln --fix-style warn
```
10 changes: 5 additions & 5 deletions src/FormatCommand.cs
Expand Up @@ -22,12 +22,12 @@ internal static RootCommand CreateCommandLineOptions()
Description = Resources.A_path_to_a_solution_file_a_project_file_or_a_folder_containing_a_solution_or_project_file_If_a_path_is_not_specified_then_the_current_directory_is_used
}.LegalFilePathsOnly(),
new Option(new[] { "--folder", "-f" }, Resources.Whether_to_treat_the_workspace_argument_as_a_simple_folder_of_files),
new Option(new[] { "--whitespace", "-w" }, Resources.Run_whitespace_formatting_Run_by_default_when_not_applying_fixes),
new Option(new[] { "--style", "-s" }, Resources.Run_code_style_analyzers_and_apply_fixes)
new Option(new[] { "--fix-whitespace", "-w" }, Resources.Run_whitespace_formatting_Run_by_default_when_not_applying_fixes),
new Option(new[] { "--fix-style", "-s" }, Resources.Run_code_style_analyzers_and_apply_fixes)
{
Argument = new Argument<string?>("severity") { Arity = ArgumentArity.ZeroOrOne }.FromAmong(SeverityLevels)
},
new Option(new[] { "--analyzers", "-a" }, Resources.Run_3rd_party_analyzers_and_apply_fixes)
new Option(new[] { "--fix-analyzers", "-a" }, Resources.Run_3rd_party_analyzers_and_apply_fixes)
{
Argument = new Argument<string?>("severity") { Arity = ArgumentArity.ZeroOrOne }.FromAmong(SeverityLevels)
},
Expand Down Expand Up @@ -64,7 +64,7 @@ internal static RootCommand CreateCommandLineOptions()
internal static string? EnsureFolderNotSpecifiedWhenFixingAnalyzers(CommandResult symbolResult)
{
var folder = symbolResult.ValueForOption<bool>("--folder");
var fixAnalyzers = symbolResult.OptionResult("--analyzers");
var fixAnalyzers = symbolResult.OptionResult("--fix-analyzers");
return folder && fixAnalyzers != null
? "Cannot specify the '--folder' option when running analyzers."
: null;
Expand All @@ -73,7 +73,7 @@ internal static RootCommand CreateCommandLineOptions()
internal static string? EnsureFolderNotSpecifiedWhenFixingStyle(CommandResult symbolResult)
{
var folder = symbolResult.ValueForOption<bool>("--folder");
var fixStyle = symbolResult.OptionResult("--style");
var fixStyle = symbolResult.OptionResult("--fix-style");
return folder && fixStyle != null
? "Cannot specify the '--folder' option when fixing style."
: null;
Expand Down
4 changes: 2 additions & 2 deletions src/Program.cs
Expand Up @@ -133,12 +133,12 @@ private static async Task<int> Main(string[] args)
}

var fixType = FixCategory.None;
if (s_parseResult.WasOptionUsed("--style", "-s"))
if (s_parseResult.WasOptionUsed("--fix-style", "-s"))
{
fixType |= FixCategory.CodeStyle;
}

if (s_parseResult.WasOptionUsed("--analyzers", "-a"))
if (s_parseResult.WasOptionUsed("--fix-analyzers", "-a"))
{
fixType |= FixCategory.Analyzers;
}
Expand Down
6 changes: 3 additions & 3 deletions tests/ProgramTests.cs
Expand Up @@ -175,7 +175,7 @@ public void CommandLine_FolderValidation_FailsIfFixAnalyzersSpecified()
var sut = FormatCommand.CreateCommandLineOptions();

// Act
var result = sut.Parse(new[] { "--folder", "--analyzers" });
var result = sut.Parse(new[] { "--folder", "--fix-analyzers" });

// Assert
Assert.Equal(1, result.Errors.Count);
Expand All @@ -188,7 +188,7 @@ public void CommandLine_FolderValidation_FailsIfFixStyleSpecified()
var sut = FormatCommand.CreateCommandLineOptions();

// Act
var result = sut.Parse(new[] { "--folder", "--style" });
var result = sut.Parse(new[] { "--folder", "--fix-style" });

// Assert
Assert.Equal(1, result.Errors.Count);
Expand All @@ -201,7 +201,7 @@ public void CommandLine_AnalyzerOptions_CanSpecifyBothWithDefaults()
var sut = FormatCommand.CreateCommandLineOptions();

// Act
var result = sut.Parse(new[] { "--analyzers", "--style" });
var result = sut.Parse(new[] { "--fix-analyzers", "--fix-style" });

// Assert
Assert.Equal(0, result.Errors.Count);
Expand Down

0 comments on commit 2753226

Please sign in to comment.