8000 Enable Roslyn analyzers in build process by iSazonov · Pull Request #11916 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@iSazonov
Copy link
Collaborator
@iSazonov iSazonov commented Feb 21, 2020

PR Summary

  • Enable Roslyn analyzers in build process
  • Force rule IDE0044: Add readonly modifier
  • Add commit to fix the rule IDE0044

PR Context

Analyzers help to make code high quality.
See .Net Runtime experience dotnet/runtime#30740

We should benefit from C# analyzers too.

PR Checklist


This change is Reviewable

PowerShell.sln Outdated
Copy link
Member

Choose a reason for hiding this comment

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

Please revert this changes

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Only the line or all such lines?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Reverted all.

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.

too big to review, PR review tool doesn't function

@ghost ghost added the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Feb 21, 2020
@TravisEz13
Copy link
Member

Perhaps you can enable one rule at a time to reduce the file changes. I cannot jump to files due to the large number of changes.

@ghost ghost removed the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Feb 22, 2020
@iSazonov
Copy link
Collaborator Author

@TravisEz13 You can review commit by commit. Yes, only one rule is forced in the PR. This add "readonly" qualifier. I will split the large commit by 20-30 files.

@iSazonov iSazonov force-pushed the cleanup-analyzers-fixes-2 branch from a174eb6 to 47c88bc Compare February 22, 2020 17:59
@TravisEz13
Copy link
Member

Git hub doesn't have a mechanism for tracking reviews, commit by commit. I can see if reviewable still works.

@TravisEz13
Copy link
Member

@PoshChan Please remind me in 2 days

@PoshChan
Copy link
Collaborator

@TravisEz13, this is the reminder you requested 2 days ago

@iSazonov iSazonov force-pushed the cleanup-analyzers-fixes-2 branch from 47c88bc to a6b8bc0 Compare March 9, 2020 17:28
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.

Reviewed 31 of 366 files at r1.
Reviewable status: 31 of 366 files reviewed (waiting on @adityapatwardhan, @anmenaga, @daxian-dbw, @iSazonov, and @SteveL-MSFT)

@TravisEz13
Copy link
Member

I'll try to review a portion each day.

@TravisEz13
Copy link
Member

@PoshChan Please remind me in 1 day.

@PoshChan
Copy link
Collaborator

@TravisEz13, this is the reminder you requested 1 day. ago

@xtqqczze
Copy link
Contributor

This PR does not seem to enable any analyzers during the build process. If it did then the build would fail since IDE1006.severity is set to error and there are 904 IDE1006 rule violations.

@xtqqczze
Copy link
Contributor

Currently IDE code style rules do not apply during builds, see dotnet/roslyn#33558

@iSazonov
Copy link
Collaborator Author
iSazonov commented Apr 17, 2020

@xtqqczze Yes, you are right about that IDE rules. The PR is only initial for the enhancement of our build process. Later we can easily add other rules and force then as needed. Also I hope the .Net issue will fixed in some w A3E2 ay.

Update: the next Microsoft.CodeAnalysis.CSharp 3.6.0 will implement this in days.

Copy link
Collaborator
@vexx32 vexx32 left a comment

Choose a reason for hiding this comment

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

Overall these changes look good. I have a couple questions/comments on a few of them. 🙂

Comment on lines +82 to +96
private readonly string _name;

/// <summary>
/// The string defining real cmdlet name.
/// </summary>
internal string Value { get { return this._value; } }

private string _value = string.Empty;
private readonly string _value = string.Empty;

/// <summary>
/// The string defining real cmdlet name.
/// </summary>
internal ScopedItemOptions Options { get { return this._options; } }

private ScopedItemOptions _options = ScopedItemOptions.AllScope | ScopedItemOptions.ReadOnly;
private readonly ScopedItemOptions _options = ScopedItemOptions.AllScope | ScopedItemOptions.ReadOnly;
Copy link
Collaborator
@vexx32 vexx32 May 12, 2020

Choose a reason for hiding this comment

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

Am I remembering wrong or was this file removed in a recent PR since it only functions to add command aliases, which were moved to attributes?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is still not merged.

/// This is the default function to use for tab expansion.
/// </summary>
private static string s_tabExpansionFunctionText = @"
private static readonly string s_tabExpansionFunctionText = @"
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems like something we'd have as const, no?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is static. If it is wrong we should fix this in another PR.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah that's why I asked. Maybe make a note of these and we can have another look in a later PR, see if it's worth making them const. 🙂

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is used only once. I believe the const would be saved in a static area too and it makes no sense to change - we get no perf benefits.

