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.
Style code quality
Recipe ID
OpenRewrite.Recipes.CSharp.CodeQuality.Style.StyleCodeQualityArtifact
OpenRewrite.Recipes.CSharp.CodeQualityDefinition
Recipes167
167 recipes
- Use EventArgs.Empty
- Place constant values on right side of comparisons
- Use string.Length instead of comparison with empty string
- Use pattern matching for null check
- Use string.IsNullOrEmpty method
- Use string.Contains instead of IndexOf comparison
- Simplify boolean logic with constants
- Prefer null check over type check
- Use explicit type instead of var
- Use method group conversion
- Use collection expression
- Use file-scoped namespace
- Use primary constructor
- Make class sealed
- Make field read-only
- Use auto property
- Mark local variable as const
- Use read-only auto property
- Default label should be last
- Make class static
- Avoid nested ternary operator
- Use element access
- Sort enum members
- Abstract type should not have public constructors
- Declare each attribute separately
- Use method chaining
- Use using declaration
- Avoid chain of assignments
- Implement exception constructors
- Use AttributeUsageAttribute
- Value type is never equal to null
- Split variable declaration
- Remove unused parameter
- Remove unused type parameter
- Parameter name differs from base
- Use constant instead of field
- Call extension method as instance method
- Order named arguments by parameters
- Order type parameter constraints
- Flag duplicate enum value
- Use EventHandler<T>
- Declare enum value as combination of names
- Add static modifier to all members of static class
- Normalize format of enum flag value
- Use coalesce expression
- Declare enum member with zero value
- Use async/await when necessary
- Implement non-generic counterpart
- Fix invalid argument null check
- Use enum field explicitly
- Use var instead of explicit type in foreach
- Use explicitly typed array
- Add parentheses to conditional expression condition
- Declare each type in separate file
- Declare using directive on top level
- Add parentheses for clarity
- Composite enum value contains undefined flag
- Static member in generic type should use a type parameter
- Convert comment to documentation comment
- Overriding member should not change 'params' modifier
- Merge preprocessor directives
- Mark type with DebuggerDisplay attribute
- Make method an extension method
- Duplicate word in a comment
- Use EventArgs.Empty instead of null
- Use 'this' for event sender
- Find missing string equality comparer
- Obsolete attribute should include explanation
- Do not raise reserved exception types
- Do not throw from finally block
- Embed caught exception as inner exception
- Do not raise ApplicationException
- Types should not extend ApplicationException
- Do not use ThreadStatic on instance fields
- Do not use dangerous threading methods
- Do not write custom certificate validation
- Do not use anonymous delegates to unsubscribe from events
- Use System.Threading.Lock instead of object for locking
- ArgumentException should specify argument name
- Do not throw NotImplementedException
- Use OperatingSystem methods instead of RuntimeInformation
- Non-constant static fields should not be visible
- Find class with Equals(T) but no IEquatable<T>
- Find non-deterministic end-of-line in strings
- Parenthesize not pattern for clarity
- Find overrides that change parameter defaults
- Find boolean literal arguments without parameter name
- Find redundant default argument values
- Find ILogger<T> type parameter mismatch
- Find multi-line XML doc comments
- Use 'var' or explicit type
- Find binary expression with identical sides
- Find throw statements in finalizer
- Find async void delegate
- Find unawaited task return in using block
- Find CompareTo without IComparable
- Find [DefaultParameterValue] without [Optional]
- Find virtual method call in constructor
- Find comparison with NaN
- Find type with BCL name
- Find static members on generic types
- Find overwritten parameter values
- Find EqualityComparer<string>.Default
- Find ToString on object-typed parameter
- Find string.GetHashCode() usage
- Find Equals without [NotNullWhen(true)]
- Find event raised with null EventArgs
- Find await foreach without CancellationToken
- Find IComparable without comparison operators
- Find IComparable<T> without IEquatable<T>
- Find IEquatable<T> without Equals(object) override
- Find implicit culture-sensitive ToString in concatenation
- Find implicit DateTime to DateTimeOffset conversion
- Find interpolated string without parameters
- Find potentially invalid attribute argument type
- Find method that is too long
- Find async call missing CancellationToken
- Add trailing comma
- Find override method missing params keyword
- Find string method missing StringComparison
- Find non-flags enum with [Flags]
- Find unobserved async call result
- Find concrete collection in public API
- Find raw string with implicit end of line
- Find static event with non-null sender
- Find unawaited task in using statement
- Find ThrowIfNull with value type argument
- Find type name matching namespace
- Find DateTime.Now/UtcNow usage
- Find [DefaultValue] on parameter
- Find == comparison that should use Equals()
- Find integer 0 used instead of named enum value
- Find Parse/ToString without IFormatProvider
- Find Interlocked.CompareExchange lazy init pattern
- Find boolean literal argument without name
- Find Process.Start with string argument
- Find Regex without ExplicitCapture option
- Find redirect without UseShellExecute=false
- Find ProcessStartInfo without UseShellExecute
- Find Dictionary/HashSet without StringComparer
- Find 'is' pattern with string literal
- Find double await pattern
- Find custom time abstraction
- Find argument validation in iterator method
- Find ElementAt() that could use indexer
- Find implicit record class declaration
- Find if/else with identical branches
- Find equality operator on Span<T>
- Find struct member that could be readonly
- Find FormattableString usage
- Find reassigned primary constructor parameter
- Find missing langword in XML comment
- Find multi-line XML doc comment style
- Find non-constant string.Format format string
- Find explicit zero initialization in enum
- Find Parse/TryParse without IFormatProvider
- Find redundant nameof with CallerArgumentExpression
- Find async void method
- Find IAsyncEnumerable method without Async suffix
- Find ToString override without DebuggerDisplay
- Find null passed for CancellationToken
- Find missing NotNullIfNotNull attribute
- Find Stream.Read() return value ignored
- Find Thread.Sleep usage
- Find GetType() on Type instance
- Find missing non-generic interface implementation
- Find collection emptiness check
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.Style.StyleCodeQuality