codecadwallader / codemaid

CodeMaid is an open source Visual Studio extension to cleanup and simplify our C#, C++, F#, VB, PHP, PowerShell, JSON, XAML, XML, ASP, HTML, CSS, LESS, SCSS, JavaScript and TypeScript coding.
http://www.codemaid.net
GNU Lesser General Public License v3.0
1.9k stars 358 forks source link

[Bug] Inserting a space before a single line comment #1016

Open CodingOctocat opened 1 year ago

CodingOctocat commented 1 year ago

Environment

Description

I enable: Inserting a space before a single line comment, For the most part it works fine, but if I use the Kernighan & Ritchie curly bracket style, it produces an unnecessary blank line.

Current behavior

SomeEvent += (s, e) => {

    // comment
    Console.WriteLine("Some code here");
}

Expected behavior

SomeEvent += (s, e) => {
    // comment
    Console.WriteLine("Some code here");
}
codecadwallader commented 11 months ago

Thanks for reporting the issue, I have been able to reproduce it. We have a regular expression that is used to try and capture the preceding brace exception, and I suspect it isn't covering this scenario.

https://github.com/codecadwallader/codemaid/blob/dev/CodeMaidShared/Logic/Cleaning/InsertBlankLinePaddingLogic.cs#L297

CodingOctocat commented 11 months ago

@codecadwallader Here's the solution from chatGPT, I haven't done much testing so just FYI:. (^[ \t]*(?!//)[^ \t\r\n\{].*(?<!\{)\r?\n)([ \t]*//)(?!//)(?![ \t]*\})

278929992-3f421805-b250-4bed-8bb8-7a4b10787b44