- Notifications
You must be signed in to change notification settings - Fork481
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
Uh oh!
There was an error while loading.Please reload this page.
Conversation
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.
codecovbot commentedJul 28, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Codecov Report
@@ 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 |
buyaa-n left a comment
There was a problem hiding this 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
...sts/Microsoft.CodeQuality.Analyzers/Maintainability/AvoidLengthCheckWhenSlicingToEndTests.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
...re/Microsoft.CodeQuality.Analyzers/Maintainability/AvoidLengthCheckWhenSlicingToEnd.Fixer.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
...etAnalyzers/Core/Microsoft.CodeQuality.Analyzers/MicrosoftCodeQualityAnalyzersResources.resx OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
...etAnalyzers/Core/Microsoft.CodeQuality.Analyzers/MicrosoftCodeQualityAnalyzersResources.resx OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
...ers/Core/Microsoft.CodeQuality.Analyzers/Maintainability/AvoidLengthCheckWhenSlicingToEnd.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
buyaa-n commentedSep 21, 2023
Thanks for broad testing, all looks valid and worth fixing. |
Co-authored-by: Buyaa Namnan <buyankhishig.namnan@microsoft.com>
Also use the new code fix title for the fixer and rerun msbuild pack.
mpidash commentedSep 22, 2023
Thanks for the review@buyaa-n, I've addressed your review, merged main, and rerun |
mpidash commentedSep 22, 2023
Seems like |
Fixesdotnet/runtime#68946.
This analyzer detects uses of
Substring/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 with
Substring/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 against
dotnet/runtimeanddotnet/roslyn-analyzers, 1 warning indotnet/roslynand 8 warnings indotnet/aspnetcore:Not sure about the resource strings, would appreciate any suggestions.