Skip to content

.NET 8 developers can verify more APIs for correct usage to speed up their development #78442

@buyaa-n

Description

@buyaa-n

With the Roslyn Analyzers we built in .NET 5, 6 and 7, we've found that developers benefit from analyzers that verify correct usage of .NET Libraries APIs. We plan to put more effort on adding valuable analyzers in .NET 8, we will continue working with the community to foster contributions into our collection of analyzers and code fixers.

Community contributors: If you'd like to work on one of the issues marked as "up for grabs", please add a comment directly on that issue asking to get it assigned to you. Please check the getting started guide for reference about how to start and what's need to be done.

Analyzers Planned for .NET 8

Approved analyzers

No Status Issue Estimate
1 ✔️ by @CollinAlpert Prefer Dictionary<K, V>.TryAddValue(key) over guarded Add(key) Medium
2 ✔️ by @CollinAlpert Prefer .Length/Count/IsEmpty over Any() Medium
3 ✔️ by @fowl2 Do not use OfType() with impossible types Small
4 ✔️ by @steveberdy Extract array of const to static readonly field Medium
5 in PR by @psxvoid Constructor parameters should match property names Medium
6 in PR by @NewellClark Prevent wrong usage of string Split Medium
7 in PR by @NewellClark Prefer static ReadOnlySpan properties over static readonly byte[] fields Medium
8 in PR by @NewellClark Do not pass Utf8JsonReader by value Medium
9 ✔️ @geeknoid Recommend use of concrete types to maximize devirtualization potential Medium
10 ✔️ @stephentoub Convert argument null checks to ArgumentNullException.ThrowIfNull Medium
11 ✔️ @Youssef1313 Using StartsWith instead of IndexOf == 0 Medium
12 @NewellClark Avoid implicitly allocating params arrays in loops Medium
13 ✔️ @carlossanlop Recommend string.ToLower{Invariant}().Contains/IndexOf/StartsWith("lowercasestring") be replaced by case-insensitive comparison Medium
14 up for grabs Usage of ToString in logging source generator method call sites Medium
15 ✔️ @carlossanlop string.ToLower() == otherString.ToLower() Small
16 ✔️ @mrahhal Recommend string.StartsWith('c') instead of string.StartsWith("c") Medium
17 up for grabs Replacing direct LoggerExtensions.Log* usage with source-generated logging methods Medium
18 up for grabs Prefer ValueTuple over Tuple Medium
19 ✔️ @mpidash Report inefficient use of sets Small
20 up for grabs Introduce an analyzer to recommend the more efficient string splitting features in .NET 8 Medium
21 partially implemented @stephentoub Recommend upgrading to CompositeFormat for enhanced performance Large
22 up for grabs Prefer Dictionary.Remove(key, out value) over Dictionary.this[key], followed by Dictionary.Remove(key) Medium
23 up for grabs Hide Thread.VolatileRead and Thread.VolatileWrite Medium
24 in PR by @mpidash Simplify calls to string.Substring and Memory/Span.Slice Small
25 @mpidash Detect the problem of using a System.Type overload instead of the generic overload Medium
26 up for grabs Treat calls to ROS op_Equality as warning Small
27 up for grabs Detect non-cancelable Task.Delay passed to Task.WhenAny Medium
28 @tannergooding Upgrade from platform specific to cross platform intrinsics Small
29 @tannergooding Suggest more optimal SIMD patterns where applicable Medium
30 up for grabs Adjust/simplify code for numeric IntPtr Medium
31 up for grabs Analyzer/fixer for converting Stream.Read calls to ReadAtLeast and ReadExactly Medium
32 up for grabs Exceptions thrown inside async methods should be wrapped by Task.FromException Medium
33 @CollinAlpert Make types declared in an executable internal Small
34 up for grabs Unawaited / returned tasks created with a disposable in using block for that disposable Large
35 @pedrodeandrade Async methods that don't take a CancellationToken Small
36 up for grabs Use IndexOfAnyValues instead of inlined or cached array Small
37 ✔️ @jozkee Add an analyzer that warns on single-use JsonSerializerOptions instances

Other analyzer proposals that need to be prepared for API review

  1. Add [CallerMustBeUnsafe] attribute to denote APIs which should be called in an unsafe block #31354
  2. Warn about ArrayPool.Return without clearArray specified when T is not a value type or has references #71698
  3. Roslyn analyzer/fixer: Simplify invocations that receive a start/offset and a count/length #35981
  4. Analyzer proposal: EventSource log argument guarding #45215
  5. NonCopyable structs attribute and analyzer #50389
  6. Analyzer: Validate literal arguments to StringSyntaxAttribute parameters/members #64009
  7. Add analyzer for StringBuilder[int] indexer #64545
  8. [Analyzer]: Regex analyzers #68962
  9. Warnings for in/readonly ref #77625
  10. [Analyzer] Lift arrays of literals to static fields #78398

CC @stephentoub @jeffhandley @ericstj @carlossanlop

Metadata

Metadata

Assignees

Labels

User StoryA single user-facing feature. Can be grouped under an epic.area-Meta

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions