bkoelman / ResharperCodeContractNullability

Reports diagnostics, helping you to annotate your source tree with (Item)NotNull / (Item)CanBeNull attributes.
https://www.jetbrains.com/resharper/help/Code_Analysis__Code_Annotations.html
Apache License 2.0
26 stars 4 forks source link

Leaves a space behind when removing from function parameter #43

Closed RedX2501 closed 3 years ago

RedX2501 commented 3 years ago

Version Used: 2.0.2

Steps to Reproduce:

Have a function with the following signature:

public void DoSomething(
   [CanBeNull] bool theParameter,
   bool someOtherParameter
  {
  }

Expected Behavior:

After applying the CNUL rule:

public void DoSomething(
   bool? theParameter,
   bool someOtherParameter
  {
  }

Actual Behavior:

Notice the space left behind in front of the bool:

public void DoSomething(
    bool? theParameter,
   bool someOtherParameter
  {
  }
bkoelman commented 3 years ago

Thanks for reporting, I understand this is quite annoying.

Unfortunately, the code formatter API in Visual Studio is very limited. There are no settings for whitespace handling around attributes, so I implemented that myself for the default case (which means all parameters on the same line). See here for details. It is nearly impossible to get this right for the various styles used by developers, without relying on a formatter that 'understands' your style.

For formatting my own code, I'm using Resharper instead, which has overwhelming support for details like this. It can infer basic style settings from your codebase. Once configured properly, it only takes a single command to reformat all your code. Although Resharper is not free, their command-line runners are.