★ wanayoo — archive 1999 https://github.com/code-cracker/code-cracker/issues/407Nouvelle recherche | Portail wanayoo
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

Change CC0001 so that it does not apply to primitives #407

Closed
OsirisTerje opened this issue Jul 13, 2015 · 8 comments
Closed

Change CC0001 so that it does not apply to primitives #407

OsirisTerje opened this issue Jul 13, 2015 · 8 comments

Comments

@OsirisTerje
Copy link

@OsirisTerje OsirisTerje commented Jul 13, 2015

Change CC0001 so that it only works on non primitives. Raise the new CC0105 for primitives.
There is a list of primitives types on MSDN of primitives from C#:

The primitive types are Boolean, Byte, SByte, Int16, UInt16, Int32, UInt32, Int64, UInt64, IntPtr, UIntPtr, Char, Double, and Single.

Remarks:

  • DateTime is not a primitive and should still be covered by CC0001.
  • String is not a primitive and should still be covered by CC0001.
  • CC0105 Should apply to both when the type is declared using an identifier name (System.Int32 i;) or using a predefined type (int i;).
  • CC0105 should follow CC0001 category and severity level (Style and Warning).
  • The code fix provider for CC0001 should updated to support CC0105, but not other change should be made to it.

Just as a reference, this is @OsirisTerje original comment:

As it is now, the CC0001 rule, "Use 'var' instead of specifying the type name" applies to any type. It could be wise to separate this into two rules, or, if possible, have an option for it, so that one can have it apply to only non-primitive types. Resharper also have this as an option.

@AlbertoMonteiro
Copy link
Member

@AlbertoMonteiro AlbertoMonteiro commented Jul 13, 2015

I guess that variable names should solve this problem, so IHMO, we should not give this kind of flexibility.
For me, CC help me to have a better code, and naming my variables correctly is one of the steps to get better code.

@giggio
Copy link
Member

@giggio giggio commented Jul 13, 2015

All rules are optional. The user only needs to edit the rules file and done. This is a .NET thing, and VS makes it really easy to do.
That said, I also think the standard is good, but I am aware some people don't like it. I am not against we having a separate set of rules that are disabled by default, and then they could enable them. Or even replacing the current CC0001 with 2 others, one for primitives and another for non primitives. The user could then turn them on or off.
And are really discussing primitives? DateTime is not a primitive. string is also not.

@OsirisTerje
Copy link
Author

@OsirisTerje OsirisTerje commented Jul 16, 2015

I think the idea of having two rules here sounds good.
With primitives I think of int, float, double, decimal etc.
Datetime is a struct, and could well be covered by 001.
String is a bit of both - in fact it is a kind of structure, so to me, any way is fine.

@dgmachado
Copy link

@dgmachado dgmachado commented Jul 21, 2015

I agree that it would be wise to separate this into two rules. This var usage rule applied to number types can induce to errors. For example, the following sentence will launch the compiler error CS0031:

short c = 1000000000; //CS0031

If you use the following sentence nothing will be launched:

var c = 1000000000;

@giggio
Copy link
Member

@giggio giggio commented Jul 22, 2015

I agree to change CC0001 so that it does not apply to primitives. string is not a primitive, but just to reinforce: I would leave string still raising CC0001, like: string a = "";.
And I agree to create a different one that would apply to primitives and complement CC0001. I think it should be enabled by default, and the user can always disable it if they want. So this way we maintain the current behavior.
Everyone, please see if that satisfies you. @code-cracker/owners your opinion is wanted.

@dgmachado the change to var could be seen as a fix. I don't really see a problem, the code is already broken.

@dgmachado
Copy link

@dgmachado dgmachado commented Jul 22, 2015

I agree with you @giggio.

@OsirisTerje
Copy link
Author

@OsirisTerje OsirisTerje commented Jul 22, 2015

Agree

@giggio giggio changed the title Should the var usage rule also apply to primitives? Change CC0001 so that it does not apply to primitives Sep 13, 2015
@giggio giggio added this to the 1.0.0 milestone Sep 13, 2015
@giggio
Copy link
Member

@giggio giggio commented Sep 13, 2015

I have updated the description so that it fits what we discussed. The issue is up for grabs and will be on 1.0.0.

@giggio giggio modified the milestones: 1.0.0-rc3, 1.0.0 Oct 3, 2015
@giggio giggio modified the milestones: 1.0.0-rc4, 1.0.0 Nov 2, 2015
@giggio giggio closed this in ca18464 Nov 26, 2015
giggio added a commit that referenced this issue Nov 26, 2015
Fixes #407 CC0001 no longer applies to primitives
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.