format
format copied to clipboard
Tool doesn't fix naming issues
I run the tool on my solution and it fixed the indentation problem (which I'm really happy about). However, the namings were not fixed- Visual Studio still lists naming issues. Doesn't the tool fix naming violations?
Hi @Loreno10, currently format does not support naming styles. From our perspective there are 3 types of configuration in the editorconfig; whitespace, code style, and naming. We launched with support for whitespace formatting and are close to merging in initial support for code style. Naming will come later after we have improved the performance of the code style formatting.
@JoeRobich Any update on this? Are there any guidelines for prospective contributors for a feature like this one?
Hi @nikolamalesevic, @jmarolf and I are working on getting analyzer support into a dotnet-format release. If you take our latest development build from our myget feed, you will see the progress that we've made so far.
Here is the output from running dotnet-format ./format.sln --fix-style warn --check -v diag
The dotnet CLI version is '5.0.100-preview.6.20277.3'.
Using MSBuild.exe located in '/usr/local/share/dotnet/sdk/5.0.100-preview.6.20277.3/'.
Formatting code files in workspace '/Users/joeyrobichaud/Source/format/format.sln'.
Loading workspace.
Complete in 5688ms.
Determining formattable files.
Complete in 915ms.
Running formatters.
Running Code Style analysis.
Determining diagnostics...
src/CodeFormatter.cs(25,64): Naming rule violation: Missing prefix: 's_' (IDE1006)
src/Workspaces/FolderWorkspace.cs(4,1): Using directive is unnecessary. (IDE0005)
tests/Analyzers/FilterDiagnosticsTests.cs(3,1): Using directive is unnecessary. (IDE0005)
tests/Analyzers/FilterDiagnosticsTests.cs(7,1): Using directive is unnecessary. (IDE0005)
tests/Analyzers/FilterDiagnosticsTests.cs(12,1): Using directive is unnecessary. (IDE0005)
Complete in 26650ms.
Fixing diagnostics...
Unable to fix IDE0005. No associated code fix found.
Unable to fix IDE1006. Code fix NamingStyleCodeFixProvider doesn't support Fix All in Solution.
Complete in 1208ms.
Analysis complete in 27858ms.
Complete in 28948ms.
Formatted 0 of 78 files.
Format complete in 35551ms.
I introduced a naming issue to show that we can now report naming violations. The next step will be improving our code fix support to work around provider that do not support fix all in solution.
You can try this out yourself by installing our latest development build with the caveat that the feature isn't 100% baked. For instance Full Framework or NetStandard projects may report compilation errors around unresolved dependencies.
dotnet tool install -g dotnet-format --version 5.0.135801 --add-source https://dotnet.myget.org/F/format/api/v3/index.json
-Joey
*Edit: The timings in the log are for a local debug build. Running with the tool built in release mode completes in just under 11 seconds.
Hi @JoeRobich ! Thank you for the awesome tool! It seems that this page contains information suggesting that naming issues fixing should work. I wasn't able to make it work on version 5.0.135301+b255ad16af715cae7bf2a80cc1db697742f46d96
. Could you clarify please if it has been implemented or when it might be if not?
@JoeRobich awesome bloody tool.
So just to be clear, does dotnet format expect NamingStyleFixProvider
to be provided from somewhere else?
If so, where is it expected to be provided from?
So just to be clear, does dotnet format expect
NamingStyleFixProvider
to be provided from somewhere else?
The NamingStyleCodeFixProvider
is present but does not provide a batch fixer as other code style fix providers do. We would need to either enhance the Roslyn CodeFixerProvider with this capability or update dotnet-format to handle these diagnostics differently.
@JoeRobich Ah okay, that makes sense. I'd love for this to be added. It's incredible useful to have a formatter do these things, especially if you pair it with pre-commit hooks.
I have absolutely no idea of the complexity of such a feature. However, is it something we/I can help out with, and if so, where is a good place to start?
Any update on this? Love the tool but it would be great for a IDE1006 naming 'fix all'.
I'd just like dotnet format --verify-no-changes
to pick up errors with the names in the code. I'm less interested in fixing
It's super weird seeing red lines in the IDE (VS Code) and dotnet format
simply ignoring them
Hi @JoeRobich iI couldn't find that version (version 5.0.135801) you mentioned.
running the command dotnet tool install -g dotnet-format --version 5.0.135801 --add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json
gives me this result:
warning NU1603: restore depends on dotnet-format (>= 5.0.135801) but dotnet-format 5.0.135801 was not found. An approximate best match of dotnet-format 5.0.211103 was resolved. You can invoke the tool using the following command: dotnet-format Tool 'dotnet-format' (version '5.0.211103') was successfully installed.
@Sakyawira The versions that ship with the .NET 6 and .NET 7 SDK support reporting naming style violations. There is still no batch fixer implemented for Naming Style errors. See this Roslyn feature request https://github.com/dotnet/roslyn/issues/14983
Any updates on this? We've started using dotnet format
and we're sad to find out it cannot format naming.
Bump.
Bump
dotnet-format uses the code fixers provided by Roslyn. Please vote up or report your frustration on the Roslyn issue tracking fix-all support https://github.com/dotnet/roslyn/issues/14983