You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is being reported as a 'Blocker' severity violation by SonarQube. The problem is the space between the , and -12. The code executes perfectly fine.
There might be more optional spaces in the format item.
Repro steps
Run rule S2275 analysis on string.Format( "{0, -12}", "FooBar" ); (SonarLint with default ruleset will detect this.)
To "fix" the issue you can remove the space between the , and -12.
Expected behavior
No issue should be raised. Alternatively I could also live with the fact that the format without the space is the one defined by the MSDN doc and, thus, constitutes the official API. The trimming of spaces is an additional feature we should not rely on. However, I highly doubt that MS would ever change this.
That's a really weird thing. You can have a space before and after the , but you cannot have space after : in order to have the expected format string.
Evangelink
changed the title
S2275 Rule should not trigger on space before alignment
Fix S2275: Rule should not trigger on space before alignment
Jul 24, 2017
Description
We have code in the form of
string.Format( "{0, -12}", "FooBar" );
.This is being reported as a 'Blocker' severity violation by SonarQube. The problem is the space between the
,
and-12
. The code executes perfectly fine.There might be more optional spaces in the format item.
Repro steps
Run rule S2275 analysis on
string.Format( "{0, -12}", "FooBar" );
(SonarLint with default ruleset will detect this.)To "fix" the issue you can remove the space between the
,
and-12
.Expected behavior
No issue should be raised. Alternatively I could also live with the fact that the format without the space is the one defined by the MSDN doc and, thus, constitutes the official API. The trimming of spaces is an additional feature we should not rely on. However, I highly doubt that MS would ever change this.
MSDN: https://docs.microsoft.com/en-us/dotnet/standard/base-types/composite-formatting?view=netframework-4.7
Actual behavior
A 'Blocker' type issue gets raised.
Known workarounds
Mark as false-positive.
Related information
SonarC# Version: 5.10.1 (build 1411)
The text was updated successfully, but these errors were encountered: