Style code quality

Proprietary

Code style modernization recipes for C#.

OpenRewrite.Recipes.CSharp.CodeQuality.Style.StyleCodeQuality
mod run . --recipe=OpenRewrite.Recipes.CSharp.CodeQuality.Style.StyleCodeQuality

Install it once, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.

Recipe list

It runs these recipes, in this order.

  1. Use EventArgs.Empty
  2. Place constant values on right side of comparisons
  3. Use string.Length instead of comparison with empty string
  4. Use pattern matching for null check
  5. Use string.IsNullOrEmpty method
  6. Use string.Contains instead of IndexOf comparison
  7. Simplify boolean logic with constants
  8. Prefer null check over type check
  9. Use explicit type instead of var
  10. Use method group conversion
  11. Use collection expression
  12. Use file-scoped namespace
  13. Use primary constructor
  14. Make class sealed
  15. Make field read-only
  16. Use auto property
  17. Mark local variable as const
  18. Use read-only auto property
  19. Default label should be last
  20. Make class static
  21. Avoid nested ternary operator
  22. Use element access
  23. Sort enum members
  24. Abstract type should not have public constructors
  25. Declare each attribute separately
  26. Use method chaining
  27. Use using declaration
  28. Avoid chain of assignments
  29. Implement exception constructors
  30. Use AttributeUsageAttribute
  31. Value type is never equal to null
  32. Split variable declaration
  33. Remove unused parameter
  34. Remove unused type parameter
  35. Parameter name differs from base
  36. Use constant instead of field
  37. Call extension method as instance method
  38. Order named arguments by parameters
  39. Order type parameter constraints
  40. Flag duplicate enum value
  41. Use EventHandler<T>
  42. Declare enum value as combination of names
  43. Add static modifier to all members of static class
  44. Normalize format of enum flag value
  45. Use coalesce expression
  46. Declare enum member with zero value
  47. Use async/await when necessary
  48. Implement non-generic counterpart
  49. Fix invalid argument null check
  50. Use enum field explicitly
  51. Use var instead of explicit type in foreach
  52. Use explicitly typed array
  53. Add parentheses to conditional expression condition
  54. Declare each type in separate file
  55. Declare using directive on top level
  56. Add parentheses for clarity
  57. Composite enum value contains undefined flag
  58. Static member in generic type should use a type parameter
  59. Convert comment to documentation comment
  60. Overriding member should not change 'params' modifier
  61. Merge preprocessor directives
  62. Mark type with DebuggerDisplay attribute
  63. Make method an extension method
  64. Duplicate word in a comment
  65. Use EventArgs.Empty instead of null
  66. Use 'this' for event sender
  67. Find missing string equality comparer
  68. Obsolete attribute should include explanation
  69. Do not raise reserved exception types
  70. Do not throw from finally block
  71. Embed caught exception as inner exception
  72. Do not raise ApplicationException
  73. Types should not extend ApplicationException
  74. Do not use ThreadStatic on instance fields
  75. Do not use dangerous threading methods
  76. Do not write custom certificate validation
  77. Do not use anonymous delegates to unsubscribe from events
  78. Use System.Threading.Lock instead of object for locking
  79. ArgumentException should specify argument name
  80. Do not throw NotImplementedException
  81. Use OperatingSystem methods instead of RuntimeInformation
  82. Non-constant static fields should not be visible
  83. Find class with Equals(T) but no IEquatable<T>
  84. Find non-deterministic end-of-line in strings
  85. Parenthesize not pattern for clarity
  86. Find overrides that change parameter defaults
  87. Find boolean literal arguments without parameter name
  88. Find redundant default argument values
  89. Find ILogger<T> type parameter mismatch
  90. Find multi-line XML doc comments
  91. Use 'var' or explicit type
  92. Find binary expression with identical sides
  93. Find throw statements in finalizer
  94. Find async void delegate
  95. Find unawaited task return in using block
  96. Find CompareTo without IComparable
  97. Find [DefaultParameterValue] without [Optional]
  98. Find virtual method call in constructor
  99. Find comparison with NaN
  100. Find type with BCL name
  101. Find static members on generic types
  102. Find overwritten parameter values
  103. Find EqualityComparer<string>.Default
  104. Find ToString on object-typed parameter
  105. Find string.GetHashCode() usage
  106. Find Equals without [NotNullWhen(true)]
  107. Find event raised with null EventArgs
  108. Find await foreach without CancellationToken
  109. Find IComparable without comparison operators
  110. Find IComparable<T> without IEquatable<T>
  111. Find IEquatable<T> without Equals(object) override
  112. Find implicit culture-sensitive ToString in concatenation
  113. Find implicit DateTime to DateTimeOffset conversion
  114. Find interpolated string without parameters
  115. Find potentially invalid attribute argument type
  116. Find method that is too long
  117. Find async call missing CancellationToken
  118. Add trailing comma
  119. Find override method missing params keyword
  120. Find string method missing StringComparison
  121. Find non-flags enum with [Flags]
  122. Find unobserved async call result
  123. Find concrete collection in public API
  124. Find raw string with implicit end of line
  125. Find static event with non-null sender
  126. Find unawaited task in using statement
  127. Find ThrowIfNull with value type argument
  128. Find type name matching namespace
  129. Find DateTime.Now/UtcNow usage
  130. Find [DefaultValue] on parameter
  131. Find == comparison that should use Equals()
  132. Find integer 0 used instead of named enum value
  133. Find Parse/ToString without IFormatProvider
  134. Find Interlocked.CompareExchange lazy init pattern
  135. Find boolean literal argument without name
  136. Find Process.Start with string argument
  137. Find Regex without ExplicitCapture option
  138. Find redirect without UseShellExecute=false
  139. Find ProcessStartInfo without UseShellExecute
  140. Find Dictionary/HashSet without StringComparer
  141. Find 'is' pattern with string literal
  142. Find double await pattern
  143. Find custom time abstraction
  144. Find argument validation in iterator method
  145. Find ElementAt() that could use indexer
  146. Find implicit record class declaration
  147. Find if/else with identical branches
  148. Find equality operator on Span<T>
  149. Find struct member that could be readonly
  150. Find FormattableString usage
  151. Find reassigned primary constructor parameter
  152. Find missing langword in XML comment
  153. Find multi-line XML doc comment style
  154. Find non-constant string.Format format string
  155. Find explicit zero initialization in enum
  156. Find Parse/TryParse without IFormatProvider
  157. Find redundant nameof with CallerArgumentExpression
  158. Find async void method
  159. Find IAsyncEnumerable method without Async suffix
  160. Find ToString override without DebuggerDisplay
  161. Find null passed for CancellationToken
  162. Find missing NotNullIfNotNull attribute
  163. Find Stream.Read() return value ignored
  164. Find Thread.Sleep usage
  165. Find GetType() on Type instance
  166. Find missing non-generic interface implementation
  167. Find collection emptiness check