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

CA1861: Do not warn if not an array initializer. #6714

Merged
merged 1 commit into from
Jun 30, 2023

Conversation

buyaa-n
Copy link
Contributor

@buyaa-n buyaa-n commented Jun 26, 2023

CA1861: Avoid constant arrays as arguments analyzer should not warn when the array creation has no array initializer.

Fixes #6697
Related to dotnet/runtime#87768 (comment)

@buyaa-n buyaa-n requested a review from a team as a code owner June 26, 2023 22:44
@codecov
Copy link

codecov bot commented Jun 26, 2023

Codecov Report

Merging #6714 (340f69d) into main (f4cc17e) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6714   +/-   ##
=======================================
  Coverage   96.36%   96.37%           
=======================================
  Files        1390     1390           
  Lines      324039   324042    +3     
  Branches    10613    10613           
=======================================
+ Hits       312274   312287   +13     
+ Misses       9224     9214   -10     
  Partials     2541     2541           

public List<object> Cases => new() { {|CA1861:new object[0]|} };
}";
var fixedSource = @"using System.Collections.Generic;
public List<object> Cases => new() { new object[0] };
Copy link
Member

Choose a reason for hiding this comment

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

This should trigger CA1825 (https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1825). Do we know why it doesn't?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it is expected for unit testing, I did not see any unrelated diagnostics triggered in unit testing except compiler warnings. By my understanding the unit tests only trigger the diagnostics related to:

using VerifyCS = Test.Utilities.CSharpCodeFixVerifier<
Microsoft.NetCore.Analyzers.Runtime.AvoidConstArraysAnalyzer,

In normal case the CA1825 is being triggered:
image

@buyaa-n buyaa-n merged commit 1ac6c1c into dotnet:main Jun 30, 2023
@buyaa-n buyaa-n deleted the donot_warn branch June 30, 2023 16:42
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.

Review code fixer for CA1861 (Avoid constant arrays)
3 participants