dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
18.74k stars 3.99k forks source link

Easy code cleanup with EditorConfig #40163

Open mikadumont opened 4 years ago

mikadumont commented 4 years ago

Overview

EditorConfig helps maintain consistent coding styles for multiple developers working on the same project across various editors and IDEs. The EditorConfig project consists of a file format for defining coding styles and a collection of text editor plugins that enable editors to read the file format and adhere to defined styles. EditorConfig files are easily readable and they work nicely with version control systems. Code Cleanup allows developers to apply code style preferences from an EditorConfig. Currently only a handful of code styles are supported by code cleanup and should make every EditorConfig option (Code Styles, Naming Styles, and Third-Party Analyzers) available in code cleanup.

Design Proposal

  1. Selecting configure code cleanup: image

  2. Will open a document tab for Code Cleanup similar to the current document tab for EditorConfig.

    • There will be a dropdown for each profile: Profile 1, Profile 2, EditorConfig Settings, and an option to Add New Profile.
    • Each profile you select should switch the view.
    • There will be a checkbox to set profile as default which will add (default) text next to the profile in the drop down. image
  3. Solution Explorer Right click menu and broom icon in the editor should only display Run Code Cleanup and delete the second profile option: image

  4. Solution Explorer right click menu should decouple Analyze and Run Code Cleanup and have a separate menu option for Run Code Cleanup. image

  5. The new menu name for Analyze should be Code Analysis.

  6. Code Cleanup on save:

    • Should live in Tools Options and be called Code Cleanup on Save.
    • There will be a checkbox to Run Code Cleanup on Save with an option to select existing profiles that a user may have set in the past (profile 1 or 2) or editorconfig settings to run it on: image
  7. The Add > New EditorConfig in the Solution Explorer right-click menu will replace the current IntelliCode EditorConfig with the .NET default EditorConfig. image


Tracking Issues

jmarolf commented 2 years ago

Execution Plan

17.1

17.1 Preview 2

17.2

17.2 Preview 1

17.2 Preview 2

17.3

17.3 Preview 1

17.3 Preview 3

CyrusNajmabadi commented 2 years ago

Can we also ensure/fixup string duplication here? (note: i'd like to front load that if possible) :)

jmarolf commented 2 years ago

Can we also ensure/fixup string duplication here? (note: i'd like to front load that if possible) :)

already in progress. sooner than 17.1

tebeco commented 2 years ago

Thanks you very much for all the work done on .editorconfig \o/ the Location is very nice to have

As I'm not sure if i'm allowed to comment here or not I have several questions here ;)

Is it possible somehow to have a button in the UI to toggle the view between the new UI or having it as text ? The Search + multi tab + multi profile is not always UX friendly / easy to use:

xperiandri commented 2 years ago

Is it possible somehow to have a button in the UI to toggle the view between the new UI or having it as text ?

I also have this issue. Because custom pattern rules do not appear in UI Rules like these:

[{App.xaml.cs,Main.*.cs,Shell.xaml.cs}]
[**/Uno.UI.SourceGenerators/**.cs]

The Search + multi tab + multi profile is not always UX friendly / easy to use

Completely agree

Eli-Black-Work commented 2 years ago

Is this the correct issue for tracking adding "Code cleanup on save" support for additional languages, such as JS and CSS, or is there another issue for that?

JadaVonRuth commented 1 year ago

Probably outside of scope of this issue, but my problem with code cleanup is that is used to quite be fast in .net core, now it is excruciatingly slow. Class file with 70 lines takes 10-30 secs to cleanup and the only changes it is supposed to make is within the class file being saved not outside. And running code cleanup for whole solution takes ages.

Eli-Black-Work commented 1 year ago

@JadaVonRuth I think that should be fixed in the next version of VS: https://developercommunity.visualstudio.com/t/Code-Cleanup--in-174-much-slower-than-i/10207182 🙂

juliank commented 1 year ago

@mikadumont: This issue was moved a bit between various milestones last year, but now there hasn't been any changes for a while. Any chance of a ballpark estimate for when this issue might get some attention again?

arkalyanms commented 1 month ago

@sharwell Lets queue this up next. Mika confirmed user feedback validating interest in this.