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

Enable more Roslynator rules #21192

Merged
merged 6 commits into from Nov 10, 2023
Merged

Conversation

RoosterDragon
Copy link
Member

Following on from #21176.

Enforces 6 Roslynator rules across the project.

I have batched together a PR for these rules as they are hopefully uncontroversial. However fixes are arranged per commit so we can easily bikeshed over rules as desired.

See https://josefpihrt.github.io/docs/roslynator/analyzers for explanation of each rule.

@@ -1052,6 +1061,9 @@ dotnet_diagnostic.RCS1159.severity = warning
# Unused type parameter.
dotnet_diagnostic.RCS1164.severity = warning

# Use read-only auto-implemented property.
dotnet_diagnostic.RCS1170.severity = warning
Copy link
Member

Choose a reason for hiding this comment

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

it looks like this rule was implemented incorrectly. Private setters were made public.

I'm not sure how this rule exactly works as it affected so little code, but this could make it harder to work with magic. In trait infos we use auto-implemented properties for non-yaml fields

Copy link
Member

Choose a reason for hiding this comment

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

Ah mb I misunderstood, but it did indeed remove the privateness from RadarWidget

Copy link
Member Author

Choose a reason for hiding this comment

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

The rule wants to change public string SoundUp { get; private set; } to public string SoundUp { get; }. However, this breaks our use of reflection in FieldLoader/ObjectCreator as it sets SoundUp from YAML.

I manually changed it to a field, like other things that need to be loaded from YAML, as it was the most elegant workaround I could see. This seemed like a worthwhile tradeoff so we can still enable an otherwise useful rule.

Copy link
Member

Choose a reason for hiding this comment

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

Looking at git blame yeah this is supposed to be used by reflection. I thought it was purposefully added to hide it from the reflection. 85b9cf0 7eb64ea

Copy link
Member

Choose a reason for hiding this comment

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

actually should have made these readonly to match other yaml defined values

if (explicitMounts.TryGetValue(filename[..explicitSplit], out var explicitPackage))
if (explicitPackage.Contains(filename[(explicitSplit + 1)..]))
return true;
if (explicitSplit > 0 &&
Copy link
Member

Choose a reason for hiding this comment

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

It would be nice if we could be consistent about whether the && goes at the start or end of the line in these cases. Is there a rule for that?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not aware of one offhand, but that's not to say there isn't one somewhere.

I've generally wrapped after as I think that's the more common convention in the codebase, but even in this chageset I wrap before in FieldLoader as that's the more common convention in that file.

Copy link
Member

Choose a reason for hiding this comment

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

I usually find the && or || nicer and more readable when placed at the start. Though it does depend on the length of the first line

@@ -63,8 +63,8 @@ public sealed class RadarWidget : Widget, IDisposable
PlayerRadarTerrain playerRadarTerrain;
Player currentPlayer;

public string SoundUp { get; private set; }
public string SoundDown { get; private set; }
public string SoundUp;
Copy link
Member

Choose a reason for hiding this comment

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

These should probably move up with the other widget fields?

Do we have a convention for widget fields to be readonly like we do for traits?

Copy link
Member Author

Choose a reason for hiding this comment

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

Moved upwards.

A quick flick through some widgets and it seems read-write fields are more common, but there are some read-only ones littered about.

@PunkPun PunkPun merged commit 9a3c398 into OpenRA:bleed Nov 10, 2023
3 checks passed
@PunkPun
Copy link
Member

PunkPun commented Nov 10, 2023

Changelog

@RoosterDragon RoosterDragon deleted the style-ros-med branch November 10, 2023 17:52
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.

None yet

4 participants