Skip to content

Conversation

@iSazonov
Copy link
Collaborator

@iSazonov iSazonov commented May 24, 2018

PR Summary

Related #4708.

Disable:

  1. SA1402 FileMayOnlyContainASingleType
  2. SA1403 FileMayOnlyContainASingleNamespace
  3. SA1101 PrefixLocalCallsWithThis
  4. SA1126 PrefixCallsCorrectly

stylecop.json

PR Checklist

Disable SA1402 and SA1403 rules.
@markekraus
Copy link
Contributor

I think for this project we need to disable SA1200 too. This project almost exclusively has using statements outside the namespace.

As for whether that is a good thing or not... is debatable.

@TravisEz13
Copy link
Member

restarted CI due to an update-help connection failure in travis-ci

@TravisEz13
Copy link
Member

@SteveL-MSFT @adityapatwardhan @daxian-dbw I've put the list of what is being disabled in the description. Are we all ok with this? I prefer a file only contain a single class, but I agree that it is not what we have been doing.

Copy link
Member

@TravisEz13 TravisEz13 left a comment

Choose a reason for hiding this comment

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

I prefer files only contain a single class, but I agree the code base doesn't follow this standard. I'm fine with this if others agree.

@markekraus
Copy link
Contributor

My opinion on this is that we should do what is best for an Open Source project, whatever that is.

One problem I hear from people acclimating to the code base is that these monolith files are both intimidating and hard to follow. It is often gating low complexity changes from novice contributors.

I personally believe it is easier to track changes from larger numbers of people if those changes are spread over a larger number of files.

To both those ends, one class per file is probably better.

@iSazonov
Copy link
Collaborator Author

While IntelliSense works in VS Code I haven't difficulties with multi-class files. :-)

Our guideline says that we don't want style changes but CodeFactor fixes is style changes. Should we ignore/remove the requirement or replace with requirement to fix CodeFactor issues?

Also we have a requirement to follow current file style. This makes the code easier to read. If we follow the CodeFactor requirements we break the readability.

I suppose we should first set a top policy:

  • should we fix all (approved/not disabled) CodeFactor issues
  • should we fix problems for specific rules only

@markekraus
Copy link
Contributor

Also we have a requirement to follow current file style.

Except, in practice, reviewers are requesting contributors not do that as often as they enforce it

IMO, for StyleCop or CodeFactor to really help us, we have to first refactor the entire code base to meet the style rules chosen, Then all new changes would just need to follow the rules. I had a recent PR where CodeFactor was complaining about code I didn't even touch just because it was in the same file. I'm not sure how that is even useful.

@iSazonov
Copy link
Collaborator Author

Fix all 186264 issues is very hude work even if we turn down some rules.

@markekraus
Copy link
Contributor

@iSazonov Agreed. This problem is why I ultimately stopped investigating style enforcement, The project has guidelines which are not compatible with style enforcement (use style of surrounding code, don't make style changes), tools for style enforcement are not precise enough to limit detection to just the code added or change in the PR (makes it useless for reviews), and fixing the style globally so that rules and tools can be useful is a massive undertaking. Also, trying to fix the problems in a single area (like web cmdlets) is a strain on the reviewers and the contributor, there are not enough contributors and reviewers to tackle the problem in just one area, let alone globally.

@iSazonov
Copy link
Collaborator Author

Some issues can be easily fixed:
"" -> string.Empty
String -> string

It is up to 1-2% issues.

Do you know of other problems that can be easily fixed?

@markekraus
Copy link
Contributor

  • Char -> char
  • "Closing Curly braces must be followed by a blank line"
  • "Elements must be separated by a blank line"
  • Single line comments must begin with a space

Basically, the white space rules are all easy wins and there are a ton of them.

@markekraus
Copy link
Contributor

We could also properly configure "The file header must contain a copyright tag" so that it doesn't false-alarm or just disable SA1634.

SA1518 should be set to required.

These are some of the easy low risk wins, I think:

@iSazonov
Copy link
Collaborator Author

@markekraus Thanks!

SA1518 is on by default.

the white space rules are all easy wins and there are a ton of them.

Maybe formatting tool from .NET code formatter tool can help? Our docs says :-)

We also run the .NET code formatter tool regularly to keep consistent formatting.

Where can get a config for the CodeFormatter?

@lzybkr
Copy link
Contributor

lzybkr commented May 29, 2018

The default settings were used when I ran the code formatter.

Some folks may like StyleCop, but I think it will discourage some contributors - it's far too picky.

And I've stated this before, but I strongly oppose one class per file - that decision should be up to the author and primary maintainer of the feature.

@lzybkr
Copy link
Contributor

lzybkr commented May 29, 2018

And to provide some data behind my objection to 1 class per file - there are > 3200 types in System.Management.Automation and ~740 cs files, so the average is >4 types per file. Going to 1 type per file means quadrupling the number of files in the project.

I'm not opposed to targeted improvements, but please don't blindly apply an arbitrary policy.

@iSazonov
Copy link
Collaborator Author

iSazonov commented May 29, 2018

@lzybkr Thanks! I agree that we should disable rule for "one class per file".
What do you think about rule which says about prefixes like "this."? CodeFactor reports tons such issues.

@lzybkr
Copy link
Contributor

lzybkr commented May 29, 2018

I'd also ignore the this. prefix warning. More unnecessary churn if you change it, and much riskier to use a regex to "fix".

@SteveL-MSFT
Copy link
Member

I'm fine with the proposed disabled settings. In general, we should error on the side of productivity and lowering the barrier for contributions.

@iSazonov
Copy link
Collaborator Author

@lzybkr

much riskier to use a regex to "fix".

I did not use a script with Regex. I did the changes in VS Code step by step selecting a pattern and then visually checking the results to exclude false changes, then commit changes for the pattern, then select next pattern.

@iSazonov
Copy link
Collaborator Author

Disable SA1101 and SA1126 - up to 25% win.

@iSazonov
Copy link
Collaborator Author

iSazonov commented May 30, 2018

I think we should disable

@lzybkr
Copy link
Contributor

lzybkr commented May 31, 2018

@iSazonov - removing this. can change a program's behavior. Consider:

    class C {
        int value;
        void f(int v1, int value) {
            this.value = v1;
        }
    }

If you remove this. - you will be assigning to the parameter. I'm not aware of tools that will help detect this change - it's very manual. This is why I said it's risky.

@iSazonov
Copy link
Collaborator Author

@lzybkr I means disabling rules SA1101 and SA1126 not changing real code. I believe you agree with the disabling.

@iSazonov
Copy link
Collaborator Author

In #6949 @lzybkr suggest disable SA1131 UseReadableConditions

@iSazonov
Copy link
Collaborator Author

iSazonov commented Jun 3, 2018

I think we can merge, look how CodeFactor statistics will be changed for master branch and continue adjust the settings in follow PRs.

@iSazonov iSazonov merged commit d67d87c into PowerShell:master Jun 4, 2018
@iSazonov iSazonov deleted the add-settings-stylecop branch June 4, 2018 05:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants