dotnet-format: accept a list of files to format (instead of a full workspace)
See original GitHub issueVersion Used: dotnet-format 3.0.0-beta4-19105-10 (70a2f514eb3932648f771b086834cb0a376fee20)
Steps to Reproduce:
- Change a number of files (so they appear in VCS output, such as
git diff --name-only
) - Pass that file list as command line parameters into
dotnet format
(or try to pipe them into stdin)
Expected Behavior:
dotnet format
only changes the passed files instead of the whole project (or solution)
Actual Behavior:
dotnet format
errors out with either “Both a MSBuild project file and solution file found in $path. Specify which one to use with the --workspace option” or “Unrecognized command or argument ‘path/to/file.cs’”. Or somewhat…not sure if I should call it worse or just different: it runs successfully, formatting all files referenced by the project or solution (in case only a single project or solution file is found in the current working directory).
Intended Use-Case:
We run a few things as part of our CI (such as static analysis), and we’d also like to use dotnet format
as a way to enforce code style before it even reaches the first review by a human. Right now this isn’t too feasible as dotnet format
takes quite a while on larger solutions with a lot of files; and running it only on the changed files would significantly improve the time to feedback (with the intention to simply error out in case it produces any changes in the CI working copy).
For smaller change sets, passing file names as command line parameter is likely a usable solution, but the larger the change set the more likely it would be to reach a length limit for arguments; so piping it into stdin would probably be the better approach there.
Or, alternatively (if it makes sense to do so), support this use case from within dotnet format
itself (or a tool derived from it), along with the --dry-run
switch: stop processing as soon as a change would have been made and return an error code that can be checked by a caller.
Thoughts and ideas are more than welcome, especially in case I missed some other tooling that already does this.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:4
- Comments:9 (6 by maintainers)
This is available on myget version 3.0.4-prerelease.19171.3 and later
@BhaaLseN you did the right thing. I just put this repo together recently