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

moving to different command structure #1276

Merged
merged 21 commits into from
Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 38 additions & 20 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/artifacts/bin/dotnet-format/Debug/netcoreapp3.1/dotnet-format.dll",
"program": "${workspaceFolder}/artifacts/bin/dotnet-format/Debug/net6.0/dotnet-format.dll",
"args": [
"@validate.rsp",
"--check"
"--verify-no-changes"
],
"cwd": "${workspaceFolder}",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
Expand All @@ -22,17 +22,37 @@
"justMyCode": false
},
{
"name": "format -f --check",
"name": "format format.sln --verify-no-changes",
"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/netcoreapp3.1/dotnet-format.dll",
"program": "${workspaceFolder}/artifacts/bin/dotnet-format/Debug/net6.0/dotnet-format.dll",
"args": [
"-f",
"format.sln",
"-v",
"diag",
"--verify-no-changes"
],
"cwd": "${workspaceFolder}",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
"stopAtEntry": false,
"justMyCode": false
},
{
"name": "format whitespace --folder --verify-no-changes",
"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/net6.0/dotnet-format.dll",
"args": [
"whitespace",
"--folder",
"-v",
"diag",
"--check"
"--verify-no-changes"
],
"cwd": "${workspaceFolder}/src",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
Expand All @@ -41,17 +61,18 @@
"justMyCode": false
},
{
"name": "format format.sln --check",
"name": "format whitespace format.sln --verify-no-changes",
"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/netcoreapp3.1/dotnet-format.dll",
"program": "${workspaceFolder}/artifacts/bin/dotnet-format/Debug/net6.0/dotnet-format.dll",
"args": [
"whitespace",
"format.sln",
"-v",
"diag",
"--check"
"--verify-no-changes"
],
"cwd": "${workspaceFolder}",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
Expand All @@ -60,20 +81,18 @@
"justMyCode": false
},
{
"name": "format format.sln --fix-style warn --check",
"name": "format style format.sln --verify-no-changes",
"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/netcoreapp3.1/dotnet-format.dll",
"program": "${workspaceFolder}/artifacts/bin/dotnet-format/Debug/net6.0/dotnet-format.dll",
"args": [
"style",
"format.sln",
"--fix-whitespace",
"--fix-style",
"warn",
"-v",
"diag",
"--check"
"--verify-no-changes"
],
"cwd": "${workspaceFolder}",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
Expand All @@ -82,19 +101,18 @@
"justMyCode": false
},
{
"name": "format format.sln --fix-analyzers warn --check",
"name": "format analyzers format.sln --verify-no-changes",
"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/netcoreapp3.1/dotnet-format.dll",
"program": "${workspaceFolder}/artifacts/bin/dotnet-format/Debug/net6.0/dotnet-format.dll",
"args": [
"analyzers",
"format.sln",
"--fix-analyzers",
"warn",
"-v",
"diag",
"--check"
"--verify-no-changes"
],
"cwd": "${workspaceFolder}",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
Expand Down
5 changes: 5 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

<Import Project="Sdk.props" Sdk="Microsoft.DotNet.Arcade.Sdk" />

<PropertyGroup>
<!-- Disable until they are better supported in tooling. -->
<DisableImplicitNamespaceImports>true</DisableImplicitNamespaceImports>
</PropertyGroup>

<!-- Nuget settings -->
<PropertyGroup>
<!-- Use Directory.Packages.props for nuget package versions -->
Expand Down
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PackageVersion Include="Microsoft.Build.Framework" Version="$(MicrosoftBuildVersion)" />
<PackageVersion Include="Microsoft.Build.Locator" Version="1.4.1" />
<PackageVersion Include="Microsoft.Build" Version="$(MicrosoftBuildVersion)"/>
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzer.Testing" Version="1.0.1-beta1.20413.3" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzer.Testing" Version="1.1.1-beta1.21413.1" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.2" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Features" Version="$(MicrosoftNETCoreCompilersPackageVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="$(MicrosoftNETCoreCompilersPackageVersion)" />
Expand Down
110 changes: 54 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,86 +45,76 @@
- [Log warnings and errors to the standard error stream (982)](https://www.github.com/dotnet/format/pull/982)
- [Only report fixable compiler diagnostics. (981)](https://www.github.com/dotnet/format/pull/981)

### .NET Core 2.1 SDK Support
### How To Use

The dotnet-format 5.1.x releases will continue to support users who only have .NET Core 2.1 SDK installed. Releases with bug fixes will continue until it reaches [end of support](https://dotnet.microsoft.com/platform/support/policy/dotnet-core) on August 21, 2021. Version 6.0 will require .NET Core SDK 3.1 or higher.
dotnet-format is now part of the .NET 6 SDK. Invoking the `dotnet format` command will fix whitespace, code style, and analyzer issues by default. dotnet-format will look in the current directory for a project or solution file and use that as the workspace to format. If more than one project or solution file is present in the current directory, you will need to specify the workspace to format. You can control how verbose the output will be by using the `--verbosity` option.

### How To Install
There are also 3 subcommands to target specific scenarios:
- `dotnet format whitespace`: fixes whitespace
- `dotnet format style`: runs code style analyzers
- `dotnet format analyzers`: runs third party analyzers

The `dotnet-format` nuget package is [published to nuget.org](https://www.nuget.org/packages/dotnet-format/).
#### Common options for all commands
- `--no-restore`: Doesn't execute an implicit restore before formatting.
- `--include-generated`: Format files generated by the SDK
- `--include`: A list of relative file or folder paths to include in formatting. All files are formatted if empty.
- `--exclude`: A list of relative file or folder paths to exclude from formatting.
- `--verbosity`: Set the verbosity level. Allowed values are q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic]
- `--report`: Accepts a file path, which if provided, will produce a json report in the given directory.
- `--binarylog`: Log all project or solution load information to a binary log file.
- `--verify-no-changes`: Verify no formatting changes would be performed. Terminates with a non-zero exit code if any files would have been formatted.

You can install the tool using the following command.
#### Unique options for `dotnet format`
- `--diagnostics`: A space separated list of diagnostic ids to use as a filter when fixing code style or 3rd party issues.
- `--severity`: The severity of diagnostics to fix. Allowed values are info, warn, and error.

```console
dotnet tool install -g dotnet-format
```
Note: if the user specifies a severity here it is used for both style and analyzers.

#### Installing Development Builds
#### Unique options for `dotnet format whitespace`
- `--folder`: Whether to treat the workspace argument as a simple folder of files.

Development builds of `dotnet-format` are being hosted on Azure Packages. You can visit the [dotnet-format Azure Packages page](https://dev.azure.com/dnceng/public/_packaging?_a=package&feed=dotnet-tools&view=versions&package=dotnet-format&protocolType=NuGet).
#### Unique options for `dotnet format style`
- `--diagnostics`: A space separated list of diagnostic ids to use as a filter when fixing code style or 3rd party issues.
- `--severity`: The severity of diagnostics to fix. Allowed values are info, warn, and error.

You can install the latest build of the tool using the following command.
#### Unique options for `dotnet cleanup analyzers`
- `--diagnostics`: A space separated list of diagnostic ids to use as a filter when fixing code style or 3rd party issues.
- `--severity`: The severity of diagnostics to fix. Allowed values are info, warn, and error.

```console
dotnet tool install -g dotnet-format --version "6.0.*" --add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json
```

### How To Use

By default `dotnet-format` will look in the current directory for a project or solution file and use that as the workspace to format. If more than one project or solution file is present in the current directory, you will need to specify the workspace to format. You can control how verbose the output will be by using the `-v` option.

```console
Usage:
dotnet-format [options] [<workspace>]

Arguments:
<workspace> 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.

Options:
--no-restore Doesn't execute an implicit restore before formatting.
--folder, -f Whether to treat the `<workspace>` argument as a simple folder of files.
--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.
--diagnostics <diagnostic ids> A space separated list of diagnostic ids to use as a filter when fixing code style or 3rd party analyzers.
--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.
--report <report> Accepts a file path, which if provided, will produce a json report in the given directory.
--binarylog <binary-log-path> Log all project or solution load information to a binary log file.
--verbosity, -v <verbosity> Set the verbosity level. Allowed values are q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic]
--version Show version information
```
### Examples

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 <workspace>` | Formats a specific project or solution. |
| `dotnet format <workspace> -f` | Formats a particular folder and subfolders. |
| `dotnet format <workspace> --fix-style warn` | Fixes only codestyle analyzer warnings. |
| `dotnet format <workspace> --fix-style --no-restore` | Fixes only codestyle analyzer errors without performing an implicit restore. |
| `dotnet format <workspace> --fix-style --diagnostics IDE0005` | Fixes only codestyle analyzer errors for the IDE0005 diagnostic. |
| `dotnet format <workspace> --fix-whitespace --fix-style` | Formats and fixes codestyle analyzer errors. |
| `dotnet format <workspace> --fix-analyzers` | Fixes only 3rd party analyzer errors. |
| `dotnet format <workspace> -wsa` | Formats, fixes codestyle errors, and fixes 3rd party analyzer errors. |
| `dotnet format -v diag` | Formats with very verbose logging. |
| `dotnet format --include Program.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` | Formats and runs analysis for the project or solution in the current directory. |
| `dotnet format -v diag` | Formats and runs analysis with very verbose logging. |
| `dotnet format <workspace>` | Formats and runs analysis for a specific project or solution. |
| `dotnet format <workspace> --severity error` | Formats, fixes codestyle errors, and fixes 3rd party analyzer errors. |
| `dotnet format whitespace <workspace> --folder` | Formats a particular folder and subfolders. |
| `dotnet format style <workspace>` | Fixes only codestyle analyzer warnings. |
| `dotnet format style <workspace> --serverity error --no-restore` | Fixes only codestyle analyzer errors without performing an implicit restore. |
| `dotnet format style <workspace> --diagnostics IDE0005` | Fixes only codestyle analyzer warnings for the IDE0005 diagnostic. |
| `dotnet format analyzers <workspace> --severity error` | Fixes only 3rd party analyzer errors. |
| `dotnet format --include Program.cs Utility\Logging.cs` | Formats the files Program.cs and Utility\Logging.cs |
| `dotnet format --verify-no-changes` | Formats but does not save. Returns a non-zero exit code if any files would have been changed. |
| `dotnet format --report <report-path>` | Formats and saves a json report file to the given directory. |
| `dotnet format --include test/Utilities/*.cs --folder` | Formats the files expanded from native shell globbing (e.g. bash). Space-separated list of files are fed to formatter in this case. Also applies to `--exclude` option. |
| `dotnet format --include 'test/Utilities/*.cs' --folder` | With single quotes, formats the files expanded from built-in glob expansion. A single file pattern is fed to formatter, which gets expanded internally. Also applies to `--exclude` option. |
| `ls tests/Utilities/*.cs \| dotnet format --include - --folder` | Formats the list of files redirected from pipeline via standard input. Formatter will iterate over `Console.In` to read the list of files. Also applies to `--exclude` option. |

### How To Uninstall
#### How to install Development Builds

You can uninstall the tool using the following command.
Development builds of `dotnet-format` are being hosted on Azure Packages. You can visit the [dotnet-format Azure Packages page](https://dev.azure.com/dnceng/public/_packaging?_a=package&feed=dotnet-tools&view=versions&package=dotnet-format&protocolType=NuGet).

You can install the latest build of the tool using the following command.

```console
dotnet tool uninstall -g dotnet-format
dotnet tool install -g dotnet-format --version "6.0.*" --add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json
```

Note: After installing .NET 6 Preview 7 SDK or higher you will need to run the dotnet-format global tool by invoking `dotnet-format`. Invoking `dotnet format` will invoke the SDK's copy of dotnet-format.

### How To Build From Source

You can build and package the tool using the following commands. The instructions assume that you are in the root of the repository.
Expand All @@ -139,3 +129,11 @@ dotnet format
```

> Note: On macOS and Linux, `.\artifacts` will need be switched to `./artifacts` to accommodate for the different slash directions.

### How To Uninstall

You can uninstall the tool using the following command.

```console
dotnet tool uninstall -g dotnet-format
```
Loading