Skip to content

Add CA 2021 into CodeAnalysis config#82649

Merged
buyaa-n merged 1 commit into
dotnet:mainfrom
buyaa-n:ca2021
Feb 25, 2023
Merged

Add CA 2021 into CodeAnalysis config#82649
buyaa-n merged 1 commit into
dotnet:mainfrom
buyaa-n:ca2021

Conversation

@buyaa-n

@buyaa-n buyaa-n commented Feb 24, 2023

Copy link
Copy Markdown
Contributor

CA2021: Do not call Enumerable.Cast<T> or Enumerable.OfType<T> with incompatible types is a new analyzer that added in January.

Because it is Warns by default it caused build failure on automation PR that updates analyzer feed which caused by some edge case scenario bug.

Because the bug could cause a failure in other repos we lowered the severity of the analyzer until those bugs get fixed. Now the fix is ready for merge which also upgrades the severity into Warning back, we need to turn off the analyzer on test projects before merge because it would cause a warning for valid scenarios like:

Assert.Throws<InvalidCastException>(() => { foreach (var t in rst) ; });
and
int[] source = { 99, 45, 81 };
Assert.Empty(source.OfType<long>());

@buyaa-n buyaa-n requested a review from stephentoub February 24, 2023 22:48
@ghost ghost assigned buyaa-n Feb 24, 2023
@ghost

ghost commented Feb 24, 2023

Copy link
Copy Markdown

Tagging subscribers to this area: @dotnet/area-meta
See info in area-owners.md if you want to be subscribed.

Issue Details

CA2021: Do not call Enumerable.Cast<T> or Enumerable.OfType<T> with incompatible types is a new analyzer that added in January.

Because it is Warns by default it caused build failure on automation PR that updates analyzer feed which caused by some edge case scenario bug.

Because the bug could cause a failure in other repos we lowered the severity of the analyzer until those bugs get fixed. Now the fix is ready for merge which also upgrades the severity into Warning back, we need to turn off the analyzer on test projects before merge because it would cause a warning for valid scenarios like:

Assert.Throws<InvalidCastException>(() => { foreach (var t in rst) ; });
and
int[] source = { 99, 45, 81 };
Assert.Empty(source.OfType<long>());

Author: buyaa-n
Assignees: -
Labels:

area-Meta

Milestone: -

@stephentoub stephentoub left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM if CI is green

@buyaa-n

buyaa-n commented Feb 25, 2023

Copy link
Copy Markdown
Contributor Author

The only failure is unrelated and known

@buyaa-n buyaa-n merged commit e26e33f into dotnet:main Feb 25, 2023
@buyaa-n buyaa-n deleted the ca2021 branch February 25, 2023 01:25
@ghost ghost locked as resolved and limited conversation to collaborators Mar 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants