codemaid icon indicating copy to clipboard operation
codemaid copied to clipboard

[Bug] Inserting a space before a single line comment

Open CodingOctocat opened this issue 1 year ago • 2 comments

Environment

  • Visual Studio version: 2022
  • CodeMaid version: 12.0
  • Code language: C#

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");
}

CodingOctocat avatar Aug 12 '23 10:08 CodingOctocat

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

codecadwallader avatar Oct 28 '23 14:10 codecadwallader

@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

CodingOctocat avatar Oct 30 '23 03:10 CodingOctocat