question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Empty lines not removed?

See original GitHub issue

Just installed dotnet-format and tested with the following code (empty lines intended). Used command was dotnet format Test.sln --fix-whitespace --fix-style. I expected the empty lines to be removed, but they remained. How to apply a more strict formatting that removes unnecessary empty lines?

Tested on this code, which is input and output at the sae time (meaning output remains unchanged)

using System;

namespace Test
{
    using System;
    using System.Collections.Generic;
    using System.Threading;
    using System.Threading.Tasks;

    class Program
    {
        static void Main()
        {
            DemoAsync().Wait();
        }

        static async Task DemoAsync()

        {

            var d = new Dictionary<int, int>();

            for (int i = 0; i < 10000; i++)

            {

                int id = Thread.CurrentThread.ManagedThreadId;

                int count;

                d[id] = d.TryGetValue(id, out count) ? count + 1 : 1;



                await Task.Yield();

            }

            foreach (var pair in d) Console.WriteLine(pair);

        }

    }
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
JoeRobichcommented, Apr 19, 2021

@anthony-steele-cko Glad things are working for you now. To fix both whitespace formatting and analyzer reported issues in the same run, you can use the command dotnet format --fix-whitespace --fix-analyzers warn.

2reactions
anthony-steele-ckocommented, Apr 17, 2021

I confirm that this works for me. This time I have a Directory.Build.Props file containing:

<Project>
  <ItemGroup>
    <PackageReference Include="StyleCop.Analyzers" Version="1.1.118" />
  </ItemGroup>
</Project>

In the .editorconfig I have file markup as given above.

Note that when opening the soltution in VS, I have errors for e.g.

Error	SA1508	A closing brace should not be preceded by a blank line.	
Error	SA1505	An opening brace should not be followed by a blank line.	
Error	SA1507	Code should not contain multiple blank lines in a row	

I run dotnet format --fix-analyzers

These are all fixed! 🎉 Blank lines are gone.

More conventional spacing, issues e.g. public SomeClass ( string pk , string sk ) was not fixed by this run, so I run dotnet format a second time with no args, and they are fixed, I get public SomeClass(string pk, string sk)

I can also confirm that without the .editorconfig markup to make these errors not warnings, dotnet format --fix-analyzers warn will remove the blank lines.

Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Remove Empty Lines Online tool
Remove Empty Lines is easy to use tool to remove empty lines. Copy, Paste and delete empty lines. Empty lines may be used...
Read more >
How to Get Rid of Empty Lines of Code in Any Text Editor
Step-by-Step: How to Remove Blank Lines of Code Using a Text Editor · In the file you want to clean up, select two...
Read more >
How to Remove Blank Lines from a File
Steps and help with removing blank lines from text and a file using Notepad++, TextPad, Word, Notepad, WordPad, or a regular expression.
Read more >
Remove blank (empty) lines
I must be very stupid. I select a section (right-click and hold, select, release right-click) Edit > Line operations > Remove Empty Lines...
Read more >
Removing empty lines or blank lines - Actions
TAD-Remove Empty Lines​​ Remove any empty lines from the draft. Empty lines may have no content, whitespace counts as content.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found