Analyzers Library
- 7 minutes to read
The table below lists supported analyzers. Refer to the Static Code Analysis article for information on how to use them.
Code Complexity Analysis
ID | Title | Description | C# | VB |
---|---|---|---|---|
CRR0001 | Redundant sub-expressions in a binary operation | The binary operation for identical sub-expressions may contain a redundant expression. | ||
CRR0004 | If conditional (ternary) operator has identical branches | Both ternary expression branches are identical. | ||
CRR2007 | IIF function has identical resulting arguments | IIF arguments are identical. | ||
CRR0009 | Subsequent if-statements have identical conditions | Subsequent conditional statements with identical conditions can be combined into a single conditional statement. | ||
CRR0012 | Logical OR expression has opposite operands | The logical OR expression has opposite terms. This expression is redundant and can be omitted. | ||
CRR0015 | Logical OR expression redundancy | The logical OR operation in the expression may be redundant. | ||
CRR0019 | Expression contains redundant subsets | The expression contains at least one expression that is a logical subset of another. | ||
CRR0024 | Increase precision with a built-in constant or call | The number is a low-precision version of a common constant. Consider changing the number to the suggested reference. | ||
CRR0047 | The type can be moved to a separate file | The type can be moved to a separate file | ||
CRR0049 | Environment.NewLine can be used | Environment.NewLine can be used. Convert the “\r\n” string value to an Environment.NewLine call. | ||
CRR0050 | String.Compare can be used | String.Compare can be used. Use the String.Compare() instead of the == operator or “!=” operator. | ||
CRR0051 | String.IsNullOrEmpty can be used | String.IsNullOrEmpty can be used. Use the string.IsNullOrEmpty method call instead of an expression. | ||
CRR0052 | String interpolation can be used | String interpolation can be used. Convert an expression into string interpolation. |
Mistake Detection
ID | Title | Description | C# | VB |
---|---|---|---|---|
CRR0002 | Suspect variable reference in a for-loop condition | The for-loop’s condition expression may use an incorrect variable. | ||
CRR0003 | Suspect variable reference in the for-loop iterator section | The for-loop’s iterator section may use an incorrect variable. | ||
CRR0006 | Suspect variable reference in null-check following as-cast | The null comparison that follows the typecast may reference an incorrect variable. | ||
CRR0007 | String format item/argument mismatch | The string.Format arguments may not match specified format items. | ||
CRR0013 | The member always returns the same value | The method’s return statements appear to always return the same constant value. | ||
CRR0017 | Null check follows usage | The expression contains a variable that is checked for null after it is referenced. | ||
CRR0020 | Integral divide operation cast to float | The divide-by-integral operation is internally cast to the integral type and rounding a floating point value may produce unexpected results. | ||
CRR0027 | Possible System.NullReferenceException | The expression is not checked for null and can cause a System.NullReferenceException exception. | ||
CRR0028 | Empty event handler | This event handler is empty and can be deleted. | ||
CRR0040 | A code metric exceeds the specified threshold | The code element exceeds the specified metric threshold. | ||
CRR0048 | The type name does not correspond to the file name | The type name does not correspond to the file name | ||
CRR1000 | Name does not correspond to Naming Conventions | The name of the declaration contradicts the existing naming conventions. Use a different name or add a new naming rule. |
Async/Await
ID | Title | Description | C# | VB |
---|---|---|---|---|
CRR0029 | The ConfigureAwait(true) is called implicitly | You should always call the ConfigureAwait() explicitly because the default behavior may cause a deadlock and should be changed in most cases. | ||
CRR0030 | Redundant await | You can delete the await keyword. | ||
CRR0031 | The returned Task is null | The returned Task should never be null, use Task.FromResult() instead. | ||
CRR0033 | The void async method should be in a try/catch block | The async method which returns nothing should be in a try/catch block. Otherwise, that method’s exceptions may cause a crash. | ||
CRR0034 | The asynchronous method should contain the “Async” suffix | The asynchronous method should contain the “Async” suffix. | ||
CRR0035 | No CancellationToken parameter in the async method | The async method has no CancellationToken parameter. | ||
CRR0036 | The await Task.FromResult() expression is redundant | The await keyword is not required for the Task.FromResult expression. | ||
CRR0037 | Task.Wait is used in an async method | Use the Task.When instead of Task.Wait method in an async method. | ||
CRR0038 | The CancellationToken parameter is never used | You should use the CancellationToken in the async method’s body to break the task if cancellation is requested. | ||
CRR0039 | The await expression without cancellation token | The cancellation token should be passed into the await expression. | ||
CRR0041 | Use Task.Run instead of Task.Factory.StartNew | You should use the Task.Run method instead. |
Unused Code Detection
ID | Title | Description | C# | VB |
---|---|---|---|---|
CRR0005 | Expression value is always the same | An expression always resolves to the same value. | ||
CRR0008 | If-block matches else-block | Both if statement child blocks appear to be identical. | ||
CRR0010 | Exception without throw | Precede the instantiation with the throw keyword if you want to throw an exception (so other parts of the program can catch it). | ||
CRR0011 | Next if-statement has an identical condition that is never reached | The next if-statement has the same condition as the current one. However, this if-statement breaks the program flow and exits the method block. The next if-statement’s body is never reached. | ||
CRR0014 | The variable is assigned twice in succession | The variable receives two assignments in succession. The first assignment may not be needed. | ||
CRR0016 | Method call’s return value is ignored | The method call’s return value is not used. This may be unintentional. | ||
CRR0018 | Suspect assignment reversal | The assignment reversal is unusual and may be an attempt to bypass side-effects occurring between two assignment statements. This may also indicate brittle code, which cannot be easily maintained. | ||
CRR0021 | Subsequent else-if conditions are identical | Nested if-else conditions are equivalent. The code in the nested if-block may never be reached. | ||
CRR0022 | Unreachable conditional code block (a similar condition in the else branch) | The conditional expression appears to always evaluate to false. You should check the conditionals above for similar expressions that would prevent the current conditional from being evaluated to true. | ||
CRR0023 | Unnecessary conditional | The conditional expression appears to always evaluate to true. The conditional expressions above are likely to ensure that this conditional never evaluates to false. | ||
CRR0025 | Unreachable conditional code block (the inversed condition is already satisfied) | The inverse of the current expression is satisfied in a parent conditional - this expression resolves to false (rendering its code block is never reached). | ||
CRR0026 | Unused type member | The member is never used and can be deleted. | ||
CRR0042 | Unused parameter | This parameter is never used and can be deleted. | ||
CRR0043 | Unused type | This type appears to be never used and can be deleted. | ||
CRR0044 | Unused local variable | The local variable is never used and can be deleted. | ||
CRR0045 | Local variable can be replaced with discard | The local variable is never used and can be replaced with a discard. | ||
CRR0046 | Redundant field initialization | Remove the redundant initialization to improve code readability. |
Spell Check
ID | Title | C# | VB |
---|---|---|---|
CRRSP02[1] | A repeated word was found. | ||
CRRSP03[1] | A misspelled word was found in the file name. | ||
CRRSP04[1] | A misspelled word was found in the XML documentation comment. | ||
CRRSP05[1] | A misspelled word was found in the comment. | ||
CRRSP06[1] | A misspelled word was found in the string. | ||
CRRSP07[1] | A misspelled word was found in the verbatim string. | ||
CRRSP08[1] | A misspelled word was found in the public identifier. | ||
CRRSP09[1] | A misspelled word was found in the internal identifier. | ||
CRRSP10[1] | A misspelled word was found in the protected internal identifier. | ||
CRRSP11[1] | A misspelled word was found in the protected identifier. | ||
CRRSP12[1] | A misspelled word was found in the private identifier. | ||
CRRSP13[1] | A misspelled word was found in the local identifier. |
Footnotes
-
Open the quick actions menu and choose the Spell Checker to see a list of possible corrections.