-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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 CA1852: Seal internal types #8389
Conversation
We can possibly exclude the analyzers for those classes using globbing in |
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'd prefer two commits: one for dotnet format
to do the usings, then add the sealed
rule and rerun. But I won't block on it.
8b514b9
to
f489deb
Compare
That's very reasonable and easy to do. I have force-pushed an update with 2 commits. The overall diff is identical to the initial commit. |
f489deb
to
ba932c1
Compare
This is already kind of working via the ProjectIsDeprecated prop. Without it build would be failing in the Deprecated directory unless we catch up with all the severity=warning rules there. It's just that |
VS auto-fixes are not respecting it either (but it's also easy to revert those changes). |
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.
Thanks!
Out of scope and stupid question (given by lack of detailed knowledge of analyzers and dotnet format
) - should running of dotnet format
guarantee that ones changes are properly adhering to the preconfigured rules (.editorconfig
)? Or at least those that can be automatically fixed?
If that's the case should dotnet format
be strongly suggested as a pre-commit step (alonmg with e.g. build.cmd -test
)? Or is there any downside (e.g. any possibly unwanted automatic reformatting)?
I'm just thinking whether we should add this step (and other specific steps - like the build.cmd -test
) to our contributing guide
ba932c1
to
6951eec
Compare
Apologies for not responding earlier. My understanding is that we allow rules to be configured as "suggestion", meaning that we don't enforce them, we just slightly prefer them to be followed. If |
Context
Types that are not designed to be inherited from should be sealed. This is general defensive goodness, and also has perf implications because it enables some runtime/JIT optimizations. A new analyzer was recently added for this.
Changes Made
Enabled the analyzer and fixed the code with
dotnet format
.Testing
Manual review of the changes.
Notes
dotnet format
also rectified our namespace imports. I don't believe there's any controversy in that and the change is low risk so I left it in. For the actual sealing:InternalsVisibleTo
, by design. This is not causing any issues for us now as we don't derive from internal types in other assemblies. OurInternalsVisibleTo
all point to our own assemblies built in this repo so this is a non-breaking change (unless hacks, reflection, etc. but the bar is certainly not that high).src/Deprecated
in this PR.