Refactor to clean up CA1851 warnings#1892
Merged
twsouthwick merged 3 commits intomainfrom Mar 17, 2025
Merged
Conversation
There was a problem hiding this comment.
PR Overview
This PR refactors code to remove CA1851 warnings by replacing multiple enumerations of IEnumerable with a new extension method and removing suppression attributes.
- Introduced the FirstOrDefaultAndMaxOne extension method in EnumerableExtensions.cs
- Removed CA1851 suppression attributes and replaced enumerations with the new extension method in SemanticConstraint.cs and RelationshipTypeConstraint.cs
Reviewed Changes
| File | Description |
|---|---|
| src/DocumentFormat.OpenXml.Framework/EnumerableExtensions.cs | Added extension method to safely return the first (or default) element while ensuring at most one element exists. |
| src/DocumentFormat.OpenXml.Framework/Validation/Semantic/SemanticConstraint.cs | Removed a suppression attribute and refactored part lookup to use LINQ with FirstOrDefaultAndMaxOne. |
| src/DocumentFormat.OpenXml.Framework/Validation/Semantic/RelationshipTypeConstraint.cs | Removed a suppression attribute and refactored relationship lookup to use FirstOrDefaultAndMaxOne. |
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
Comments suppressed due to low confidence (3)
src/DocumentFormat.OpenXml.Framework/EnumerableExtensions.cs:15
- [nitpick] Consider renaming the parameter 'exThrow' to 'exceptionFactory' for improved clarity.
public static T? FirstOrDefaultAndMaxOne<T>(this IEnumerable<T> enumerable, Func<Exception>? exThrow = null)
src/DocumentFormat.OpenXml.Framework/EnumerableExtensions.cs:25
- [nitpick] The exception message may be improved for clarity; consider rephrasing it to better indicate that the enumerable contains more than one element.
throw exThrow?.Invoke() ?? throw new InvalidOperationException("Max of a single item should be in the enumerable");
src/DocumentFormat.OpenXml.Framework/Validation/Semantic/RelationshipTypeConstraint.cs:67
- [nitpick] Consider passing a custom exception factory lambda to FirstOrDefaultAndMaxOne to provide a more context-specific error message.
.FirstOrDefaultAndMaxOne();
mikeebowen
approved these changes
Mar 10, 2025
Test Results 70 files 70 suites 1h 8m 48s ⏱️ Results for commit 923a052. |
lindexi
reviewed
Mar 11, 2025
tomjebo
approved these changes
Mar 17, 2025
Member
Author
|
See #1899 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1325