Moderne OnlyThis recipe is proprietary to Moderne and runs on the Moderne platform or CLI — it isn’t part of the open-source catalog. Available with a Moderne subscription.
Performance code quality
Recipe ID
OpenRewrite.Recipes.CSharp.CodeQuality.Performance.PerformanceCodeQualityArtifact
OpenRewrite.Recipes.CSharp.CodeQualityDefinition
Recipes54
54 recipes
- Avoid boxing of value type
- Use StringComparison
- Avoid locking on publicly accessible instance
- Use StringBuilder.AppendLine
- Use Array.Empty<T>() instead of new T[0]
- Return completed task instead of null
- Use Count/Length property instead of Count()
- Use Regex.IsMatch
- Use string.Concat instead of string.Join
- Bitwise operation on enum without Flags attribute
- Make parameter ref read-only
- Avoid NullReferenceException
- Remove unnecessary explicit enumerator
- Throwing of new NotImplementedException
- Optimize method call
- Do not pass non-read-only struct by read-only reference
- Replace Enum.ToString() with nameof
- Optimize StringBuilder.Append usage
- Find blocking calls in async methods
- Find methods not forwarding CancellationToken
- Find implicit culture-sensitive string methods
- Find implicit culture-sensitive ToString calls
- Find LINQ methods replaceable with direct methods
- Find missing WithCancellation on async enumerables
- Do not use async void
- Do not use NaN in comparisons
- Add timeout to Regex
- Do not use blocking calls on tasks
- Use ContainsKey instead of TryGetValue with discard
- String.Format format string should be constant
- Avoid closure when using ConcurrentDictionary
- Use RegexOptions.ExplicitCapture
- Do not use ToString on GetType result
- Find EqualityComparer<string>.Default usage
- Find string.GetHashCode() without StringComparer
- Use char overload for single-character string methods
- Find Regex that could use source generator
- Find FormattableString that could use string.Create
- Find GetCustomAttributes that could use Attribute.IsDefined
- Find Span<char> equality that should use SequenceEqual
- Find structs without StructLayout attribute
- Find methods that could be static
- Find Guid.Parse with constant string
- Find calls that could use TimeProvider
- Find simplifiable string.Create calls
- Find closure in GetOrAdd that could use factory argument
- Find GetType() called on System.Type
- Find LINQ Count() on materialized collection
- Find unused Stream.Read return value
- Find Dictionary/HashSet with struct key type
- Find LINQ methods replaceable with indexer
- Use ContainsKey instead of Keys.Contains
- Find Values.Contains() instead of ContainsValue()
- Find closure in GetOrAdd/AddOrUpdate factory
Usage
Run this recipe
In order to run C# recipes, you will need to use the Moderne CLI.
Once the CLI is installed, you can install this C# recipe package by running the following command:
Install the recipe package
mod config recipes nuget install OpenRewrite.Recipes.CSharp.CodeQuality
Then, you can run the recipe via:
Run the recipe
mod run . --recipe OpenRewrite.Recipes.CSharp.CodeQuality.Performance.PerformanceCodeQuality