Skip to content

feat: Enable Rule CA2211 #9857

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

Merged

Conversation

workgroupengineering
Copy link
Contributor

What does the pull request do?

CA2211

What is the current behavior?

What is the updated/expected behavior with this PR?

How was the solution implemented (if it's not obvious)?

Checklist

Breaking changes

Obsoletions / Deprecations

Fixed issues

Part of #8944

@workgroupengineering
Copy link
Contributor Author

@robloo Can you review?

@avaloniaui-team
Copy link
Contributor

You can test this PR using the following package version. 11.0.999-cibuild0028064-beta. (feed url: https://pkgs.dev.azure.com/AvaloniaUI/AvaloniaUI/_packaging/avalonia-all/nuget/v3/index.json) [PRBUILDID]

@@ -31,7 +31,7 @@ public DataGridCheckBoxColumn()
/// <summary>
/// Defines the <see cref="IsThreeState"/> property.
/// </summary>
public static StyledProperty<bool> IsThreeStateProperty =
public readonly static StyledProperty<bool> IsThreeStateProperty =
Copy link
Contributor

@robloo robloo Jan 3, 2023

Choose a reason for hiding this comment

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

nit: Convention in this project seems to be "static readonly" ordering

@@ -8,6 +8,6 @@ public static class ToolTipDiagnostics
/// <summary>
/// Provides access to the internal <see cref="ToolTip.ToolTipProperty"/> for use in DevTools.
/// </summary>
public static AvaloniaProperty<ToolTip?> ToolTipProperty = ToolTip.ToolTipProperty;
public readonly static AvaloniaProperty<ToolTip?> ToolTipProperty = ToolTip.ToolTipProperty;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Convention in this project seems to be "static readonly" ordering

Comment on lines 292 to 295
#pragma warning disable CA2211 // Non-constant fields should not be visible
protected static Color[,]? _colorChart = null;
protected static object _colorChartMutex = new object();
#pragma warning restore CA2211 // Non-constant fields should not be visible
protected static readonly object _colorChartMutex = new();
Copy link
Contributor

@robloo robloo Jan 3, 2023

Choose a reason for hiding this comment

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

My comments here apply to all 4 affect color palettes.

  1. Firstly I'm not a fan of rule CA2211 for exactly this reason. It doesn't allow for protected fields which absolutely have a usage and don't violate the non-public principle. The rule needs to be fixed...
  2. With that said, the chart itself was made protected before the final design was complete. There was a thought that it would be needed in derived types. However, with the colors now held in an enum (compiled in for performance) and then the inability to share color charts between half/full palettes, I think this design is obsolete. My suggestion is to make both of these fields private.
  3. I don't care about the new() syntax usage. This is still largely developer preference so I probably wouldn't have changed it but it doesn't matter. Avalonia seems to prefer the shortest possible code.
private static Color[,]? _colorChart = null;
private static object _colorChartMutex = new();

private void InitColorChart()

If this ever needs to be undone in the future (I doubt it) It is very easy and non-breaking to make them protected again.

@avaloniaui-team
Copy link
Contributor

You can test this PR using the following package version. 11.0.999-cibuild0028138-beta. (feed url: https://pkgs.dev.azure.com/AvaloniaUI/AvaloniaUI/_packaging/avalonia-all/nuget/v3/index.json) [PRBUILDID]

@workgroupengineering workgroupengineering marked this pull request as ready for review January 4, 2023 09:15
@maxkatz6 maxkatz6 enabled auto-merge January 4, 2023 21:42
@maxkatz6 maxkatz6 merged commit 228f26f into AvaloniaUI:master Jan 4, 2023
@avaloniaui-team
Copy link
Contributor

You can test this PR using the following package version. 11.0.999-cibuild0028147-beta. (feed url: https://pkgs.dev.azure.com/AvaloniaUI/AvaloniaUI/_packaging/avalonia-all/nuget/v3/index.json) [PRBUILDID]

@workgroupengineering workgroupengineering deleted the features/NetAnalyzers/CA2211 branch January 5, 2023 00:30
@workgroupengineering workgroupengineering mentioned this pull request Jan 5, 2023
33 tasks
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.

4 participants