-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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 workflow to automatically check code style issues for PRs #4670
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
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 took a quick look, didn't look at everything yet since the diff is pretty large.
It might be easier to review if the change moving everything to a src
sub-directory is done on a separate PR. GitHub is currently showing this:
The diff you're trying to view is too large. We only load the first 3000 changed files.
So I guess it is not showing all the changes.
About the style changes, the only one I'm not sure about is the new()
change. I'm not sure if we should be enforcing it everywhere, it sounds like something that would come up quite often. There are a few other changes that I would probably take a while to get used to, but I don't think they would be triggered often enough to annoy me.
There are a few warnings that seems to be disabled with pragmas quite often (like IDE0066). I didn't actually look at the number of times we need to disable it, but if it happens too often, maybe it's better to just set csharp_style_prefer_switch_expression = false
on the editorconfig to avoid needing to disable it many times.
src/Ryujinx.Audio.Backends.OpenAL/OpenALHardwareDeviceDriver.cs
Outdated
Show resolved
Hide resolved
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
My intention was to enforce the existing rules from editorconfig, but also consider how we address styling in PRs currently. If I made changes here which don't reflect the code style of Ryujinx, I should revert them and adapt editorconfig to match the code style instead. |
This comment was marked as resolved.
This comment was marked as resolved.
Download the artifacts for this pull request: Experimental GUI (Avalonia)GUI-less (SDL2)Only for Developers
|
I was talking about cases where About the switch expression change, I like switch expressions, but I'm not a fan of switch expression with |
Unrelated to the discussion above, but it would be nice if we could catch naming violations too. For example, I can write a method like |
Ah I misunderstood then! I didn't want to change too many things at once, so I added the #pragmas first, so we could discuss whether we want to disable these rules or enforce them properly. (I should have kept track of them and added a list here, oh well.)
Hmm, I'll have to think about this some more, but it doesn't sound impossible to me, since analyzers should be able to detect logical patterns. We might be able to add an analyzer to this.
It's surprising there isn't but we might as well add one. I think it could save us a lot of work too. |
That's fair, I guess let others chime in so that we can decide what we should enforce and what we should disable on the
Maybe a bit overkill to have our own analyzer just to enforce switch expressions to be used in some cases.
There is an issue on the Roslyn tracking the implementation of one (dotnet/roslyn#14983), but who knows when it will be done. |
It sounds fun to implement (currently), so I might add something to |
ca62211
to
6b3d49a
Compare
These are the default rules, so we don't need to override them.
Bindings won't work with static members, but this issue is silently ignored.
Skipping 4.5.0 since it breaks dotnet format
…x#4670) * Add workflow to perform automated checks for PRs * Downgrade Microsoft.CodeAnalysis to 4.4.0 This is a workaround to fix issues with dotnet-format. See: - dotnet/format#1805 - dotnet/format#1800 * Adjust editorconfig to be more compatible with Ryujinx code-style * Adjust .editorconfig line endings to match .gitattributes * Disable 'prefer switch expression' rule * Remove naming styles These are the default rules, so we don't need to override them. * Silence IDE0060 in .editorconfig * Slightly adjust .editorconfig * Add lost workflow changes * Move .editorconfig comment to the top * .editorconfig: private static readonly fields should be _lowerCamelCase * .editorconfig: Remove alignment for declarations as well * editorconfig: Add rule for local constants * Disable CA1822 for HLE services * Disable CA1822 for ViewModels Bindings won't work with static members, but this issue is silently ignored. * Run dotnet format for the whole solution * Check result code of SDL_GetDisplayBounds * Fix dotnet format style issues * Add missing trailing commas * Update Microsoft.CodeAnalysis.CSharp to 4.6.0 Skipping 4.5.0 since it breaks dotnet format * Restore old default naming rules for dotnet format * Add naming rule exception for CPU tests * checks: Include all files before excluding paths * Fix dotnet format issues * Check dotnet format version * checks: Run dotnet format with severity info again * checks: Disable naming style rules until they won't crash the process anymore * Remove unread private member * checks: Attempt to run analyzers 3 times before giving up * checks: Enable naming style rules again with the new retry logic
This PR was originally planned to contain a lot more things, but formatting already took a while and I didn't expect our codebase to report so many issues (via dotnet-format).
A new workflow will now be triggered for every PR which will run dotnet-format to check for style issues.
If the workflow doesn't succeed the author of the PR will need to make some style changes, before we are able to merge the PR. The issues dotnet-format found will be uploaded as an artifact but also printed to the log of the workflow run.
This allows reviewers to focus more on actual code review instead of adding a lot of comments about minor styling issues. This will hopefully make reviews a little bit easier and authors still get feedback about code styling with the workflow.
I was able to automate silencing some of the issues dotnet-format reported with this script.
Since this PR required a few other code changes to make dotnet-format happy, feel free to suggest improvements/changes to those as well.
Feedback about this approach would also be appreciated!
List of code style/quality rules we need to discuss:
IDE0044: Add readonly modifier
IDE0051: Remove unused private member
IDE0052: Remove unread private member
IDE0059: Remove unnecessary value assignment
IDE0060: Remove unused parameter
IDE0066: Use switch expression
IDE1006: Naming rule violation
CS0169: The private field 'class member' is never used
CS0414: The private field 'field' is assigned but its value is never used
CS0649: Field 'field' is never assigned to, and will always have its default value 'value'
CA1822: Mark members as static
CA1834: Use StringBuilder.Append(char) for single character strings