Ticket T726440
Visible to All Users

Code cleanup / formatting

created 6 years ago

Hi … I'm struggling to find which combination of formatting options I need to combine in order to get the desired output. Ive played around with spacing, braces, and newlines, and it gets close - but when nested lambdas come into play everything gets a bit hairy. The default VS indentation in this case is preferable.

A picture speaks a thousand words so let s just look and see… Ive set the text to smaller than I generally have it to see more and get a better feel for the output.

Also, you should allow ctrl+v pasting image data directly to this form :p . The amount of idents seems to be related, but only to delcaration or statement - there doesnt seem to be a scope of ("The start of the line that called the method where this inline lambda or block is an argument") …  which sounds wordy, but its the default for vs, after a format document / Ctrl K, Ctrl D.

Ahh and i only seem to be able ot add 1 image so i guess i will respond to myself with a comment.

Show previous comments (3)

    Repro file attached

      And from the screenshot there is one section which uses a local function (https://docs.microsoft.com/en-us/dotnet/csharp/local-functions-vs-lambdas ) which doesn't seem to fall into the same category, but is affected by the same undesirable excessive unindenting.

      AE AE
      Alex Eg (DevExpress) 6 years ago

        I've created a separate ticket on your behalf (Formatting - Local function with the lambda expression is formatted incorrectly). It has been placed in our processing queue and will be answered shortly.

        Answers approved by DevExpress Support

        created 6 years ago

        Thank you for the provided information. I can reproduce the described behavior. We have researched the situation with the lambda formatting in your sample. It seems that we can't find any other way to keep code formatted as you need without disabling the 'C#->Formatting->Braces\Lambda Expression and Anonymous methods' option because your code construction looks too complex and is initially formatted in a custom manner - our formatting engine can't currently handle such constructions. We will keep your case as a potential source of information for possible future formatting improvements. It's unlikely that we will make any corrections or improvements in this direction soon - there is a strong possibility that such changes can break existing behavior in many other cases.

          Show previous comments (1)

            just an example from the official docs where you will see similiar "complexity":
            https://docs.microsoft.com/en-us/aspnet/core/fundamentals/startup?view=aspnetcore-2.2

            C#
            public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .ConfigureAppConfiguration((hostingContext, config) => { HostingEnvironment = hostingContext.HostingEnvironment; Configuration = config.Build(); }) .ConfigureServices(services => { ... }) .Configure(app => { var loggerFactory = app.ApplicationServices .GetRequiredService<ILoggerFactory>(); var logger = loggerFactory.CreateLogger<Program>(); logger.LogInformation("Logged in Configure"); if (HostingEnvironment.IsDevelopment()) { ... } else { ... } var configValue = Configuration["subsection:suboption1"]; ... }); }

              attached the default vs options which will give the desired effect ( eqyptian style braces on same line as statement )

              AE AE
              Alex Eg (DevExpress) 6 years ago

                Joe,
                Thank you for the sample from the MS documentation. We have checked our formatting on this sample and found that it works as you requested:
                https://monosnap.com/file/G3k3GWLz98wiZnNszKEqBcL5qOdIB7
                Then we have compared it with your original code and found that there is a minor difference in a code structure (the level of chained method calls) and now it seems that we can the add an extra setting for the 'Chained method call' options and formatting will work in your code as requested. I added this task in our formatting improvement backlog, however I cannot give you an estimation on it's implementation. Thank you for pointing our attention to this situation and providing the additional information!

                Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

                Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.