Code Inspections in C#
In C#, ReSharper 2024.3 provides two kinds of code inspections: 1176 inspections that detect errors such as broken syntax, unresolved symbols, compiler errors, and so on (you cannot configure or disable any of these inspections), and 958 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 by their categories.
Code Notification (2 inspections)
This category groups code inspections with minor severity levels.
Inspection | |
---|---|
| |
Part of the code cannot be parsed |
Common Practices and Code Improvements (172 inspections)
This category groups inspections that hunt for medium severity issues that mainly affect code readability.
Inspection | |
---|---|
Access to a static member of a type via a derived type | |
Add explicit 'return' or 'continue' before local functions | |
Annotation duplicate in hierarchy | |
Auto-property can be made get-only (non-private accessibility) | |
Auto-property can be made get-only (private accessibility) | |
Base member has 'params' parameter, but the overrider does not have it | |
Can simplify 'Contains' before 'Add' | |
Cast expression can be replaced with explicit type arguments | |
Cast expression can be replaced with explicit variable type | |
Cast expression can be replaced with lambda return type | |
Cast expression can be replaced with simplified type arguments | |
Change lock field type to 'System.Threading.Lock' | |
Check for reference equality instead | |
Check for reference equality instead | |
Check for reference equality instead | |
Check for reference equality instead | |
Class can be made sealed (non-inheritable) (non-private accessibility) | |
Class can be made sealed (non-inheritable) (private accessibility) | |
| |
Container nullability attribute usage with declaration of non-container type | |
Convert 'if do while' into 'while' | |
| |
Convert local variable or field into constant (non-private accessibility) | |
Convert local variable or field into constant (private accessibility) | |
Declaration nullability inferred (parameter is inferred to be not null) | |
Declaration nullability inferred (parameter is inferred to be nullable) | |
Declaration nullability inferred (type member is inferred to be not null) | |
Declaration nullability inferred (type member is inferred to be nullable) | |
Dictionary item removal can be simplified with single 'Remove' | |
Dictionary lookup can be simplified with 'GetValueOrDefault' | |
Dictionary lookup can be simplified with 'TryAdd' | |
Dictionary lookup can be simplified with 'TryGetValue' | |
| |
Extract common property pattern | |
Field can be made readonly (non-private accessibility) | |
Field can be made readonly (private accessibility) | |
Get-only auto-property is never assigned | |
Invert condition | |
Iteration variable can be declared with a more specific type | |
Join local variable declaration and assignment | |
Local function can be made static | |
Local variable has too wide declaration scope | |
Make constructor in abstract class protected | |
Member can be made private (non-private accessibility) | |
Member can be made private (private accessibility) | |
Member can be made protected (non-private accessibility) | |
Member can be made protected (private accessibility) | |
Member can be made static (shared) (non-private accessibility) | |
Member can be made static (shared) (private accessibility) | |
Member or type can be made internal (friend) | |
Method has async overload | |
Method has async overload with cancellation support | |
Method supports cancellation | |
Missing XML comment for private or internal type or member | |
Multiple nullable attributes usage | |
Nested string interpolation can be inlined | |
Nullability attribute usage with declaration of void or value type | |
Nullability attribute used with declaration that cannot be directly referenced from other code | |
Parameter can be declared with the base type | |
Parameter of the constructor can be declared with the base type | |
Parameter type can be IEnumerable<T> (non-private accessibility) | |
Parameter type can be IEnumerable<T> (private accessibility) | |
Property can be made init-only (non-private accessibility) | |
Property can be made init-only (private accessibility) | |
Put local function after 'return' or 'continue' | |
Redundant 'is' | |
Remove constructor invocation | |
Remove redundant statement | |
Remove redundant statement | |
Remove ToList() | |
Remove ToList() | |
Replace 'async' code with 'Task'-return | |
Replace with FirstOrDefault($args$) | |
Replace with FirstOrDefault($args$) | |
Replace with FirstOrDefault($args$) | |
Replace with FirstOrDefault($args$) | |
Replace with LastOrDefault($args$) | |
Replace with LastOrDefault($args$) | |
Replace with LastOrDefault($args$) | |
Replace with LastOrDefault($args$) | |
Replace with OfType<T>() | |
Replace with OfType<T>() | |
Replace with OfType<T>() | |
Replace with OfType<T>().Any() | |
Replace with OfType<T>().Any() (replace with OfType<T>().Any(..)) | |
Replace with OfType<T>().Count() | |
Replace with OfType<T>().Count() (replace with OfType<T>().Count(..)) | |
Replace with OfType<T>().First() | |
Replace with OfType<T>().First() (replace with OfType<T>().First(..)) | |
Replace with OfType<T>().FirstOrDefault() | |
Replace with OfType<T>().FirstOrDefault() (replace with OfType<T>().FirstOrDefault(..)) | |
Replace with OfType<T>().Last() | |
Replace with OfType<T>().Last() (replace with OfType<T>().Last(..)) | |
Replace with OfType<T>().LastOrDefault() | |
Replace with OfType<T>().LastOrDefault() (replace with OfType<T>().LastOrDefault(..)) | |
Replace with OfType<T>().LongCount() | |
Replace with OfType<T>().Single() | |
Replace with OfType<T>().Single() (replace with OfType<T>().Single(..)) | |
Replace with OfType<T>().SingleOrDefault() | |
Replace with OfType<T>().SingleOrDefault() (replace with OfType<T>().SingleOrDefault(..)) | |
Replace with OfType<T>().Where() (replace with OfType<T>().Where(..)) | |
Replace with simple assignment | |
Replace with simple assignment | |
Replace with single assignment | |
Replace with single assignment | |
Replace with single call to Any(..) | |
Replace with single call to Count(..) | |
Replace with single call to First(..) | |
Replace with single call to FirstOrDefault(..) | |
Replace with single call to Last(..) | |
Replace with single call to LastOrDefault(..) | |
Replace with single call to Single(..) | |
Replace with single call to SingleOrDefault(..) | |
Replace with SingleOrDefault($args$) | |
Replace with SingleOrDefault($args$) | |
Replace with SingleOrDefault($args$) | |
Replace with SingleOrDefault($args$) | |
Return type can be IEnumerable<T> (non-private accessibility) | |
Return type can be IEnumerable<T> (private accessibility) | |
Simplify conditional ternary expression | |
Simplify 'IsInstanceOfType()' invocation | |
Simplify LINQ expression (use 'All') | |
Simplify LINQ expression (use 'Any') | |
Simplify negated pattern | |
Simplify negated relational pattern | |
Simplify negative equality expression | |
Specify string comparison explicitly | |
Specify string culture explicitly | |
String literal can be inlined | |
String.Compare is culture-specific (string.Compare(string, int, string, int) is culture-specific) | |
| |
| |
String.Compare is culture-specific (string.Compare(string, string) is culture-specific) | |
String.Compare is culture-specific (string.Compare(string, string, bool) is culture-specific) | |
String.Compare is culture-specific (string.Compare(string, string, bool) is culture-specific) | |
String.CompareTo is culture-specific | |
String.EndsWith is culture-specific (string.EndsWith(string) is culture-specific) | |
String.IndexOf is culture-specific (string.IndexOf(string) is culture-specific) | |
String.IndexOf is culture-specific (string.IndexOf(string, int) is culture-specific) | |
String.IndexOf is culture-specific (string.IndexOf(string, int) is culture-specific) | |
String.LastIndexOf is culture-specific (string.LastIndexOf(string) is culture-specific) | |
String.LastIndexOf is culture-specific (string.LastIndexOf(string, int) is culture-specific) | |
String.LastIndexOf is culture-specific (string.LastIndexOf(string, int) is culture-specific) | |
String.StartsWith is culture-specific (string.StartsWith(string) is culture-specific) | |
Struct can be made readonly | |
Struct lacks 'IEquatable' implementation (non-private accessibility) | |
Struct lacks 'IEquatable' implementation (private accessibility) | |
Struct member can be made readonly | |
Struct with default equality members is used for comparison (non-private accessibility) | |
Struct with default equality members is used for comparison (private accessibility) | |
try-catch and try-finally statements can be merged | |
Type can be made file-local | |
Type parameter could be declared as covariant or contravariant | |
Type with suspicious equality is used in a record (non-private accessibility) | |
Type with suspicious equality is used in a record (private accessibility) | |
Usage of default struct equality | |
Use 'ArgumentNullException.ThrowIfNull' | |
Use array creation expression | |
Use array creation expression | |
Use 'Array.Empty<T>()' | |
Use cancellation token | |
Use compiler-supported nullable attributes | |
Use 'EventArgs.Empty' | |
Use indexed property | |
| |
| |
Use method Any() | |
Use method Any() | |
Use method Any() | |
Use method Any() | |
| |
Use 'Type.EmptyTypes' |
Compiler Warnings (197 inspections)
Inspections in this category detect compiler warnings before you compile.
Inspection | |
---|---|
| |
| |
| |
A local variable is returned by reference but was initialized to a value that cannot be returned by reference. | |
A member of a variable is returned by reference but was initialized to a value that cannot be returned by reference | |
A method marked [DoesNotReturn] should not return. | |
A possible null value may not be used for a type marked with [NotNull] or [DisallowNull]. | |
A previous catch clause already catches all exceptions | |
A result of a stackalloc expression in this context may be exposed outside of the containing method. | |
| |
| |
Alignment value 'value' has a magnitude greater than 'magnitude limit' and may result in a large formatted string. | |
Ambiguous reference in XML comment | |
| |
| |
Argument should be a variable because it is passed to a 'ref readonly' parameter. | |
Argument should be passed with the 'in' keyword. | |
Assignment in conditional expression | |
Assignment made to same variable | |
Async function without await expression | |
Async method invocation without await expression | |
| |
Async-iterator has one or more parameters of type 'CancellationToken' but none of them is annotated with the 'EnumeratorCancellation' attribute. | |
| |
| |
Badly formed XML in included comments file | |
Bitwise-or operator used on a sign-extended operand. | |
Call to a non-readonly member from a 'readonly' member results in an implicit copy of 'this' | |
Cannot convert null literal to non-nullable reference type. | |
Cannot resolve reference in XML comment | |
Class overrides Object.Equals(object o) but not Object.GetHashCode() | |
| |
Collection expression may incur unexpected heap allocations | |
Collection expression may incur unexpected heap allocations due to the use of '..' spreads | |
Comparing with null of nullable value type always produces 'false' | |
Comparison to integral constant is useless; the constant is outside the range of type 'type'. | |
Converting method group to non-delegate type 'object'. | |
Converting null literal or possible null value to non-nullable type. | |
Declaring new protected member in sealed class is the same as declaring it as private | |
Default value specified for parameter will have no effect because it applies to a member that is used in contexts that do not allow optional arguments | |
Dereference of a possibly null reference. | |
Duplicate param tag in XML comment | |
Duplicate typeparam tag in XML comment | |
| |
| |
Filter expression is a constant, consider removing the filter | |
Given expression always matches the provided pattern | |
Given expression is always of the provided type | |
Given expression is never of the provided type | |
'goto case' value is not implicitly convertible to required type | |
Incorrect signature in XML comment | |
| |
Inline array indexer will not be used for element access expression. | |
Inline array 'Slice' method will not be used for element access expression. | |
| |
Introducing a 'Finalize' method can interfere with destructor invocation | |
| |
| |
| |
| |
Member cannot be used in this attribute. | |
Member must conditionally have a non-null value when exiting a function. | |
Member must have a non-null value when exiting. | |
Member overrides obsolete member | |
Method lacks '[DoesNotReturn]' annotation in order to match implemented or overridden member. | |
Missing XML comment for publicly visible type or member | |
Multiple override candidates at run-time | |
Namespace should be default namespace of this project | |
| |
| |
Non-nullable member is uninitialized. | |
Nullability mismatch in constraints for type parameter. | |
| |
Nullability of reference types in interface implemented by the base type doesn't match. | |
Nullability of reference types in return type doesn't match implemented member. | |
Nullability of reference types in return type doesn't match implicitly implemented member. | |
Nullability of reference types in return type doesn't match overridden member. | |
Nullability of reference types in return type doesn't match partial method declaration. | |
| |
| |
Nullability of reference types in source type doesn't match target type. | |
Nullability of reference types in type doesn't match implemented member. | |
Nullability of reference types in type doesn't match implicitly implemented member. | |
Nullability of reference types in type doesn't match overridden member. | |
| |
Nullability of reference types in type of parameter doesn't match implemented member. | |
Nullability of reference types in type of parameter doesn't match implicitly implemented member. | |
Nullability of reference types in type of parameter doesn't match interceptable method | |
Nullability of reference types in type of parameter doesn't match overridden member. | |
Nullability of reference types in type of parameter doesn't match partial member declaration. | |
| |
| |
| |
Nullability of type argument doesn't match 'class' constraint. | |
Nullability of type argument doesn't match constraint type. | |
Nullability of type argument doesn't match 'notnull' constraint. | |
| |
| |
| |
Nullable value type may be null. | |
Object or collection initializer implicitly dereferences possibly null member. | |
Obsolete member overrides non-obsolete member | |
Obsolete members should not be required. | |
| |
Opt in to preview features before using them. | |
Parameter has no matching param tag in the XML comment | |
Parameter has params modifier in lambda but not in target delegate type. | |
| |
| |
Parameter must conditionally have a non-null value when exiting a function. | |
| |
Parameter must have a non-null value when exiting. | |
Parameter occurs after interpolated string handler parameter in the parameter list. | |
Partial indexer declarations have signature differences. | |
Partial method declarations have inconsistent nullability for type parameter. | |
Possible mistaken empty statement | |
Possible null reference argument for a parameter. | |
Possible null reference assignment. | |
Possible null reference return. | |
Possible unintended reference comparison | |
Possibly incorrect assignment to local which is the argument to a 'using' or 'lock' statement | |
Primary constructor parameter is shadowed by a member from base type. | |
Record defined 'Equals' but not 'GetHashCode' | |
Reference kind modifier of parameter doesn't match the corresponding parameter in hidden member. | |
| |
Reference kind modifier of parameter doesn't match the corresponding parameter in target. | |
Reference to a volatile field will not be treated as volatile | |
| |
Signatures of interceptable and interceptor methods do not match | |
Static type in 'is' or 'as' operator. | |
Struct member returns 'this' or other instance members by reference. | |
| |
Taking address of marshal-by-reference class field | |
The '&' operator should not be used on parameters or local variables in async methods. | |
The annotation for nullable reference types should only be used in code within a '#nullable' annotations context. | |
The annotation for nullable reference types should only be used in code within a '#nullable' annotations context. Auto-generated code requires an explicit '#nullable' directive in source. | |
| |
The CallerArgumentExpressionAttribute applied to parameter will have no effect because it's self-referential | |
The CallerArgumentExpressionAttribute is applied with an invalid parameter name. | |
The CallerArgumentExpressionAttribute will have no effect because it applies to a member that is used in contexts that do not allow optional arguments | |
The CallerArgumentExpressionAttribute will have no effect; it is overridden by the CallerFilePathAttribute | |
The CallerArgumentExpressionAttribute will have no effect; it is overridden by the CallerLineNumberAttribute | |
The CallerArgumentExpressionAttribute will have no effect; it is overridden by the CallerMemberNameAttribute | |
The default parameter value does not match in the target delegate type. | |
The 'EnumeratorCancellation' attribute is only effective on a parameter of type 'CancellationToken' in an async-iterator method returning 'IAsyncEnumerable<>'. | |
The given expression always matches the provided constant. | |
The given expression never matches the provided pattern. | |
The 'l' suffix is easily confused with the digit '1' | |
The 'Main' method will not be used as an entry point because compilation unit with top-level statements was found. | |
| |
| |
The result of the expression is always 'null' of nullable type | |
| |
| |
The 'scoped' modifier of a parameter doesn't match target delegate. | |
The 'scoped' modifier of parameter doesn't match overridden or implemented member. | |
The switch expression does not handle all possible inputs (it is not exhaustive). | |
The switch expression does not handle all possible values of its input type (it is not exhaustive). However, a pattern with a 'when' clause might successfully match this value. | |
The switch expression does not handle some null inputs (it is not exhaustive). | |
| |
The switch expression does not handle some values of its input type (it is not exhaustive) involving an unnamed enum value. | |
The tuple element name is ignored because a different name or no name is specified by the target type. | |
The tuple element name is ignored because a different name or no name is specified on the other side of the tuple == or != operator. | |
| |
| |
This ref-assigns a value that can only escape the current method through a return statement. | |
| |
This ref-assigns an expression to a variable with a narrower escape scope. | |
This returns a member of local by reference but it is not a ref local. | |
This returns a parameter by reference but it is not a ref parameter. | |
This returns a parameter by reference but it is scoped to the current method. | |
| |
This returns by reference a member of parameter that is not a ref or out parameter. | |
This returns by reference a member of parameter that is scoped to the current method. | |
| |
This returns local by reference but it is not a ref local. | |
This takes the address of, gets the size of, or declares a pointer to a managed type. | |
| |
Type is already listed in the interface list with different nullability of reference types. | |
Type is for evaluation purposes only and is subject to change or removal in future updates. | |
Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. | |
Type parameter has no matching typeparam tag in the XML comment | |
Type parameter has the same name as a type parameter from the outer type | |
Types and aliases should not be named 'record' | |
Unable to include XML fragment | |
| |
| |
Unboxing a possibly null value. | |
| |
Use of a variable in this context may expose referenced variables outside of their declaration scope. | |
| |
Use of obsolete symbol (without message) | |
Using 'is' to test compatibility with 'dynamic' is essentially identical to testing compatibility with 'Object' and will succeed for all non-null values | |
XML comment has a 'param' tag for 'Parameter', but there is no parameter by that name | |
XML comment has a 'typeparam' tag for 'TypeParameter', but there is no type parameter by that name | |
XML comment has cref attribute that refers to a type parameter | |
XML comment is not placed on a valid language element |
Constraints Violations (11 inspections)
This category includes code inspections, mostly with the warning severity level, which detect violations related to symbol attributes, including ReSharper's code annotations, and other similar issues.
Inspection | |
---|---|
| |
BaseTypeRequired attribute supports only classes and interfaces | |
| |
Namespace does not correspond to file location | |
Non-nullable or required member is not initialized at constructor exit | |
Possible 'null' assignment to non-nullable entity | |
Possible violation of 'ValueRange'/'NonNegativeValue' attribute | |
Problem in contract annotation definition | |
Required base type conflicting another type | |
Type specified in '[BaseTypeRequired]' attribute conflicts another type | |
|
Entity Framework (8 inspections)
This category groups code inspections that validate usages of types and members from Entity Framework and their derivatives.
Inspection | |
---|---|
Database function must not be called in non-database context | |
Function is not convertible to SQL and must not be called in the database context | |
Possible multiple queries to the database (N+1 problem) | |
Possible multiple queries to the database for related entities (N+1 problem) | |
Possible performance issues caused by unlimited string length | |
Query can return incomplete data for related entities | |
The relationship defined by this property contributes to a dependency loop | |
Usage of navigational property can return incomplete data |
Formatting (41 inspections)
Inspections in this category detect code formatting problems.
Inspection | |
---|---|
Incorrect blank lines (blank lines are missing elsewhere) | |
Incorrect blank lines (blank lines are redundant elsewhere) | |
Incorrect blank lines (incorrect number of blank lines near braces) | |
Incorrect indent (around child statement) | |
Incorrect indent (around declaration braces) | |
Incorrect indent (around expression braces) | |
Incorrect indent (around namespace braces) | |
Incorrect indent (around preprocessor directive) | |
Incorrect indent (around statement braces) | |
Incorrect indent (around switch statement) | |
Incorrect indent (incorrect indent size) | |
Incorrect indent (indent level is not restored) | |
Incorrect indent (missing indent/outdent elsewhere) | |
Incorrect indent (redundant indent/outdent elsewhere) | |
Incorrect indent (tabs/spaces mismatch) | |
Incorrect line breaks (around comma in lists) | |
Incorrect line breaks (around declaration braces) | |
Incorrect line breaks (around empty braces) | |
Incorrect line breaks (around expression braces) | |
Incorrect line breaks (around LINQ queries) | |
Incorrect line breaks (around parenthesis) | |
Incorrect line breaks (around statement braces) | |
Incorrect line breaks (line break is missing elsewhere) | |
Incorrect line breaks (line break is redundant elsewhere) | |
Incorrect line breaks (multiple statements on one line) | |
Incorrect line breaks (multiple type members on one line) | |
Incorrect spacing (around attributes) | |
Incorrect spacing (around braces) | |
Incorrect spacing (around colon) | |
Incorrect spacing (around comma) | |
Incorrect spacing (around generic brackets) | |
Incorrect spacing (around member access symbols) | |
Incorrect spacing (around operator symbols) | |
Incorrect spacing (around parenthesis) | |
Incorrect spacing (around semicolon) | |
Incorrect spacing (around square brackets within a statement) | |
Incorrect spacing (between keyword and parenthesis) | |
Incorrect spacing (multiple spaces are prohibited) | |
Incorrect spacing (space is missing elsewhere) | |
Incorrect spacing (space is redundant elsewhere) | |
Incorrect spacing (tabs are prohibited here) |
Grammar Issues (4 inspections)
Inspections in this category report grammar issues in string literals and documentation comments.
Inspection | |
---|---|
| |
Grammar error in markup attribute value | |
| |
Grammar error in string literal |
Language Usage Opportunities (83 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.
Inspection | |
---|---|
Append to collection expression | |
Class cannot be instantiated | |
Conditional expression can be rewritten as null-coalescing | |
Convert 'as' expression type check and the following null check into negated pattern matching | |
Convert 'as' expression type check and the following null check into pattern matching | |
Convert constructor into member initializers | |
Convert constructor into primary constructor | |
Convert delegate variable into local function | |
Convert 'if' statement into 'switch' | |
Convert into 'await using' statement or declaration | |
Convert into lambda expression | |
Convert into static class | |
Convert into 'using' declaration | |
Convert lambda expression into method group | |
Convert negated 'is' expression into 'is' expression with negated pattern | |
Convert 'Nullable<T>' into 'T?' | |
Convert property into auto-property | |
Convert property into auto-property (when possible) | |
Convert property into auto-property with private setter | |
Convert static method invocation into extension method call | |
Foreach loop can be converted into LINQ-expression but another 'GetEnumerator' method will be used | |
For-loop can be converted into foreach-loop | |
'if' statement can be rewritten as '?:' expression | |
'if' statement can be rewritten as '??' expression | |
'if' statement can be rewritten as '??=' assignment | |
'if-return' statement can be rewritten as 'return' statement | |
Inline 'out' variable declaration | |
| |
Introduce optional parameters (non-private accessibility) | |
Introduce optional parameters (private accessibility) | |
Invert 'if' statement to reduce nesting | |
Join null check with assignment | |
Lambda expression/anonymous method can be made 'static' | |
Lambda expression/anonymous method must be 'static' to avoid allocations | |
Lambda expression/anonymous method must not have captures of the containing context | |
Literal length can be reduced by using verbatim string | |
Loop can be converted into LINQ-expression | |
Merge 'and' pattern | |
Merge conditional ?: expression into conditional access | |
Merge negated null/pattern checks into complex pattern | |
Merge nested property patterns | |
Merge null/pattern checks into complex pattern | |
Merge null/pattern/value checks into 'or'/'and' patterns | |
Merge sequential checks into single conditional access check | |
Move to existing positional deconstruction pattern | |
Move variable declaration inside loop condition | |
Part of foreach loop can be converted into LINQ-expression but another 'GetEnumerator' method will be used | |
Part of loop's body can be converted into LINQ-expression | |
Pass string interpolation expression | |
Redundant accessor body | |
Replace auto-property with computed property | |
Replace if statement with null-propagating code | |
Replace object pattern not performing any additional checks with 'var' pattern | |
Replace 'SequenceEqual' with constant pattern | |
Replace 'Slice' with range indexer | |
Replace 'Substring' with range indexer | |
Replace 'switch' statement with 'switch' expression | |
Replace ternary expression with 'switch' expression | |
Replace with 'field' keyword | |
Replace with primary constructor parameter | |
Use alias | |
Use collection expression syntax | |
Use compound assignment | |
| |
Use deconstruction | |
Use deconstruction to swap variables | |
| |
Use index from end expression | |
Use 'nameof' expression to reference name | |
Use 'nameof' expression to reference name in part of the string literal | |
Use 'nameof' expression to reference type name | |
Use 'nameof' expression when registering a DependencyProperty | |
Use object or collection initializer when possible | |
Use positional deconstruction pattern | |
Use raw string | |
Use string interpolation expression | |
Use type annotation syntax | |
Use unsigned right shift operator '>>>' | |
| |
Use 'with' expression to copy anonymous object | |
Use 'with' expression to copy record | |
Use 'with' expression to copy struct | |
Use 'with' expression to copy tuple |
NUnit (30 inspections)
These inspections detect code issues related to NUnit tests.
Inspection | |
---|---|
NUnit. Async test method must return Task or Task<T> | |
NUnit. Duplicate values. | |
NUnit. Ignored parameter attribute. | |
NUnit. Implicitly unspecified null values. | |
NUnit. Incompatible argument type or incorrect argument value. | |
NUnit. Incompatible expected result type or incorrect value. | |
NUnit. Incorrect range bounds. 'to' must be greater than or equal to 'from'. | |
NUnit. Mismatch of the range step sign. | |
NUnit. Missing arguments in TestCase attribute. | |
NUnit. Missing 'CancelAfter' attribute on test method declaration. | |
NUnit. Missing expected result for non-void test method. | |
NUnit. No values provided in the attributes. | |
NUnit. Non-public test method. | |
NUnit. Range 'step' parameter value must be non-zero. | |
NUnit. Redundant argument in TestCase attribute. | |
NUnit. Redundant argument instead of ExpectedResult. | |
NUnit. Redundant expected result for void test method. | |
NUnit. Specified attribute values produce too many tests. | |
NUnit. Specified values are not compatible with the test parameter type. | |
NUnit. Test case Result property duplicates ExpectedResult. | |
NUnit. Test case Result property is obsolete. | |
NUnit. Test case source must be field, property, or method. | |
NUnit. Test case source must be non-abstract and implement IEnumerable. | |
NUnit. Test case source must be static. | |
NUnit. The maximum range value is not reachable with the step value. | |
NUnit. Values for test method parameters are not provided. | |
NUnit. Values in range do not fit the type of the test parameter. | |
NUnit.AutoFixture. Incompatible argument type or incorrect argument value. | |
NUnit.AutoFixture. Missing Test or TestFixture attribute. | |
NUnit.AutoFixture. Redundant argument in InlineAutoData attribute. |
Potential Code Quality Issues (211 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 | |
---|---|
'?:' expression has identical true and false branches | |
| |
[ThreadStatic] does not work with instance fields | |
A suppressed nullable warning might hide an underlying problem | |
Abstract or virtual (overridable) event is never invoked | |
Access to disposed captured variable | |
Access to foreach variable in closure | |
Access to modified captured variable | |
According to values of the bit masks, expression result will always be the same | |
Actual shift count equals zero | |
Ambiguous symbols in text argument | |
Annotation conflict in hierarchy | |
Assignment in conditional expression | |
Async iterator invocation without 'await foreach' | |
Auto-property accessor is never used (non-private accessibility) | |
Auto-property accessor is never used (private accessibility) | |
Avoid mixing of variable-length escape sequences and text | |
Avoid using 'async' for methods and functions with the 'void' return type | |
Avoid using 'async' lambda when delegate type returns 'void' | |
Backing field is assigned but never used | |
Backing field is used but never assigned | |
Bitwise operation on enum that is not marked by the [Flags] attribute | |
Call to base member with implicit default parameters | |
Call to 'base.Equals(...)' is reference equality | |
Cannot access static symbol in text argument | |
Cannot access symbol in text argument | |
Cannot resolve property | |
Cannot resolve resource | |
Cannot resolve resource item | |
Cannot resolve symbol in text argument | |
Captured field reference of a marshal-by-reference class may cause a runtime exception | |
Captured primary constructor parameter is mutable | |
Captured reference to 'volatile' field will not be treated as 'volatile' | |
Char is possibly unintentionally used as integer | |
Class is never instantiated (non-private accessibility) | |
Class is never instantiated (private accessibility) | |
Collection content is never queried (non-private accessibility) | |
Collection content is never queried (private accessibility) | |
Collection is never updated (non-private accessibility) | |
Collection is never updated (private accessibility) | |
| |
Constant shift expression with non-zero operands results in a zero value | |
| |
CQRS attribute is redundant and can be removed | |
CQRS context intersection. Command is called from the Query context. (show on declarations) | |
CQRS context intersection. Command is called from the Query context. (show on usages) | |
CQRS context intersection. Query is called from the Command context. (show on declarations) | |
CQRS context intersection. Query is called from the Command context. (show on usages) | |
Disposal of a variable already captured by the 'using' statement | |
Division by zero in at least one execution path | |
Do not store SpinLock in readonly field | |
Do not use object initializer for 'using' variable | |
| |
Duplicated switch section bodies | |
| |
| |
Empty 'with' expression is redundant | |
'Enumerable.Sum' invocation in explicit unchecked context | |
Equality comparison of floating point numbers | |
Escape sequence can be simplified | |
Event is never subscribed to (non-private accessibility) | |
Event is never subscribed to (private accessibility) | |
Event never invoked | |
Event unsubscription via anonymous delegate | |
Exception rethrow possibly intended | |
Explicit argument passed to parameter with caller info attribute | |
| |
Field hides property with default implementation in interface | |
Formatting is specified, but interpolated string expression is not IFormattable | |
Function body is too complex to analyze | |
Function is recursive on all execution paths | |
| |
'GC.SuppressFinalize' is invoked for type without destructor | |
Heuristically unreachable case according to integer analysis | |
Heuristically unreachable switch arm according to integer analysis | |
Inconsistent arguments passed to 'Math.Clamp()' method | |
Inconsistent order of taken locks | |
Inconsistent synchronization on field | |
Index from end must be greater than zero; use '^1' to refer to the last element | |
Interfaces marked as ServiceContract should declare at least one OperationContract | |
Invalid XML documentation comment | |
Invocation of polymorphic field-like event | |
IQueryable is possibly unintentionally used as IEnumerable | |
Iterator never returns | |
Local function hides method | |
| |
Local variable hides primary constructor parameter | |
Loop control variable is never changed inside loop | |
Meaningless [HandlesResourceDisposal] annotation for an output parameter | |
Meaningless [MustDisposeResource] annotation for an input parameter | |
Member hides static member from outer class | |
Member initialized value ignored | |
Method is called from both CQRS contexts (show on declarations) | |
Method is called from both CQRS contexts (show on usages) | |
Method is marked as OperationContract but containing type is not marked as ServiceContract | |
Method with optional or 'params' parameter is hidden by overload | |
Mismatch of optional parameter value in overridden method | |
Missing '.ConfigureAwait(false)' for async disposable in library code | |
Missing '.ConfigureAwait(false)' in library code | |
Multiple sequential 'OrderBy' invocation | |
Non-accessed field (non-private accessibility) | |
Non-accessed field (private accessibility) | |
Non-accessed positional property (non-private accessibility) | |
Non-accessed positional property (private accessibility) | |
Non-public member in implementation class hides default implementation in interface | |
Non-readonly type member referenced in 'GetHashCode()' | |
Nullability conflicts with annotations in hierarchy | |
Nullable warning suppression operator might be confused with inverted 'is' expression | |
'Object.ReferenceEquals' is always false because it is called with value type | |
One way operations must not return values | |
Operator 'is'/'Type Of ... Is ...' can be used | |
Operator without matching checked operator | |
Overridden GetHashCode calls base 'Object.GetHashCode()' | |
| |
Parameter hides primary constructor parameter | |
Parameter name differs between partial member declarations | |
Possible ambiguity while accessing member by interface | |
Possible comparison of value type with 'null' | |
Possible cyclic constructor call | |
| |
Possible incorrect implementation of Double-Check Locking pattern. Read access to checked field. | |
| |
Possible loss of fraction | |
Possible mistaken argument of type 'System.Type' | |
Possible mistaken 'GetType()' invocation | |
| |
Possible overflow | |
Possible overflow in checked context | |
Possible overflow in unchecked context | |
Possible 'System.ArgumentOutOfRangeException'. Index must be a non-negative integer. | |
Possible 'System.ArgumentOutOfRangeException'. Start index must be less than or equal to end index. | |
Possible 'System.InvalidCastException' | |
Possible 'System.InvalidCastException' in foreach loop | |
Possible 'System.InvalidOperationException' | |
Possible 'System.InvalidOperationException: Collection was modified' | |
Possible 'System.NullReferenceException' | |
Possible unassigned object created by 'new' expression | |
Possible unintended reference comparison | |
| |
Possibly misleading 'DefaultValueAttribute' usage to define optional parameter value | |
Possibly missing comma before indexer initializer | |
Possibly unintended linear search in set | |
Possibly unintended string interpolation instead of format string template | |
Possibly wrong string comparison: spans are only equal when pointing to the same memory location | |
Potentially misleading parameter name in lambda or local function | |
Primary constructor parameter capturing is disallowed | |
'ref' or 'out' parameter with [Optional] attribute | |
Return of a task produced by 'using'-captured object | |
Return of a variable captured by 'using' statement | |
Return type of a function can be made non-nullable | |
Return value of [MustUseReturnValue] annotated method is not used | |
Return value of a method annotated with [MustDisposeResource] is never disposed | |
Return value of a property must be disposed by the callee | |
Return value of 'GetEnumerator' method call is never disposed | |
Return value of iterator is not used | |
Return value of pure method is not used | |
| |
Safe cast expression always succeeds | |
Shift expression with zero left operand equals zero | |
Similar anonymous type detected nearby | |
Similar expressions comparison | |
| |
Some values of the enum are not processed inside 'switch' statement | |
| |
Static field or auto-property in generic type | |
Static member initializer refers to static member below or in other part | |
String formatting method problems | |
Structured message template problems | |
Suspicious locking over synchronization primitive | |
Suspicious parameter name in ArgumentNullException | |
Suspicious shift count for this type of left operand | |
Suspicious type conversion or check | |
Suspicious use of variable with discard-like name | |
Suspicious 'volatile' field usage: compound operation is not atomic. 'Interlocked' class can be used instead. | |
Symbol from module that might be missing at runtime | |
Tail recursive call can be replaced with loop | |
The expression of 'is' operator is never of the provided type | |
The given expression of 'is' operator is always of the provided type | |
The pattern is redundant, it does not produce any runtime checks | |
The source expression always matches the provided pattern | |
The source expression never matches the provided pattern | |
Thread static field has initializer | |
Try cast and check for null can be replaced with a type check | |
Type check and casts can be merged | |
Type pattern and casts can be merged | |
Unassigned field (non-private accessibility) | |
Unassigned field (private accessibility) | |
Unassigned readonly field | |
| |
Unknown Razor layout | |
Unknown Razor section | |
Usage of <inheritdoc /> is invalid | |
Use <inheritdoc /> on root level to inherit documentation from base candidate | |
Use collection's count property | |
Use format specifier in format strings | |
Use format specifier in interpolated strings | |
Use null check instead of a type check succeeding on any not-null value | |
Use null check pattern instead of a type check succeeding on any not-null value | |
Use nullable annotation instead of an attribute | |
Useless arithmetical operation | |
Using stackalloc inside loop | |
Value assigned to a property of non-variable qualifier expression can be lost | |
| |
Variable can be declared as non-nullable | |
Variable in local function hides variable from outer scope | |
Virtual member call in constructor | |
'void' method is annotated with the [MustDisposeResource] attribute | |
'void' method is annotated with the [MustUseReturnValue] attribute | |
'void' method is annotated with the [Pure] attribute | |
'with' expression is used instead of object initializer | |
'with' expression modifies all accessible instance members |
Redundancies in Code (96 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 | |
---|---|
'??' condition is known to be null or not null | |
'??' condition is never null according to nullable reference types' annotations | |
[NotNull] or [CanBeNull] attribute is applied to a type that already has the same annotation from nullable reference types | |
Anonymous method signature is not necessary | |
Array creation can be replaced with array initializer | |
| |
Assignment results are fully discarded | |
Comparison to integral constant is useless | |
Conditional access qualifier expression is known to be null or not null | |
| |
'ContainsKey' call is redundant before adding the item to the dictionary | |
| |
| |
Empty region | |
Explicit delegate creation expression is redundant | |
| |
Expression is always 'true' or always 'false' | |
Expression is always 'true' or 'false' according to nullable reference types' annotations | |
Heuristically unreachable code | |
Immediate delegate invocation | |
Math.Abs() argument is always non-negative | |
Math.Sign() method always gives the same result | |
Parentheses are redundant if attribute has no arguments | |
Pattern is always 'true' or always 'false' | |
Private field can be converted into local variable | |
Raw string can be simplified | |
Redundant [AttributeUsage] attribute property assignment | |
| |
Redundant anonymous type property explicit name | |
Redundant argument passed to caller argument expression parameter | |
Redundant argument with default value | |
Redundant arithmetic overflow checking context | |
| |
Redundant 'base.' qualifier | |
Redundant boolean comparison | |
Redundant braces in collection initializer | |
| |
Redundant 'case' label before default section | |
| |
| |
Redundant 'class' keyword in record declaration | |
Redundant condition check before assignments | |
Redundant conditional ternary expression usage | |
Redundant context capturing with 'ConfigureAwait' | |
Redundant control flow jump statement | |
Redundant discard designation | |
| |
Redundant empty argument list on object creation expression | |
Redundant empty finally block | |
Redundant empty object or collection initializer | |
Redundant empty switch section | |
Redundant explicit collection creation in argument of 'params' parameter | |
Redundant explicit nullable type creation | |
Redundant explicit positional property declaration | |
Redundant explicit size specification in array creation | |
Redundant explicit tuple component name | |
Redundant explicit type in array creation | |
Redundant fixed pointer declaration | |
Redundant global using directive | |
Redundant 'IEnumerable.Cast<T>' or 'IEnumerable.OfType<T>' call | |
Redundant lambda expression parameter type specification | |
Redundant lambda signature parentheses | |
| |
Redundant 'notnull' constraint on type parameter constrained by non-nullable base type | |
Redundant nullable annotation on base type constraint of type parameter constrained by another non-nullable base type | |
Redundant nullable annotation on base type constraint of type parameter having non-nullable type kind | |
Redundant nullable annotation on 'class?' constraint of type parameter constrained by non-nullable base type | |
Redundant nullable attribute | |
| |
Redundant nullable warning suppression expression | |
Redundant 'object.ToString()' call | |
Redundant 'object.ToString()' call for value types | |
Redundant operand in logical conditional expression | |
Redundant 'orderby' clause 'ascending' keyword | |
Redundant property pattern clause | |
Redundant range bound | |
Redundant 'readonly' modifier | |
Redundant 'scoped' parameter modifier | |
Redundant semicolon after type or namespace declaration | |
Redundant string interpolation | |
Redundant 'string.Format()' call | |
Redundant 'string.ToCharArray()' call | |
Redundant type arguments of method | |
Redundant type check in a pattern | |
Redundant type declaration body | |
| |
Redundant verbatim prefix | |
Redundant verbatim string prefix | |
Redundant 'virtual' modifier | |
Redundant 'WithCancellation()' invocation | |
Remove redundant pattern-matching parentheses | |
Subpattern that always matches is redundant | |
'true' is redundant as 'for'-statement condition | |
Type check for nullable type is equal to underlying type check | |
Unsafe context declaration is redundant | |
Unused nullable directive |
Redundancies in Symbol Declarations (50 inspections)
This category includes code inspections, mostly with the warning severity level, which detect empty and unused symbol declarations.
Inspection | |
---|---|
Class with virtual (overridable) members never inherited (non-private accessibility) | |
Class with virtual (overridable) members never inherited (private accessibility) | |
Component of the tuple is never used | |
'DefaultParameterValueAttribute' must be used in conjunction with 'OptionalAttribute' | |
| |
| |
Empty implementation of 'partial void' method is redundant | |
| |
Entity is only used to capture its name (non-private accessibility) | |
Entity is only used to capture its name (private accessibility) | |
| |
Local function is never used | |
Local function return value is never used | |
Method return value is never used (non-private accessibility) | |
Method return value is never used (private accessibility) | |
| |
Non-accessed local variable is only used to discard the 'out' parameter value | |
Not accessed primary constructor parameter | |
Parameter is only used for precondition check (non-private accessibility) | |
Parameter is only used for precondition check (private accessibility) | |
Parameter output value is always discarded (non-private accessibility) | |
Parameter output value is always discarded (private accessibility) | |
'params' modifier is always ignored on overrides | |
Redundant base constructor call | |
Redundant class or interface specification in base types list | |
| |
| |
Redundant method overload (non-private accessibility) | |
Redundant method overload (private accessibility) | |
Redundant 'partial' modifier on method declaration | |
Redundant 'partial' modifier on type declaration | |
| |
Type is never used (non-private accessibility) | |
Type is never used (private accessibility) | |
Type member is never accessed via base type (non-private accessibility) | |
Type member is never accessed via base type (private accessibility) | |
Type member is never used (non-private accessibility) | |
Type member is never used (private accessibility) | |
Type member is only used in overrides (non-private accessibility) | |
Type member is only used in overrides (private accessibility) | |
Underlying type of enum is 'int' | |
Unused label | |
| |
Unused parameter (non-private accessibility) | |
Unused parameter (private accessibility) | |
Unused parameter in partial method | |
Unused positional parameter | |
Unused type parameter | |
Virtual (overridable) member is never overridden (non-private accessibility) | |
Virtual (overridable) member is never overridden (private accessibility) |
Security (1 inspection)
Inspections in this category report NuGet packages that have vulnerabilities according to Checkmarks.
Inspection | |
---|---|
|
Spelling Issues (3 inspections)
These inspections detect typos in various contexts.
Inspection | |
---|---|
| |
| |
|
Syntax Style (46 inspections)
Inspections in this category detect violations of code syntax styles. In contrast to most 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 on the page of ReSharper options Alt+R, O. You can also fix issues that these inspection detect using code cleanup.
Inspection | |
---|---|
Add parentheses to avoid non-obvious precedence | |
Add/remove qualifier for static members | |
| |
Adjust modifiers declaration order | |
| |
Join or separate attributes in section | |
Join or separate 'var' in deconstruction declarations | |
Place assignment expression into block | |
| |
Replace built-in type reference with a CLR type name or a keyword | |
| |
Separate control transfer statement with blank line | |
Unnecessary whitespace at the end of line | |
Usage of tabulation character for indentation is prohibited | |
Use explicit or implicit modifier definition for type members | |
Use explicit or implicit modifier definition for types | |
| |
Use preferred argument style for anonymous functions | |
Use preferred argument style for literal values | |
Use preferred argument style for named expressions | |
Use preferred argument style for string literal values | |
Use preferred body style (convert into constructor or destructor with preferred body style) | |
Use preferred body style (convert into local function with preferred body style) | |
Use preferred body style (convert into method or operator with preferred body style) | |
Use preferred body style (convert into property, indexer, or event with preferred body style) | |
Use preferred braces style (enforce braces in 'do-while' statement) | |
Use preferred braces style (enforce braces in 'fixed' statement) | |
Use preferred braces style (enforce braces in 'for' statement) | |
Use preferred braces style (enforce braces in 'foreach' statement) | |
Use preferred braces style (enforce braces in 'if' statement) | |
Use preferred braces style (enforce braces in 'lock' statement) | |
Use preferred braces style (enforce braces in 'using' statement) | |
Use preferred braces style (enforce braces in 'while' statement) | |
Use preferred braces style (remove redundant braces) | |
Use preferred namespace body style | |
Use preferred style for discard declaration | |
Use preferred style for trailing comma before new line in multiline lists | |
Use preferred style for trailing comma when the last element is not followed by a new line | |
Use preferred style of default value expression when type is evident | |
Use preferred style of default value expression when type is not evident | |
Use preferred style of 'new' expression when created type is evident | |
Use preferred style of 'new' expression when created type is not evident | |
Use preferred 'var' style (elsewhere) | |
Use preferred 'var' style (for built-in types) | |
Use preferred 'var' style (in deconstruction declarations) | |
Use preferred 'var' style (when type is simple) |
Unreal Build System (2 inspections)
Inspections in this category are specific to Unreal Engine projects.
Inspection | |
---|---|
Dependency for the plugin is missing in the project file | |
Module with this name does not exist |
Xunit (1 inspection)
These inspections detect code issues related to xUnit.Net tests.
Inspection | |
---|---|
|