-
Notifications
You must be signed in to change notification settings - Fork 173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Empty lines not removed? #1074
Comments
I just read SA15007 and it's about multiple empty lines following each other directly. In my case it's only one blank line followed by code (well, there's both in my code; expectation would be too remove most of them like e.g. Prettifier in the JavaScript world does it). |
@jmarolf SA1507 does have a code fix (as listed in the status table), but it's not the only rule that applies here. The blank lines before and after most With that said, none of these rules would apply unless StyleCop Analyzers is installed. 16.10 is the first release where Roslyn's built-in analyzers consider blank line removal, and only in a small set of cases. |
@sharwell Being new to these things, do I understand correctly that I could add https://github.com/DotNetAnalyzers/StyleCopAnalyzers to my project and dotnet-format would than have more rules/functionality? |
@wondering639 That is right. You can add a package reference to the StyleCopAnalyzers in your projects and fix issues by using the format/tests/Analyzers/ThirdPartyAnalyzerFormatterTests.cs Lines 69 to 120 in 8b7b3ab
|
similar request #67 |
Closing this issue as StyleCopAnalyzers can be used to remove blank lines. |
Not working for me. What I did was
Result: |
@anthony-steele-cko You will need to configure the analyzers to report a sufficient severity. You will need to either add or update your editorconfig to include the following configuration. If you do not want them to be .editorconfig root = true
[*.cs]
# Two or more consecutive blank lines: Remove down to one blank line. SA1507
dotnet_diagnostic.SA1507.severity = error
# Blank line immediately before or after a { line: remove it. SA1505, SA1509
dotnet_diagnostic.SA1505.severity = error
dotnet_diagnostic.SA1509.severity = error
# Blank line immediately before a } line: remove it. SA1508
dotnet_diagnostic.SA1508.severity = error |
I confirm that this works for me. This time I have a
In the Note that when opening the soltution in VS, I have errors for e.g.
I run These are all fixed! 🎉 Blank lines are gone. More conventional spacing, issues e.g. I can also confirm that without the Thank you. |
@anthony-steele-cko Note that I would not recommend ever setting analyzer diagnostics to |
@sharwell I agree: as proof of concept, it works; as a way to remove blank lines using |
@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 |
This seems like a good thing to have without having to bring in style cop. |
Agree with @niemyjski. This seems like such a basic feature, why rely on StyleCop? |
@JoeRobich can you please reopen |
@niemyjski If the request is to have these empty line formatting options in the box, then it would be best to open a feature request on Roslyn (https://github.com/dotnet/roslyn/issues). I know Roslyn has experimental analyzers for consecutive empty line and some other empty line scenarios (see dotnet/roslyn#50358). |
Shouldn't this be part of the |
@norberthuethmayr whitespace options for |
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)
The text was updated successfully, but these errors were encountered: