format icon indicating copy to clipboard operation
format copied to clipboard

Tool doesn't fix naming issues

Open marcinjahn opened this issue 5 years ago • 14 comments

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?

marcinjahn avatar Aug 26 '19 12:08 marcinjahn

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 avatar Aug 26 '19 15:08 JoeRobich

@JoeRobich Any update on this? Are there any guidelines for prospective contributors for a feature like this one?

nikolamalesevic avatar Jul 15 '20 11:07 nikolamalesevic

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.

JoeRobich avatar Jul 15 '20 16:07 JoeRobich

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?

ivribalko avatar Sep 01 '20 18:09 ivribalko

@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?

floppydisken avatar Jan 22 '21 10:01 floppydisken

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 avatar Jan 25 '21 19:01 JoeRobich

@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?

floppydisken avatar Jan 27 '21 08:01 floppydisken

Any update on this? Love the tool but it would be great for a IDE1006 naming 'fix all'.

domholmes avatar Nov 16 '21 15:11 domholmes

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

benc-uk avatar Jul 31 '22 14:07 benc-uk

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 avatar Aug 01 '22 03:08 Sakyawira

@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

JoeRobich avatar Aug 01 '22 16:08 JoeRobich

Any updates on this? We've started using dotnet format and we're sad to find out it cannot format naming.

radutomy avatar Apr 12 '24 13:04 radutomy

Bump.

spencer741 avatar Apr 14 '24 23:04 spencer741

Bump

cvetomir-todorov avatar Sep 20 '24 11:09 cvetomir-todorov

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

JoeRobich avatar Sep 24 '24 01:09 JoeRobich