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

Add CollectionExpression support to CA1870 (UseSearchValues) #7252

Merged
merged 2 commits into from
Apr 3, 2024

Conversation

MihaZupan
Copy link
Member

Followup after #6898 to add recognition for collection expression patterns as well.

Currently, if you write something like

private static readonly char[] s_chars = new[] { 'a', 'e', 'i', 'o', 'u', 'A' };
public static int Test(ReadOnlySpan<char> s) => s.IndexOfAny(s_chars);

you will be offered two fixers: one to replace s_chars with SearchValues.Create("aeiouA"), and the other to replace the array creation with ['a', 'e', 'i', 'o', 'u', 'A'].
If you accept the latter, you won't be offered the SearchValues fixer anymore since we don't recognize the pattern.

This PR adds recognition for patterns like

static readonly char[] s_chars = ['a', 'e', 'i', 'o', 'u', 'A'];

text.IndexOfAny(['a', 'e', 'i', 'o', 'u', 'A']);
text.IndexOfAny([(byte)'a', (byte)'e', (byte)'i', (byte)'o', (byte)'u', (byte)'A']);
text.IndexOfAny(s_chars);

@MihaZupan MihaZupan requested a review from a team as a code owner March 19, 2024 21:39
@MihaZupan
Copy link
Member Author

cc: @stephentoub

Copy link

codecov bot commented Mar 19, 2024

Codecov Report

Attention: Patch coverage is 86.82171% with 17 lines in your changes are missing coverage. Please review.

Project coverage is 96.47%. Comparing base (de3a920) to head (3692f88).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##             main    #7252     +/-   ##
=========================================
  Coverage   96.47%   96.47%             
=========================================
  Files        1436     1440      +4     
  Lines      342881   344487   +1606     
  Branches    11292    11340     +48     
=========================================
+ Hits       330797   332356   +1559     
- Misses       9230     9262     +32     
- Partials     2854     2869     +15     

@MihaZupan
Copy link
Member Author

@dotnet/roslyn-analysis who would be the right person to review this one?

Copy link
Contributor

@buyaa-n buyaa-n left a comment

Choose a reason for hiding this comment

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

LGTM, I will let @CyrusNajmabadi take another look

Copy link
Member

@CyrusNajmabadi CyrusNajmabadi left a comment

Choose a reason for hiding this comment

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

Looks reasonable to me :-)

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.

3 participants