Skip to content
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

Fix S2275: Rule should not trigger on space before alignment #571

Closed
KevinSchienerCZ opened this issue Jul 19, 2017 · 3 comments
Closed
Assignees
Labels
Type: False Positive Rule IS triggered when it shouldn't be.
Milestone

Comments

@KevinSchienerCZ
Copy link

KevinSchienerCZ commented Jul 19, 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

  1. Run rule S2275 analysis on string.Format( "{0, -12}", "FooBar" ); (SonarLint with default ruleset will detect this.)

  2. 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)

@Evangelink Evangelink added Type: False Positive Rule IS triggered when it shouldn't be. question labels Jul 21, 2017
@Evangelink
Copy link
Contributor

Hi @KevinSchiener.

Thanks for the feedback! We will have a look to this issue quickly and get back to you.

@Evangelink Evangelink self-assigned this Jul 24, 2017
@Evangelink Evangelink added this to the 6.3 milestone Jul 24, 2017
@Evangelink
Copy link
Contributor

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 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
@KevinSchienerCZ
Copy link
Author

KevinSchienerCZ commented Jul 24, 2017

@Evangelink Thank you for the quick evaluation/fix.

@Evangelink Evangelink added rules and removed question labels Jul 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: False Positive Rule IS triggered when it shouldn't be.
Projects
None yet
Development

No branches or pull requests

2 participants