Skip to content

Instantly share code, notes, and snippets.

@jmarolf
Last active September 1, 2020 20:16
Show Gist options
  • Save jmarolf/3aeaa55b974df9ac7d42a65322464465 to your computer and use it in GitHub Desktop.
Save jmarolf/3aeaa55b974df9ac7d42a65322464465 to your computer and use it in GitHub Desktop.

dotnet format commands

Note: implicit in this doc is that we keep the name format as the root command.

Whitespace

Command Format: dotnet format <workspace> --fix-whitespace

Fixes whitespace only. Just looks at files and folders

Alias: 'w'. Invoking dotnet format without any arguments is equivalent to doing dotnet format --fix-whitespace

Arguments:

  • workspace (Optional): a folder or file (must exist). If the path evaluated to either a sln file or a csproj file we will attempt to laod it to determine the set of files to format. If the path evaluated to a folder or is not specified dotnet format uses the directory it was invoked from and just recurses through the files in that directory.

Code Style

Command Format: dotnet format <workspace> --fix-style <severity>

Only fixes code style (aka code cleanup). Loads your solution or project.

Alias: 's'

Arguments:

  • workspace (Optional): a path that contains a solution or project. so C:\workspace is a valid workspace if it has either C:\workspace\*.sln or C:\workspace\*.csproj. This mirrors the behavior for dotnet build i.e. if dotnet build works for a path then dotnet format --fix-style should also work. If not specified dotnet format uses the directory it was invoked from.

  • severity (Optional): the severity of the code style options to fix. By default it is info to ensure it fixes everything that is specified in your editorconfig file. Possible values are info, warning, and error.

Analyzers

Command Format: dotnet format <workspace> --fix-analyzers <severity>

Alias: 'a'

Arguments:

  • workspace (Optional): evaluated identically to how it is for --fix-style. If not specified dotnet format uses the directory it was invoked from.

Fixing everything

Command Format: dotnet format <workspace> --fix-all <severity>

Alias: no alias for this command. passing -wsa will do the same thing.

Arguments:

  • workspace (Optional): evaluated identically to how it is for --fix-style

  • severity (Optional): the severities passed into both the --fix-style and --fix-analyzers commands.

@jmarolf
Copy link
Author

jmarolf commented Sep 1, 2020

I will also note that I think --exclude is another solution here. It seems like we have several mechanisms to include/exclude files as the user wants. I am still on the fence as the whether we really want a --folder option.

@JoeRobich
Copy link

@jmarlof I think removing the --folder option is fine. --fix-whitespace (or the default behavior) will automatically treat folder path workspaces as folders of files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment