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

Sort namespaces as per stylecop rules/.net convention and remove unused namespaces from source files. #1963

Merged
merged 4 commits into from
Dec 25, 2018

Conversation

codemzs
Copy link
Member

@codemzs codemzs commented Dec 24, 2018

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:

  1. There is decent amount of code under IF DEFs that seems dead and should be removed, example:
    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.

  1. Consider removing Float and use float directly.

CC: @TomFinley

fixes #1961
fixes #1962

@codemzs codemzs changed the title Sort namespaces as stylecop rules/.net convention and remove unused namespaces from source files. Sort namespaces as per stylecop rules/.net convention and remove unused namespaces from source files. Dec 24, 2018
using System;
using System.Collections.Generic;
using System.Linq;
using Float = System.Single;
Copy link
Contributor

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.

Copy link
Contributor

@justinormont justinormont Dec 24, 2018

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)

Copy link
Member Author

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.

Copy link
Contributor

@TomFinley TomFinley Dec 25, 2018

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

Copy link
Contributor

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.

Copy link
Member

@sharwell sharwell left a 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:

  1. 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
  2. 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"
        }
      }
    }
  3. The analyzers for enforcing using directives ordering (SA1208, SA1209, SA1210, SA1211, SA1216, SA1217) and placement (SA1200) are enabled

    <Rule Id="SA1208" Action="None" />
    <Rule Id="SA1209" Action="None" />
    <Rule Id="SA1210" Action="None" />
    <Rule Id="SA1211" Action="None" />

    <Rule Id="SA1216" Action="None" />
    <Rule Id="SA1217" Action="None" />

@codemzs
Copy link
Member Author

codemzs commented Dec 24, 2018

@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

@codemzs
Copy link
Member Author

codemzs commented Dec 24, 2018

@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.

Copy link
Member

@sharwell sharwell left a 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;
Copy link
Member

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.

@codemzs codemzs requested review from abgoswam, wschin and ganik December 24, 2018 17:10
@TomFinley
Copy link
Contributor

TomFinley commented Dec 25, 2018

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.

@codemzs
Copy link
Member Author

codemzs commented Dec 25, 2018

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.

@TomFinley
Copy link
Contributor

Hi @TomFinley , I used VS’s powertools extension and ran it on every solution, 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.

Excellent. Thank you @codemzs (and @sharwell !).

Copy link
Contributor

@TomFinley TomFinley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @codemzs

@codemzs
Copy link
Member Author

codemzs commented Dec 25, 2018

Thank you for reviewing and approving, @TomFinley and @sharwell !

@codemzs codemzs requested review from artidoro and Anipik December 25, 2018 06:27
Copy link
Contributor

@Anipik Anipik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@codemzs
Copy link
Member Author

codemzs commented Dec 25, 2018

Thanks @Anipik for reviewing!

@codemzs codemzs merged commit a570da1 into dotnet:master Dec 25, 2018
@ghost ghost locked as resolved and limited conversation to collaborators Mar 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove unused namespaces in source files. Sort namespaces in source files as per Microsoft .NET convention
5 participants