Code Inspections in C#
In C#, JetBrains Rider 2017.2 provides two kinds of code inspections: 672 inspections that detect errors such as broken syntax, unresolved symbols, compiler errors, etc. (you cannot configure or disable any of these inspections), and 496 proprietary code inspections, any of which you can disable or change its severity level.
These code inspections help you detect code issues in design time in all open files, and additionally they allow you to find code issues in specific scope.
Configurable C# inspections are listed below, grouped in the following categories:
- Code Notification (1 inspection)
- Code Style (33 inspections)
- Common Practices and Code Improvements (134 inspections)
- Compiler Warnings (58 inspections)
- Constraints Violations (10 inspections)
- Language Usage Opportunities (33 inspections)
- NUnit (3 inspections)
- Potential Code Quality Issues (121 inspections)
- Redundancies in Code (62 inspections)
- Redundancies in Symbol Declarations (41 inspections)
Code Notification (1 inspection)
This category groups code inspections with minor severity levels.Inspection | Default Severity |
---|---|
Method invocation is skipped | Hint |
Code Style (33 inspections)
Inspections in this category detect violations of code style rules. In contrast to the rest of code inspections, these inspections can either detect the same code construct as a code issue or not depending on the corresponding code style rule configured in the pages of ReSharper options. You can also fix issues that these inspection detect, using code cleanup. For more information, see Code Style and Cleanup.Common Practices and Code Improvements (134 inspections)
This category groups inspections that hunt for medium severity issues that mainly affect code readability.Inspection | Default Severity |
---|---|
Access to a static member of a type via a derived type | Warning |
Annotation duplicate in hierarchy | Warning |
Auto-property can be made get-only (non-private accessibility) | Suggestion |
Auto-property can be made get-only (private accessibility) | Suggestion |
Base member has 'params' parameter, but overrider hasn't | Warning |
Check for reference equality instead | Suggestion |
Check for reference equality instead | Suggestion |
Class can be made sealed(non-inheritable) (non-private accessibility) | Disabled |
Class can be made sealed(non-inheritable) (private accessibility) | Disabled |
Container nullability attribute usage with declaration of non-container type | Warning |
Convert 'if do while' to 'while | Suggestion |
Convert 'if' to '||' | Suggestion |
Convert local variable or field to constant (non-private accessibility) | Hint |
Convert local variable or field to constant (private accessibility) | Hint |
Declaration nullability inferred (parameter is inferred to be not null) | Disabled |
Declaration nullability inferred (parameter is inferred to be nullable) | Disabled |
Declaration nullability inferred (type member is inferred to be not null) | Disabled |
Declaration nullability inferred (type member is inferred to be nullable) | Disabled |
Empty control statement body | Warning |
Empty statement is redundant | Warning |
Field can be made readonly (non-private accessibility) | Suggestion |
Field can be made readonly (private accessibility) | Suggestion |
Get-only auto-property is never assigned | Warning |
Invert condition | Hint |
Iteration variable can be declared with a more specific type | Suggestion |
Join local variable declaration and assignment | Suggestion |
Literal's length can be reduced by using verbatim string | Hint |
Local variable has too wide declaration scope | Suggestion |
Make constructor in abstract class protected | Suggestion |
Member can be made private (non-private accessibility) | Suggestion |
Member can be made private (private accessibility) | Suggestion |
Member can be made protected (non-private accessibility) | Suggestion |
Member can be made protected (private accessibility) | Suggestion |
Member can be made static(shared) (non-private accessibility) | Hint |
Member can be made static(shared) (private accessibility) | Hint |
Member or type can be made internal(friend) | Disabled |
Method supports cancellation | Suggestion |
Multiple nullable attributes usage | Warning |
Nested string interpolation can be inlined | Suggestion |
Nullability attribute usage with declaration of void or value type | Warning |
Parameter can be declared with base type | Hint |
Parameter type can be IEnumerable<T> (non-private accessibility) | Hint |
Parameter type can be IEnumerable<T> (private accessibility) | Hint |
Possible mistaken argument | Warning |
Possible mistaken call to GetType() | Warning |
Possible mistaken call to GetType() | Warning |
Remove constructor invocation | Disabled |
Remove redundant statement | Suggestion |
Remove redundant statement | Suggestion |
Remove ToList() | Suggestion |
Remove ToList() | Suggestion |
Replace with FirstOrDefault($args$) | Suggestion |
Replace with FirstOrDefault($args$) | Suggestion |
Replace with FirstOrDefault($args$) | Suggestion |
Replace with FirstOrDefault($args$) | Suggestion |
Replace with LastOrDefault($args$) | Suggestion |
Replace with LastOrDefault($args$) | Suggestion |
Replace with LastOrDefault($args$) | Suggestion |
Replace with LastOrDefault($args$) | Suggestion |
Replace with OfType<T>() | Suggestion |
Replace with OfType<T>() | Suggestion |
Replace with OfType<T>() | Suggestion |
Replace with OfType<T>().Any() | Suggestion |
Replace with OfType<T>().Any() (replace with OfType<T>().Any(..)) | Suggestion |
Replace with OfType<T>().Count() | Suggestion |
Replace with OfType<T>().Count() (replace with OfType<T>().Count(..)) | Suggestion |
Replace with OfType<T>().First() | Suggestion |
Replace with OfType<T>().First() (replace with OfType<T>().First(..)) | Suggestion |
Replace with OfType<T>().FirstOrDefault() | Suggestion |
Replace with OfType<T>().FirstOrDefault() (replace with OfType<T>().FirstOrDefault(..)) | Suggestion |
Replace with OfType<T>().Last() | Suggestion |
Replace with OfType<T>().Last() (replace with OfType<T>().Last(..)) | Suggestion |
Replace with OfType<T>().LastOrDefault() | Suggestion |
Replace with OfType<T>().LastOrDefault() (replace with OfType<T>().LastOrDefault(..)) | Suggestion |
Replace with OfType<T>().LongCount() | Suggestion |
Replace with OfType<T>().Single() | Suggestion |
Replace with OfType<T>().Single() (replace with OfType<T>().Single(..)) | Suggestion |
Replace with OfType<T>().SingleOrDefault() | Suggestion |
Replace with OfType<T>().SingleOrDefault() (replace with OfType<T>().SingleOrDefault(..)) | Suggestion |
Replace with OfType<T>().Where() (replace with OfType<T>().Where(..)) | Suggestion |
Replace with simple assignment | Suggestion |
Replace with simple assignment | Suggestion |
Replace with single assignment | Suggestion |
Replace with single assignment | Suggestion |
Replace with single call to Any(..) | Suggestion |
Replace with single call to Count(..) | Suggestion |
Replace with single call to First(..) | Suggestion |
Replace with single call to FirstOrDefault(..) | Suggestion |
Replace with single call to Last(..) | Suggestion |
Replace with single call to LastOrDefault(..) | Suggestion |
Replace with single call to Single(..) | Suggestion |
Replace with single call to SingleOrDefault(..) | Suggestion |
Replace with SingleOrDefault($args$) | Suggestion |
Replace with SingleOrDefault($args$) | Suggestion |
Replace with SingleOrDefault($args$) | Suggestion |
Replace with SingleOrDefault($args$) | Suggestion |
Return type can be IEnumerable<T> (non-private accessibility) | Hint |
Return type can be IEnumerable<T> (private accessibility) | Hint |
Simplify conditional ternary expression | Suggestion |
Simplify LINQ expression | Suggestion |
Simplify negative equality expression | Suggestion |
Specify string comparison explicitly | Hint |
Specify string culture explicitly | Warning |
String literal can be inlined | Suggestion |
String.Compare is culture-specific (string.Compare(string, int, string, int) is culture-specific) | Warning |
String.Compare is culture-specific (string.Compare(string, int, string, int, bool) is culture-specific) | Warning |
String.Compare is culture-specific (string.Compare(string, int, string, int, bool) is culture-specific) | Warning |
String.Compare is culture-specific (string.Compare(string, string) is culture-specific) | Warning |
String.Compare is culture-specific (string.Compare(string, string, bool) is culture-specific) | Warning |
String.Compare is culture-specific (string.Compare(string, string, bool) is culture-specific) | Warning |
String.CompareTo is culture-specific | Warning |
String.EndsWith is culture-specific (string.EndsWith(string) is culture-specific) | Disabled |
String.IndexOf is culture-specific (string.IndexOf(string) is culture-specific) | Warning |
String.IndexOf is culture-specific (string.IndexOf(string, int) is culture-specific) | Warning |
String.IndexOf is culture-specific (string.IndexOf(string, int) is culture-specific) | Warning |
String.LastIndexOf is culture-specific (string.LastIndexOf(string) is culture-specific) | Warning |
String.LastIndexOf is culture-specific (string.LastIndexOf(string, int) is culture-specific) | Warning |
String.LastIndexOf is culture-specific (string.LastIndexOf(string, int) is culture-specific) | Warning |
String.StartsWith is culture-specific (string.StartsWith(string) is culture-specific) | Disabled |
try-catch and try-finally statements can be merged | Hint |
Type parameter could be declared as covariant or contravariant | Suggestion |
Unreachable code detected | Warning |
Use array creation expression | Suggestion |
Use array creation expression | Suggestion |
Use indexed property | Suggestion |
Use 'is' operator | Suggestion |
Use 'is' operator | Suggestion |
Use method Any() | Suggestion |
Use method Any() | Suggestion |
Use method Any() | Suggestion |
Use method Any() | Suggestion |
Use method Any() | Suggestion |
Use method IsInstanceOfType(..) | Suggestion |
Use 'String.IsNullOrEmpty' | Suggestion |
Compiler Warnings (58 inspections)
Inspections in this section detect compiler warnings before you compile.Constraints Violations (10 inspections)
This category includes code inspections, mostly with the warning severity level, which detect violations related to symbol attributes, including JetBrains Rider's code annotations, and other similar issues.Inspection | Default Severity |
---|---|
Base type is required | Warning |
BaseTypeRequired attribute supports only classes and interfaces | Warning |
Compare with '==' types marked by 'CannotApplyEqualityOperatorAttribute' | Warning |
Inconsistent Naming | Warning |
Member with '[NotNull]' attribute is not initialized at constructor exit | Warning |
Namespace does not correspond to file location | Warning |
Possible 'null' assignment to entity with '[NotNull]' attribute | Warning |
Problem in contract annotation definition | Warning |
Required base type conflicting another type | Warning |
Type specified in '[BaseTypeRequired]' attribute conflicts another type | Warning |
Language Usage Opportunities (33 inspections)
This category includes code inspections, mostly with the suggestion severity level, which notify you when more advanced language constructs can be used. These inspections detect syntax of outdated language versions and suggest using features from more modern language versions. For most of the supported languages, language version can be detected automatically or set manually.NUnit (3 inspections)
These inspections detect code issues related to NUnit tests.Inspection | Default Severity |
---|---|
Make test method method public (nUnit Test methods should have public visibility) | Hint |
Remove parameters from test method (nUnit Test methods should not have parameters) | Disabled |
Remove return value from test method (nUnit Test methods should not return any value) | Disabled |
Potential Code Quality Issues (121 inspections)
This category includes inspections that detect critical issues (code smells), mostly with Error or Warning level. This category also includes inspections that ensure localization assistance.Inspection | Default Severity |
---|---|
'?:' expression has identical true and false branches | Warning |
[ThreadStatic] doesn't work with instance fields | Warning |
Abstract or virtual(overridable) event is never invoked | Suggestion |
Access to disposed closure | Warning |
Access to foreach variable in closure | Warning |
Access to modified closure | Warning |
Ambiguous symbols in text argument | Warning |
Annotation conflict in hierarchy | Warning |
Assignment in conditional expression | Warning |
Assignment to a property of a readonly field can be useless | Warning |
Auto-property accessor is never used (non-private accessibility) | Warning |
Auto-property accessor is never used (private accessibility) | Warning |
Bitwise operation on enum which is not marked by [Flags] attribute | Warning |
Call to base member with implicit default parameters | Warning |
Call to 'base.Equals(...)' is reference equality | Warning |
Cannot access static symbol in text argument | Warning |
Cannot access symbol in text argument | Warning |
Cannot resolve property | Error |
Cannot resolve resource | Error |
Cannot resolve resource item | Error |
Cannot resolve symbol in text argument | Warning |
Class is never instantiated (non-private accessibility) | Suggestion |
Class is never instantiated (private accessibility) | Suggestion |
Collection is never updated (non-private accessibility) | Warning |
Collection is never updated (private accessibility) | Warning |
Collection's content is never queried (non-private accessibility) | Warning |
Collection's content is never queried (private accessibility) | Warning |
Co-variant array conversion | Warning |
Delegate subtractions | Warning |
Element is localizable | Warning |
Empty general catch clause | Warning |
'Enumerable.Sum' invocation in explicit unchecked context | Warning |
Equality comparison of floating point numbers | Warning |
Event is never subscribed to (non-private accessibility) | Suggestion |
Event is never subscribed to (private accessibility) | Suggestion |
Event never invoked | Warning |
Event unsubscription via anonymous delegate | Warning |
Exception rethrow possibly intended | Warning |
Explicit argument passed to parameter with caller info attribute | Warning |
Formatting is specified, but interpolated string expression is not IFormattable | Warning |
Function body is too complex to analyze | Disabled |
Function is recursive on all execution paths | Warning |
Function never returns | Warning |
'GC.SuppressFinalize' is invoked for type without destructor | Warning |
Implicitly captured closure | Hint |
Impure method is called for readonly field of value type | Warning |
Inconsistent synchronization on field | Warning |
Instance of IEnumerator is never disposed | Warning |
Interfaces marked as ServiceContract should declare at least one OperationContract | Warning |
Invocation of polymorphic field-like event | Warning |
IQueryable is possibly unintentionally used as IEnumerable | Suggestion |
Iterator never returns | Warning |
Local variable hides member | Warning |
Loop control variable is never changed inside loop | Warning |
Member hides static member from outer class | Warning |
Member initialized value ignored | Warning |
Method is marked as OperationContract but containing type isn't marked as ServiceContract | Warning |
Method with optional or 'params' parameter is hidden by overload | Warning |
Method with 'params' is invoked while more specific method is available | Warning |
Mismatch optional parameter value in overridden method | Warning |
Multiple sequential 'OrderBy' invocation | Warning |
Non-accessed field (non-private accessibility) | Suggestion |
Non-accessed field (private accessibility) | Warning |
Non-readonly type member referenced in 'GetHashCode()' | Warning |
'Object.ReferenceEquals' is always false because it is called with value type | Warning |
One way operations couldn't return values | Warning |
Operator 'is'/'Type Of ... Is ...' can be used | Warning |
Overridden GetHashCode calls base 'Object.GetHashCode()' | Warning |
Parameter hides member | Warning |
Parameter name differs in partial method declaration | Warning |
Possible ambiguity while accessing member by interface | Warning |
Possible compare of value type with 'null' | Disabled |
Possible cyclic constructor call | Warning |
Possible incorrect implementation of Double-Check Locking pattern. Possible multiple write access to checked field | Warning |
Possible incorrect implementation of Double-Check Locking pattern. Read access to checked field | Warning |
Possible infinite inheritance | Warning |
Possible loss of fraction | Warning |
Possible multiple enumeration of IEnumerable | Warning |
Possible 'System.InvalidCastException' | Warning |
Possible 'System.InvalidCastException' in foreach loop | Warning |
Possible 'System.InvalidOperationException' | Warning |
Possible 'System.NullReferenceException' | Warning |
Possible unassigned object created by 'new' expression | Warning |
Possible unintended reference comparison | Warning |
Possibly misleading 'DefaultValueAttribute' usage to define optional parameter value | Warning |
Possibly missing comma before indexer initializer | Warning |
'ref' or 'out' parameter with [Optional] attribute | Warning |
Return value of [MustUseReturnValue] annotated method is not used | Warning |
Return value of iterator is not used | Warning |
Return value of pure method is not used | Warning |
Right operand of dynamic shift operation should be convertible to 'int' | Warning |
Safe cast expression always succeeds | Suggestion |
Similar anonymous type detected nearby | Hint |
Similar expressions comparison | Warning |
Some values of the enum are not processed inside switch statement | Hint |
Static field or auto-property in generic type | Warning |
Static member initializer refers to static member below or in other part | Warning |
String formatting method problems | Warning |
Suspicious type conversion or check | Warning |
Tail recursive call may be replaced with loop | Hint |
The given expression of 'is' operator is always of the provided type | Warning |
The given expression of 'is' operator is never of the provided type | Warning |
The source expression always matches the provided pattern | Warning |
The source expression is always of pattern's type | Warning |
The source expression never matches the provided pattern | Warning |
Thread static field has initializer | Warning |
Try cast and check for null may be replaced with type check | Warning |
Try cast and check for null may be replaced with type check | Warning |
Type check and casts can be merged | Suggestion |
Unassigned field (non-private accessibility) | Suggestion |
Unassigned field (private accessibility) | Warning |
Unassigned readonly field | Warning |
Usage of <inheritdoc /> is invalid. | Warning |
Use <inheritdoc /> on root level to inherit documentation from base candidate. | Suggestion |
Use collection's count property | Suggestion |
Use format specifier in format strings | Suggestion |
Use format specifier in interpolated strings | Suggestion |
'value' parameter is not used | Warning |
Virtual member call in constructor | Warning |
'void' method is annotated by [MustUseReturnValue] attribute | Warning |
'void' method is annotated by [Pure] attribute | Warning |
Redundancies in Code (62 inspections)
Code inspections in this category look for redundancies and dead code, which affect code readability and style, and could be safely removed. Some code redundancies cannot be fixed automatically, and quick-fixes for them are performed in the interactive mode, requiring the user input. But the majority of the redundancies can be fixed without user interaction, using either fix in scope or code cleanup.Inspection | Default Severity |
---|---|
'??' condition is known to be null or not null | Warning |
Anonymous method signature is not necessary | Warning |
Array creation can be replaced with array initializer | Hint |
Assignment is not used | Warning |
Assignment results are fully discarded | Warning |
Conditional access qualifier expression is known to be null or not null | Warning |
Double negation operator | Suggestion |
Empty 'for' loop is redundant | Warning |
Explicit delegate creation expression is redundant | Warning |
Expression is always 'null' | Warning |
Expression is always 'true' or always 'false' | Warning |
Heuristically unreachable code | Warning |
Immediate delegate invocation | Suggestion |
Parentheses are redundant if attribute has no arguments | Hint |
Private field can be converted to local variable | Warning |
Redundant [AttributeUsage] attribute property assignment | Suggestion |
Redundant anonymous type property explicit name | Warning |
Redundant argument with default value | Warning |
Redundant arithmetic overflow checking context | Warning |
Redundant 'base.' qualifier | Warning |
Redundant boolean comparison | Warning |
Redundant braces in collection initializer | Hint |
Redundant 'case' label | Warning |
Redundant cast | Warning |
Redundant cast to 'object' | Warning |
Redundant catch clause | Warning |
Redundant comma in array/object/collection/anonymous type initializer | Hint |
Redundant comma in attribute list | Hint |
Redundant comma in enum declaration | Hint |
Redundant condition check before assignments | Warning |
Redundant conditional ternary expression usage | Warning |
Redundant control flow jump statement | Warning |
Redundant 'else' keyword | Hint |
Redundant empty argument list on object creation expression | Hint |
Redundant empty finally block | Warning |
Redundant empty object or collection initializer | Warning |
Redundant empty switch section | Warning |
Redundant explicit array creation in argument of 'params' parameter | Suggestion |
Redundant explicit nullable type creation | Warning |
Redundant explicit size specification in array creation | Warning |
Redundant explicit tuple component name | Warning |
Redundant explicit type in array creation | Warning |
Redundant 'IEnumerable.Cast<T>' or 'IEnumerable.OfType<T>' call | Warning |
Redundant lambda expression parameter type specification | Warning |
Redundant lambda signature parentheses | Hint |
Redundant name qualifier | Warning |
Redundant 'object.ToString()' call | Warning |
Redundant 'object.ToString()' call for value types | Hint |
Redundant operand in logical conditional expression | Warning |
Redundant 'orderby' clause 'ascending' keyword | Hint |
Redundant semicolon after type or namespace declaration | Hint |
Redundant string interpolation | Suggestion |
Redundant 'string.Format()' call | Warning |
Redundant 'string.ToCharArray()' call | Warning |
Redundant type arguments of method | Warning |
Redundant type specification in default expression | Suggestion |
Redundant using directive | Warning |
Redundant verbatim prefix | Suggestion |
Redundant verbatim string prefix | Suggestion |
'true' is redundant as 'for'-statement condition | Warning |
Type check for nullable type is equal to underlying type check | Warning |
Unsafe context declaration is redundant | Warning |
Redundancies in Symbol Declarations (41 inspections)
This category includes code inspections, mostly with the warning severity level, which detect empty and unused symbol declarations.Inspection | Default Severity |
---|---|
Class with virtual(overridable) members never inherited (non-private accessibility) | Suggestion |
Class with virtual(overridable) members never inherited (private accessibility) | Suggestion |
Component of the tuple is never used | Warning |
'DefaultParameterValueAttribute' should be used in conjunction with 'OptionalAttribute' | Warning |
Empty constructor | Warning |
Empty destructor | Warning |
Empty namespace declaration | Warning |
Local entity is only used to capture it's name | Warning |
Local function is never used | Warning |
Local function return value is never used | Warning |
Method return value is never used (non-private accessibility) | Suggestion |
Method return value is never used (private accessibility) | Warning |
Non-accessed local variable | Warning |
Parameter is only used for precondition check (non-private accessibility) | Suggestion |
Parameter is only used for precondition check (private accessibility) | Warning |
'params' modifier is always ignored on overrides | Warning |
Redundant base constructor call | Warning |
Redundant class or interface specification in base types list | Warning |
Redundant member initializer | Warning |
Redundant member override | Warning |
Redundant method overload (non-private accessibility) | Suggestion |
Redundant method overload (private accessibility) | Suggestion |
Redundant 'partial' modifier on method declaration | Warning |
Redundant 'partial' modifier on type declaration | Warning |
Sealed member in sealed class | Warning |
Type member is never accessed via base type (non-private accessibility) | Suggestion |
Type member is never accessed via base type (private accessibility) | Warning |
Type member is only used in overrides (non-private accessibility) | Suggestion |
Type member is only used in overrides (private accessibility) | Warning |
Type or member is never used (non-private accessibility) | Suggestion |
Type or member is never used (private accessibility) | Warning |
Underlying type of enum is 'int' | Warning |
Unused label | Warning |
Unused local variable | Warning |
Unused parameter (non-private accessibility) | Suggestion |
Unused parameter (private accessibility) | Warning |
Unused parameter in partial method | Warning |
Unused parameter of local function | Warning |
Unused type parameter | Warning |
Virtual(overridable) member is never overridden (non-private accessibility) | Suggestion |
Virtual(overridable) member is never overridden (private accessibility) | Suggestion |