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 S4056: Rule should not recommend to use obsolete methods #708

Closed
gkello opened this issue Aug 21, 2017 · 1 comment
Closed

Fix S4056: Rule should not recommend to use obsolete methods #708

gkello opened this issue Aug 21, 2017 · 1 comment
Assignees
Labels
Type: False Positive Rule IS triggered when it shouldn't be.
Milestone

Comments

@gkello
Copy link

gkello commented Aug 21, 2017

Description

The usage of Enum.ToString() method is detected by S4056 rule, but the overloads which are using IFormatProvider are depreciated, as described in https://docs.microsoft.com/en-us/dotnet/api/system.enum.tostring?view=netframework-4.7

ToString(String, IFormatProvider) This method overload is obsolete; use ToString(String).
ToString(IFormatProvider) This method overload is obsolete; use ToString().

Repro steps

string str1 = DayOfWeek.Monday.ToString();
string str2 = DayOfWeek.Monday.ToString("F");

Expected behavior

No issues for S4056 is detected

Actual behavior

Both lines are generating

Warning S4056 Use the overload that takes a 'CultureInfo' or 'IFormatProvider' parameter.

Known workarounds

Related information

  • SonarAnalyzer.CSharp 6.3.0.2862
  • Visual Studio Professional 2017, version 15.3.1
@Evangelink Evangelink changed the title S4056 false positive for Enum.ToString() Fix S4056: Rule should not recommend to use ToString(IFormatProvide) Aug 21, 2017
@Evangelink Evangelink changed the title Fix S4056: Rule should not recommend to use ToString(IFormatProvide) Fix S4056: Rule should not recommend to use Enum.ToString(IFormatProvide) Aug 21, 2017
@Evangelink
Copy link
Contributor

Hi @gkello,

Thanks for the feedback. You are right this usage is deprecated since fwk 2.0, we will fix this soon.

  • Update RSPEC-4056 to include exception
  • Update rule to conform to new behavior.

@Evangelink Evangelink added Area: RSPEC Type: False Positive Rule IS triggered when it shouldn't be. labels Aug 21, 2017
@Evangelink Evangelink added this to the 6.5 milestone Aug 21, 2017
@Evangelink Evangelink changed the title Fix S4056: Rule should not recommend to use Enum.ToString(IFormatProvide) Fix S4056: Rule should not recommend to use Enum.ToString(IFormatProvider) Aug 21, 2017
@michalb-sonar michalb-sonar self-assigned this Sep 12, 2017
@michalb-sonar michalb-sonar changed the title Fix S4056: Rule should not recommend to use Enum.ToString(IFormatProvider) Fix S4056: Rule should not recommend to use obsolete methods Sep 12, 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

3 participants