";

private static string s_createCommandExistsInCurrentDirectoryScript = @"
private static readonly string s_createCommandExistsInCurrentDirectoryScript = @"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should these strings be const?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The same.

Comment on lines 1082 to +1098
internal struct CRYPT_PROVIDER_CERT
{
private DWORD _cbStruct;
private readonly DWORD _cbStruct;
internal IntPtr pCert; // PCCERT_CONTEXT
private BOOL _fCommercial;
private BOOL _fTrustedRoot;
private BOOL _fSelfSigned;
private BOOL _fTestCert;
private DWORD _dwRevokedReason;
private DWORD _dwConfidence;
private DWORD _dwError;
private IntPtr _pTrustListContext; // CTL_CONTEXT*
private BOOL _fTrustListSignerCert;
private IntPtr _pCtlContext; // PCCTL_CONTEXT
private DWORD _dwCtlError;
private BOOL _fIsCyclic;
private IntPtr _pChainElement; // PCERT_CHAIN_ELEMENT
private readonly BOOL _fCommercial;
private readonly BOOL _fTrustedRoot;
private readonly BOOL _fSelfSigned;
private readonly BOOL _fTestCert;
private readonly DWORD _dwRevokedReason;
private readonly DWORD _dwConfidence;
private readonly DWORD _dwError;
private readonly IntPtr _pTrustListContext; // CTL_CONTEXT*
private readonly BOOL _fTrustListSignerCert;
private readonly IntPtr _pCtlContext; // PCCTL_CONTEXT
private readonly DWORD _dwCtlError;
private readonly BOOL _fIsCyclic;
private readonly IntPtr _pChainElement; // PCERT_CHAIN_ELEMENT
Copy link
Collaborator
@vexx32 vexx32 May 12, 2020

Choose a reason for hiding this comment

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

We don't provide a constructor to set these and they're readonly. How would these be set?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Same question for the rest of the structs in this file actually.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'd ask why they private :-)

Looks like false positives.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah both are good questions here 😁

Not sure how this struct is actually used to be honest, but I don't see how it would be useful at the moment.

Copy link
Collaborator Author
@iSazonov iSazonov May 13, 2020

Choose a reason for hiding this comment

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

In fact, all these structures are created in P/Invoke, they are really readonly for C# and "private" here is "named unused".
I believe we can accept the change.

@iSazonov
Copy link
Collaborator Author

@TravisEz13 Could you please continue?

@xtqqczze
Copy link
Contributor

@iSazonov something to be aware of: dotnet/roslyn#43051

@iSazonov
Copy link
Collaborator Author
iSazonov commented May 19, 2020

@xtqqczze Thanks! We use warnaserror in the project.
And we force errors

# IDE0044: Add readonly modifier
dotnet_style_readonly_field = true:error

@iSazonov
Copy link
Collaborator Author

@TravisEz13 Could you please continue the code review?

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.

Reviewed 35 of 366 files at r1.
Reviewable status: 57 of 366 files reviewed (waiting on @adityapatwardhan, @anmenaga, @daxian-dbw, @iSazonov, @SteveL-MSFT, @TravisEz13, and @vexx32)

@ghost ghost added the Review - Needed The PR is being reviewed label Jun 9, 2020
@ghost
Copy link
ghost commented Jun 9, 2020

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Mainainer, Please provide feedback and/or mark it as Waiting on Author

@adityapatwardhan adityapatwardhan removed this from the 7.1.0-preview.4 milestone Jun 29, 2020
@xtqqczze
Copy link
Contributor

@iSazonov It seems this PR is stale, we could continue with IDE0044 in #13880? We could split the changes into multiple PRs for ease of review.

@iSazonov
Copy link
Collaborator Author

@iSazonov It seems this PR is stale, we could continue with IDE0044 in #13880? We could split the changes into multiple PRs for ease of review.

Yes.

@ghost ghost removed the Review - Needed The PR is being reviewed label Oct 26, 2020
@iSazonov iSazonov closed this Oct 26, 2020
@iSazonov iSazonov deleted the cleanup-analyzers-fixes-2 branch October 26, 2020 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-CodeCleanup Indicates that a PR should be marked as a Code Cleanup change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

0