-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Sort namespaces as per stylecop rules/.net convention and remove unused namespaces from source files. #1963
Conversation
…amespaces from source files.
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Float = System.Single; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we rename Float
in the file to Single
? It seems odd having our own alias of float
/Single
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems we do this in many of the files... (not just this one file)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be we should but does it make sense to be it owns change so that its easier on the reviewers? Apparently there are 54 files where Float = System.Single is being used so I suspect removing them all and changing all their references to float might pollute this change. Lets see what @TomFinley feels? I'm fine either ways.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's unclear to me why we're bringing that up in this PR. There is no urgency to that change. We've been doing it opportunistically (not that exactly, but Float
to float
). Let's continue that policy. Doing it all at once would cause a great deal of conflicts with existing changes for no particular reason whatsoever. (These changes being at the header of the file are at least easier to manage.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed.
I initially didn't notice using Float = System.Single;
was used in many files. If it was only in one, I'd ask for the change. It's a larger tasks which belongs in its own PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to standardize on the format used in this pull request, I would expect to see the following changes as well:
-
A .editorconfig is added which sets the placement of System using directives for C# source files:
# Sort using and Import directives with System.* appearing first dotnet_sort_system_directives_first = true
-
A stylecop.json file is added, which sets the expected using directives placement to outside the namespace
{ "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json", "settings": { "orderingRules": { "usingDirectivesPlacement": "outsideNamespace" } } }
-
The analyzers for enforcing using directives ordering (SA1208, SA1209, SA1210, SA1211, SA1216, SA1217) and placement (SA1200) are enabled
machinelearning/src/Source.ruleset
Lines 148 to 151 in 0c62e30
<Rule Id="SA1208" Action="None" /> <Rule Id="SA1209" Action="None" /> <Rule Id="SA1210" Action="None" /> <Rule Id="SA1211" Action="None" /> machinelearning/src/Source.ruleset
Lines 155 to 156 in 0c62e30
<Rule Id="SA1216" Action="None" /> <Rule Id="SA1217" Action="None" />
@sharwell This is great feedback and I was thinking the same how we could standardize, thanks. Do you by any chance have an example of a repo that contains such standardization? i.e use of .editorconfig and stylecop.json |
@sharwell Thanks for reaching out on IM today evening and helping me with standardizing stylecop. I found some errors using it that I had earlier missed, not sure how even though I used VS's power tools extensions to sort namespaces and remove unused ones. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 I forgot to include SA1200 in the set of diagnostics that can be enabled in the ruleset file, but that's less important than the other 6 you already included and could easily be part of a future change.
|
||
[assembly: LoadableClass(typeof(SumupPerformanceCommand), typeof(SumupPerformanceCommand.Arguments), typeof(SignatureCommand), | ||
"", "FastTreeSumupPerformance", "ftsumup")] | ||
|
||
namespace Microsoft.ML.Trainers.FastTree | ||
{ | ||
using Stopwatch = System.Diagnostics.Stopwatch; | ||
using Stopwatch = System.Diagnostics.Stopwatch; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😕 not sure how this indentation change happened.
Hi @codemzs, may I ask how we automated this change? My reasons for wondering are, I feel like in a PR like this it would be more helpful to review how we automated, rather than review every single file. At least, assuming you did automate. 😄 Maybe you didn't. |
Hi @TomFinley , I used VS’s powertools extension and ran it on every project, compiled it, fixed extra lines errors and repeated the process. Lastly I enforced namespaces be sorted via editor configuration using the method @sharwell suggested, this also verified the namespaces are sorted as per .NET standards outlined in this PR’s description. |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @codemzs
Thank you for reviewing and approving, @TomFinley and @sharwell ! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks @Anipik for reviewing! |
Sorts namespaces as per stylecop rules/.net convention and removes unused namespaces from source files. Standardizes namespace to be always sorted as per .NET convention in source files.
My impressions after doing this change:
In IntArray.cs
#if USE_SINGLE_PRECISION
using FloatType = System.Single;
#else
using FloatType = System.Double;
#endif
USE_SINGLE_PRECISION is not defined anywhere and FloatType is not at all used anywhere in the file. We should consider opening an issue to do this sort of clean up. There are many such examples.
CC: @TomFinley
fixes #1961
fixes #1962