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

Add StyleCop.Analyzers and enable some basic suggestions #14074

Merged
merged 15 commits into from
Aug 14, 2023

Conversation

MikeAlhayek
Copy link
Member

@MikeAlhayek MikeAlhayek commented Aug 3, 2023

Adding StyleCop.Analyzers to help us enforce some good practices. We should be able to apply the SA1122 rule globally using the dotnet format to replace all "" with string.Empty.

Also, at some point I think almost all the rules that are defined as Warning in the link below should be defined at least as suggestion in OC.

https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/rulesets/StyleCopAnalyzersDefault.ruleset

@MikeAlhayek MikeAlhayek requested a review from jtkech August 3, 2023 23:03
.editorconfig Outdated
dotnet_diagnostic.SA1114.severity = none # Parameter list should follow declaration.
dotnet_diagnostic.SA1115.severity = none # Parameter should follow comma .
dotnet_diagnostic.SA1116.severity = none # Split parameters should start on line after declaration.
dotnet_diagnostic.SA1117.severity = suggestion # Parameters should be on same line or separate lines.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe not use tabs for the indentation.

Do we need rules for the .editorconfig itself ;)

.editorconfig Outdated Show resolved Hide resolved
@jtkech
Copy link
Member

jtkech commented Aug 4, 2023

Related to #12929 and #7950

Yes, I thought about this but the first goal was just to follow our current editor rules and the default analyzers, because it was already implying many updates.

Updated Analyzers and new ones will come with net8.0, trying dotnet 8.0 I could saw new code analysis suggestions.

Otherwise looks good, we will need more time to check the rules we want, at least the ones that we already follow implicitly, didn't try to define them without having to use StyleCop.

.editorconfig Outdated Show resolved Hide resolved
.editorconfig Outdated Show resolved Hide resolved
@MikeAlhayek
Copy link
Member Author

@jtkech I cleaned up the .editorconfig file. I also enabled few rules that we currently follow in OC. Once we merge this PR, we can then enable and apply globally other rules.

The idea with this PR here is to include the StyleCop analyzer and then use it in other PR along with applying rules.

@MikeAlhayek
Copy link
Member Author

@jtkech you recently did lots of clean up. Should we merge this one?

@jtkech
Copy link
Member

jtkech commented Aug 14, 2023

Refer to #14074 (comment)

@jtkech you recently did lots of clean up.

Yes, to follow our current rules and default analyzers, already implying many updates.

Should we merge this one?

I would like too to have at least the rules that we already follow implicitly, so I'm not against.

Just need to ask @sebastienros if he agrees to use StyleCop, knowing that:

  • Updated Analyzers and new ones will come with net8.0.

  • Didn't try to define these rules without using StyleCop, maybe not possible.

  • We may need a little more time to check the rules we want.

Yes, if we use StyleCop I will take the time to try some rules, not sure about String.Empty (but not against), "" does the same and there are many, we could add rules around the usage of braces ...

For info about our current rules, we have remaining violations, it looks like that when we run the code analysis it doesn't check the whole files, but I think we fixed most of the violations.

.editorconfig Outdated
dotnet_diagnostic.SA1113.severity = none # Comma should be on the same line as previous parameter.
dotnet_diagnostic.SA1114.severity = none # Parameter list should follow declaration.
dotnet_diagnostic.SA1115.severity = none # Parameter should follow comma .
dotnet_diagnostic.SA1116.severity = none # Split parameters should start on line after declaration.
Copy link
Member

Choose a reason for hiding this comment

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

Looks like there are some remaining tab indentations

dotnet_diagnostic.SA1505.severity = none # A closing brace should not be preceded by a blank line.
dotnet_diagnostic.SA1506.severity = none # Element documentation headers should not be followed by blank line.
dotnet_diagnostic.SA1507.severity = none # Code should not contain multiple blank lines in a row.
dotnet_diagnostic.SA1508.severity = none # Closing braces should not be preceded by blank line.
Copy link
Member

Choose a reason for hiding this comment

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

Yes, we could suggest this one

Copy link
Member Author

Choose a reason for hiding this comment

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

@jtkech
yes we could suggest more than just this one. But, I think in this PR, we should merge it as is if agreed. Once we merge it, we can use follow up PR to enable and apply which every rules we want. this way, it's easy to clean up the project using smaller PRs with one/two rules at a time.

dotnet_diagnostic.SA1510.severity = none # Chained statement blocks should not be preceded by blank line.
dotnet_diagnostic.SA1511.severity = none # While-do footer should not be preceded by blank line.
dotnet_diagnostic.SA1512.severity = none # Single-line comments should not be followed by blank line.
dotnet_diagnostic.SA1513.severity = none # Closing brace should be followed by blank line.
Copy link
Member

Choose a reason for hiding this comment

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

Idem, would need a little more time to check all of them ;)

src/OrchardCore.Build/Dependencies.props Outdated Show resolved Hide resolved
@jtkech
Copy link
Member

jtkech commented Aug 14, 2023

yes we could suggest more than just this one. But, I think in this PR, we should merge it as is if agreed. Once we merge it, we can use follow up PR to enable and apply which every rules we want. this way, it's easy to clean up the project using smaller PRs with one/two rules at a time.

Okay then, so I think it is too soon to suggest String.Empty, I suggest to remove this rule.

Then I will approve and merge, unless you prefer to wait for @sebastienros, if he prefers to not use StyleCop, hmm but anyway easy to revert.

@MikeAlhayek
Copy link
Member Author

@jtkech okay. I switched SA1122 to none for now. We always prefer String.Empty over "" which is why it was suggested. But yes, that can also be part of a separate PR

@jtkech
Copy link
Member

jtkech commented Aug 14, 2023

Yes I agree but for now to not add 500 new sugestions in the current code.

@jtkech jtkech merged commit ec01501 into OrchardCMS:main Aug 14, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants