Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add CA1514: Remove redundant length argument#6814

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
buyaa-n merged 7 commits intodotnet:mainfrommpidash:issue-68946
Sep 22, 2023

Conversation

@mpidash
Copy link

Fixesdotnet/runtime#68946.

This analyzer detects uses ofSubstring/Slice(start, length) that slice to the end of the buffer.
In these cases, the length check is redundant, can be omitted, and the call can be replaced withSubstring/Slice(start).
The analyzer also detects if the evaluation of the instance or arguments can lead to side effects and does not flag these cases.

I have found no warning when running the analyzer againstdotnet/runtime anddotnet/roslyn-analyzers, 1 warning indotnet/roslyn and 8 warnings indotnet/aspnetcore:

  1. ContainedLanguageCodeSupport.cs(427,38): info CA1514: 'string.Substring(int, int)' uses a length check that can be avoided
  2. EmbeddedFileProvider.cs(95,23): info CA1514: 'string.Substring(int, int)' uses a length check that can be avoided
  3. RoutePatternParserTests.cs(112,17): info CA1514: 'string.Substring(int, int)' uses a length check that can be avoided
  4. MultipartReader.cs(124,25): info CA1514: 'string.Substring(int, int)' uses a length check that can be avoided
  5. AsciiDecoding.cs(108,78): info CA1514: 'System.Span.Slice(int, int)' uses a length check that can be avoided
  6. AsciiDecoding.cs(109,75): info CA1514: 'string.Substring(int, int)' uses a length check that can be avoided
  7. Program.cs(465,69): info CA1514: 'string.Substring(int, int)' uses a length check that can be avoided
  8. Utf8BufferTextWriter.cs(199,23): info CA1514: 'System.Memory.Slice(int, int)' uses a length check that can be avoided
  9. Utf8BufferTextWriterTests.cs(381,20): info CA1514: 'System.Memory.Slice(int, int)' uses a length check that can be avoided

Not sure about the resource strings, would appreciate any suggestions.

This analyzer detects uses of Substring/Slice(start, length) that sliceto the end of the buffer. In these cases, the length check is redundant,can be omitted, and the call can be replaced withSubstring/Slice(start). The analyzer also detects if the evaluation ofthe instance or arguments can lead to side effects and does not flagthese cases.
@mpidashmpidash requested a review froma team as acode ownerJuly 28, 2023 00:21
@codecov
Copy link

codecovbot commentedJul 28, 2023
edited
Loading

Codecov Report

Merging#6814 (9164b28) intomain (4aefee9) willdecrease coverage by0.03%.
The diff coverage is97.25%.

❗ Current head9164b28 differs from pull request most recent headfa03bad. Consider uploading reports for the commitfa03bad to get more accurate results

@@            Coverage Diff             @@##             main    #6814      +/-   ##==========================================- Coverage   96.42%   96.39%   -0.03%==========================================  Files        1398     1406       +8       Lines      333552   332375    -1177       Branches    11038    10923     -115     ==========================================- Hits       321624   320408    -1216- Misses       9165     9212      +47+ Partials     2763     2755       -8

Copy link

@buyaa-nbuyaa-n left a comment

Choose a reason for hiding this comment

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

Thanks you@mpidash, left a few comments, overall LGTM

mpidash reacted with heart emoji
@buyaa-n
Copy link

I have found no warning when running the analyzer againstdotnet/runtime anddotnet/roslyn-analyzers, 1 warning indotnet/roslyn and 8 warnings indotnet/aspnetcore:

Thanks for broad testing, all looks valid and worth fixing.

mpidashand others added4 commitsSeptember 22, 2023 19:31
Co-authored-by: Buyaa Namnan <buyankhishig.namnan@microsoft.com>
Also use the new code fix title for the fixer and rerun msbuild pack.
@mpidash
Copy link
Author

Thanks for the review@buyaa-n, I've addressed your review, merged main, and rerunmsbuild pack, PTAL :)

buyaa-n reacted with thumbs up emoji

@mpidash
Copy link
Author

Seems likemsbuild pack does not add a trailing newline toAnalyzerReleases.Unshipped.md, I've added it manually.

@buyaa-nbuyaa-nenabled auto-merge (squash)September 22, 2023 20:45
@buyaa-nbuyaa-n merged commit39ccb5b intodotnet:mainSep 22, 2023
@mpidashmpidash deleted the issue-68946 branchSeptember 23, 2023 12:48
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

1 more reviewer

@buyaa-nbuyaa-nbuyaa-n approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[Analyzer proposal]: Simplify calls to string.Substring and Memory/Span.Slice

2 participants

@mpidash@buyaa-n

[8]ページ先頭

©2009-2025 Movatter.jp