List of code inspections in C#
This topic lists code inspections available in C#. Under each inspection, you can see the EditorConfig property that you can use to configure that inspection.
Inspection settings in .editorconfig files are configured similarly to other properties — by adding the corresponding lines:
For example, you can change the severity level of the Possible 'System.NullReferenceException' inspection to Error with the following line:
or you can disable the Redundant argument with default value inspection with the following line:
Code Notification (2 inspections)
This category groups code inspections with minor severity levels.
Inspection | |
---|---|
Method invocation is skipped | |
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) | Disabled |
Class can be made sealed (non-inheritable) (private accessibility) | Disabled |
Confusing body-like statement | |
Container nullability attribute usage with declaration of non-container type | |
Convert 'if do while' into 'while' | |
Convert 'if' into '||' | |
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) | 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 |
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' | |
Empty statement is redundant | |
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 | Disabled |
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) | Disabled |
Method has async overload | |
Method has async overload with cancellation support | |
Method supports cancellation | |
Missing XML comment for private or internal type or member | Disabled |
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 | Disabled |
Parameter of the constructor can be declared with the base type | Disabled |
Parameter type can be IEnumerable<T> (non-private accessibility) | Disabled |
Parameter type can be IEnumerable<T> (private accessibility) | Disabled |
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 | Disabled |
Remove redundant statement | |
Remove redundant statement | |
Remove ToList() | |
Remove ToList() | |
Replace 'async' code with 'Task'-return | Disabled |
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) | Disabled |
Return type can be IEnumerable<T> (private accessibility) | Disabled |
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, int, string, int, bool) is culture-specific) | |
String.Compare is culture-specific (string.Compare(string, int, string, int, bool) 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) | Disabled |
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) | Disabled |
Struct can be made readonly | |
Struct lacks 'IEquatable' implementation (non-private accessibility) | |
Struct lacks 'IEquatable' implementation (private accessibility) | |
Struct member can be made readonly | Disabled |
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 | Disabled |
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' | Disabled |
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 'is' operator | |
Use method Any() | |
Use method Any() | |
Use method Any() | |
Use method Any() | |
Use method Any() | |
Use 'String.IsNullOrEmpty' | |
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 | |
| |
| |
| |
Keyword 'new' is required | |
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. | |
Operator '==' or operator '!=' with 'Object.Equals(object o)' and 'Object.GetHashCode()' not overridden | |
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 JetBrains Fleet's code annotations, and other similar issues.
Inspection | |
---|---|
Base type is required | |
BaseTypeRequired attribute supports only classes and interfaces | |
Inconsistent Naming | |
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 | |
Values of types marked with 'CannotApplyEqualityOperatorAttribute' should be compared using 'Equals()' |
Formatting (41 inspections)
Inspections in this category detect code formatting problems.
Inspection | |
---|---|
Incorrect blank lines (blank lines are missing elsewhere) | Disabled |
Incorrect blank lines (blank lines are redundant elsewhere) | Disabled |
Incorrect blank lines (incorrect number of blank lines near braces) | Disabled |
Incorrect indent (around child statement) | |
Incorrect indent (around declaration braces) | Disabled |
Incorrect indent (around expression braces) | Disabled |
Incorrect indent (around namespace braces) | Disabled |
Incorrect indent (around preprocessor directive) | Disabled |
Incorrect indent (around statement braces) | |
Incorrect indent (around switch statement) | Disabled |
Incorrect indent (incorrect indent size) | Disabled |
Incorrect indent (indent level is not restored) | Disabled |
Incorrect indent (missing indent/outdent elsewhere) | Disabled |
Incorrect indent (redundant indent/outdent elsewhere) | Disabled |
Incorrect indent (tabs/spaces mismatch) | Disabled |
Incorrect line breaks (around comma in lists) | Disabled |
Incorrect line breaks (around declaration braces) | Disabled |
Incorrect line breaks (around empty braces) | Disabled |
Incorrect line breaks (around expression braces) | Disabled |
Incorrect line breaks (around LINQ queries) | Disabled |
Incorrect line breaks (around parenthesis) | Disabled |
Incorrect line breaks (around statement braces) | Disabled |
Incorrect line breaks (line break is missing elsewhere) | Disabled |
Incorrect line breaks (line break is redundant elsewhere) | Disabled |
Incorrect line breaks (multiple statements on one line) | Disabled |
Incorrect line breaks (multiple type members on one line) | Disabled |
Incorrect spacing (around attributes) | Disabled |
Incorrect spacing (around braces) | Disabled |
Incorrect spacing (around colon) | Disabled |
Incorrect spacing (around comma) | Disabled |
Incorrect spacing (around generic brackets) | Disabled |
Incorrect spacing (around member access symbols) | Disabled |
Incorrect spacing (around operator symbols) | Disabled |
Incorrect spacing (around parenthesis) | Disabled |
Incorrect spacing (around semicolon) | Disabled |
Incorrect spacing (around square brackets within a statement) | Disabled |
Incorrect spacing (between keyword and parenthesis) | Disabled |
Incorrect spacing (multiple spaces are prohibited) | Disabled |
Incorrect spacing (space is missing elsewhere) | Disabled |
Incorrect spacing (space is redundant elsewhere) | Disabled |
Incorrect spacing (tabs are prohibited here) | Disabled |
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.
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 | |
Inline temporary variable | |
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' | Disabled |
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 | Disabled |
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 compound assignment | |
Use deconstruction | |
Use deconstruction to swap variables | |
Use discard assignment | |
Use index from end expression | |
Use 'nameof' expression to reference name | |
Use 'nameof' expression to reference name in part of the string literal | Disabled |
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 | Disabled |
Use raw string | |
Use string interpolation expression | |
Use type annotation syntax | |
Use unsigned right shift operator '>>>' | |
Use UTF-8 string literal | |
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 |
Potential Code Quality Issues (211 inspections)
This category includes inspections that detect critical issues (code smells), mostly with Error or Warning level.
Inspection | |
---|---|
'?:' expression has identical true and false branches | |
[MustDisposeResource] annotation is not inherited from the base constructor and should be placed explicitly | |
[ThreadStatic] does not work with instance fields | |
A suppressed nullable warning might hide an underlying problem | Disabled |
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) | |
Conflicting CQRS attribute | |
Constant shift expression with non-zero operands results in a zero value | |
Co-variant array conversion | |
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 | |
Do not use object initializer for 'using' variable (object initializer expression may throw exception while initializing 'using' variable) | |
Duplicated switch section bodies | |
Element is localizable | |
Empty general catch clause | |
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 | |
Extract common code | |
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 | Disabled |
Function is recursive on all execution paths | |
Function never returns | |
'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 member | |
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 | Disabled |
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 member | |
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' | Disabled |
Possible cyclic constructor call | |
Possible incorrect implementation of Double-Check Locking pattern. Possible multiple write access to checked field. | |
Possible incorrect implementation of Double-Check Locking pattern. Read access to checked field. | |
Possible infinite inheritance | |
Possible loss of fraction | |
Possible mistaken argument of type 'System.Type' | |
Possible mistaken 'GetType()' invocation | |
Possible multiple enumeration | |
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 impure struct method is called on readonly variable: struct value always copied before invocation | |
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 | Disabled |
'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 | |
Return value should be disposed but the method or function is not annotated with [MustDisposeResource] | |
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' expression and are handled via exception in default arm | |
Some values of the enum are not processed inside 'switch' statement | |
Some values of the enum are not processed inside 'switch' statement and are handled via default section | |
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 | |
Unidentified CQRS entity | |
Unknown Razor layout | |
Unknown Razor section | |
Usage of <inheritdoc /> is invalid | |
Use <inheritdoc /> on root level to inherit documentation from base candidate | Disabled |
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 | |
'value' parameter is not used | |
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.
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 is not used | |
Assignment results are fully discarded | |
Comparison to integral constant is useless | |
Conditional access qualifier expression is known to be null or not null | |
Conditional access qualifier expression is not null according to nullable reference types' annotations | |
'ContainsKey' call is redundant before adding the item to the dictionary | |
Double negation operator | |
Empty 'for' loop is redundant | |
Empty region | |
Explicit delegate creation expression is redundant | |
Expression is always 'null' | |
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 'abstract' modifier | |
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 'Attribute' suffix | |
Redundant 'base.' qualifier | |
Redundant boolean comparison | |
Redundant braces in collection initializer | |
Redundant 'case' label | |
Redundant 'case' label before default section | Disabled |
Redundant cast | |
Redundant catch clause | |
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 'else' keyword | |
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 name qualifier | |
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 directive | |
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 using directive | |
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 constructor | |
Empty destructor | |
Empty implementation of 'partial void' method is redundant | |
Empty namespace declaration | |
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 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 | |
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 member initializer | |
Redundant member override | |
Redundant method overload (non-private accessibility) | |
Redundant method overload (private accessibility) | |
Redundant 'partial' modifier on method declaration | |
Redundant 'partial' modifier on type declaration | |
Sealed member in sealed class | |
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 local variable | |
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) |