Home > Code Analysis > CodeRush Code Issues overall list

CodeRush Code Issues overall list

February 11th, 2011

Here is the list of code issues shipped in the latest official version of CodeRush Pro. All issues are categorized by their type.

Hints

Issue name

Description

Can initialize conditionally The initialization can be moved to an else block of the following conditional statement, and may result in more efficient code.
Can combine initialization with declaration The initialization and declaration can be combined into a single statement, which may improve readability.
Can implement base type constructors The current type can implement constructors from a base type, which may be a sign of incomplete code.
Can inline temporary variable The expression assigned to the temporary variable that is used only once can be inlined, which may improve readability.
Declaration can be a constant The declaration can be made constant.
Delegate can be replaced with lambda expression The anonymous method expression can replaced with a lambda expression, which may improve readability.
Environment.NewLine can be used The carriage return line feed string can be converted to a call to the Environment.NewLine, which may improve readability and portability.
Field can be read-only The field can be made read-only.
ForEach Action can be called The code block of the List iteration can be converted to an anonymous method which can be passed as the Action delegate to the List<T>.ForEach method, which may improve readability.
Implicit variable can be used The explicitly-typed variable declaration can be an implicit one, which may improve readability.
Initializer can be used The instantiation and subsequent property assignments can be converted into an initializer expression, which is more compact and may improve readability.
Member can be static The instance member can be made static, which increases the scope for which it may be called.
Nested code can be flattened The conditional expression can be converted into a guard clause, allowing the nested code to be unindented, which may improve readability.
Null coalescing operation can be used The ternary expression can be expressed as a null coalescing operation, which may improve readability.
Partial class has only single part The partial class has only one declaration part, and does not need to be declared as partial.
Partial method has only single part The partial method has only a single declaration, and does not need to be declared as partial.
Property can be auto-implemented The simple property can be more simply declared as auto-implemented, removing the backing store, which may improve readability.
Redundant delegate creation The explicit delegate creation is redundant and can be removed, which may improve readability.
Redundant sealed modifier The member resides inside a sealed class, and the redundant sealed modifier can be removed, which may improve readability.
Redundant constructor The redundant constructor can be removed, which may improve readability.
Redundant String.Format call The redundant String.Format call (having only one argument) can be removed, which may improve readability.
Redundant ToString() call The ToString call is redundant and can be removed, which may improve readability.
String.Compare can be used The string comparison can be replaced with a String.Compare call, which may improve readability and offer additional options for comparison.
String.Format can be used The string composition can be converted into a single String.Format call, which can improve readability and prepare code for localization.
Ternary expression can be used The conditional statement can be converted to a ternary expression, which tends to be more compact and may improve readability.
Type can be moved to separate file The type can be moved to a separate file, reducing the number of types in this file. This may improve readability, and make it easier to find and work with types as application complexity increases.
Type name does not correspond to file name The type name does not match the file name, and can be renamed to produce a one-to-one correspondence. This may improve readability, and make it easier to find and work with types as application complexity increases.

Dead Code

Issue name

Description

Can remove type qualifier The type qualifier is redundant and can be removed, which may improve readability.
Empty case statement The case statement is empty and can be removed.
Empty event handler The event handler is empty and can be removed, which may improve readability, and may improve performance by a small (probably a non-perceivable) amount.
Empty finally block The finally block is empty and can be removed.
Empty namespace declaration The namespace is empty and can be removed.
Redundant base constructor call The call to the base constructor can be removed, which may improve readability.
Redundant base qualifier The “base” qualifier is redundant and can be removed, which may improve readability.
Redundant destructor The redundant destructor can be removed, which may improve readability.
Redundant else statement The else statement is redundant and can be removed.
Redundant field initialization The fields initialization is redundant and can be removed.
Lambda parameter has redundant type specification The type specifier to the lambda expression parameter is redundant and can be removed, which may improve readability.
Redundant namespace reference The namespace reference is redundant and can be removed, which may improve readability.
Redundant private setter The private setter simply assigns a value to the field and can be removed without side-effects, which may improve readability.
Redundant this qualifier The “this” or “Me” qualifier is redundant and can be removed, which may improve readability.
Redundant type qualifier The type qualifier is redundant and can be removed, which may improve readability.
Unused member The member has no references and can be removed, which may improve readability.
Unused declaration The declaration has no references and can be removed, which may improve readability.
Unused setter The property setter has no references and can be removed, which may improve readability.
Unused type parameter The type parameter to this generic class or method is not referenced within its scope and can be removed, which may improve readability.

Warnings

Issue name

Description

Case statements do not explicitly handle all enum values The switch or select statement handles only a subset of the possible enumeration values it’s checking for. This may be a sign of incomplete code.
Catch block is empty The catch block is empty and will suppress all errors. This may be a sign of incomplete code.
Class should implement IDisposable This issue appears when a class contains fields that implement IDisposable, but the class itself does NOT implement IDisposable.
Default branch is missing The switch or select statement is missing a default branch and may be unintentional.
Fields should be disposed This issue appears when fields implementing IDisposable are inside a class that also implements IDisposable, but those fields are NOT disposed.
Member is not implemented The member is not implemented and may be a sign of incomplete code.
Protected member in sealed type will be private Members in sealed types cannot have a protected visibility.
Undisposed local The local variable implements the IDisposable interface and it is not disposed inside this method. This may be a sign of incomplete code.
Virtual call in constructor The order in which constructors are called is different from the order in which virtual methods are called. It can produce unexpected results.

Errors

Issue name Description
Abstract member cannot be declared in nonabstract class The class that holds this abstract member must be marked as abstract.
Abstract member cannot be private The abstract member is private. The visibility must be greater than private.
Abstract member cannot be marked as sealed The abstract member is sealed (this is not allowed).
Abstract member cannot be marked as virtual The abstract member is virtual (this is not allowed).
Abstract member cannot declare a body The abstract member declares a member body.
Anonymous method cannot have ‘params’ parameter The anonymous method contains a ‘params’ parameter.
Array elements cannot be of static type Elements of an array may not be of the static type.
Base type constructors are not implemented The current type doesn’t implement non-default constructors from a base type, which may be a sign of incomplete code.
Cannot create an instance of abstract class Attempting to construct an instance of an abstract class.
Cannot create an instance of interface Interfaces cannot be instantiated.
Cannot create an instance of static class Attempting to construct an instance of a static class.
Cannot declare instance member in a static class An instance member exists inside this static class.
Cannot declare variable of static type The variable is of a static type.
Cannot inherit from sealed type The class inherits from a sealed type.
Cannot inherit from special class System.ValueType Inheriting from a value type is not permitted.
Cannot inherit from static class Inheriting from a static class is not permitted.
Cannot override inherited sealed member The sealed member cannot be overridden.
Cannot yield in the body of a catch clause Yield statements are not permitted inside a catch clause body.
Cannot yield in the body of a finally clause Yield statements are not permitted inside a finally clause body.
Cannot yield in the body of a try block with a catch clause Yield statements are not permitted inside a try block with a catch clause.
Constant cannot be marked static Constant may not be marked as static.
Constructor cannot call itself Constructors may not include an initializer that calls itself.
Constructor must declare a body Constructors must declare a constructor body.
Control cannot leave the body of a finally clause Flow redirection (e.g., through “return” or “goto” statements) are not permitted inside finally blocks.
Delegate cannot be marked static Delegates may not be marked as static.
Destructor must declare a body Destructors must declare a destructor body.
Interface events cannot have add or remove accessors Interface events must be declared without add or remove accessors.
Extension method cannot have a parameter array used with ‘this’ modifier The first parameter to an extension method cannot be a parameter array.
Extension methods cannot have a pointer type used with ‘this’ modifier The first parameter to an extension method must not be of pointer type.
Extension method must be defined in a non-generic static class The class holding extension methods must be static and must not be generic.
Extension method must be defined in a top level static class The class holding extension methods must be top level, and may not be nested.
Extern member cannot declare a body External members must be declared without a member body.
Format item index too large The format item index must be less than the number of arguments passed in to a String.Format call.
Generic class cannot derive from Attribute The generic class may not derive from an attribute class.
Indexer cannot be static Indexer properties must not be static.
Interface cannot contain constructors Constructors are not permitted inside interfaces.
Interface member cannot have a definition Interface members may not declare a body.
Interface expected Interfaces may only descend from interfaces.
Keyword base is not valid in a static member Static members may not reference base members.
Keyword this /Me is not valid in a static member Self-referencing from static members is not possible.
Lambda expression cannot have ‘params’ parameter Lambda expressions must have an unchanging number of parameters.
Member cannot be sealed because it is not an override The “sealed” keyword is only permitted on overridden members.
Member must declare a body because it is not marked abstract or extern Members which are not abstract and not externally implemented must declare a member body.
Member names cannot be the same as their enclosing type Members names must not match the name of their enclosing type.
Method must have a return type Functions must have a return type.
Only class types can contain destructors Destructors are only permitted inside class types.
Operator cannot be abstract Operators must be implemented.
Operator cannot have ‘params’ parameter Operators must have an unchanging number of parameters.
Operator must be declared static and public Operators must be static and have a public visibility.
Operator must declare a body Operators not marked with the external modifier must declare a member body.
Overloaded unary operator takes one parameter Implicit and explicit unary operators must accept a single parameter.
Override member cannot be marked as new Overridden members cannot also be marked as new.
Override member cannot be marked as virtual Overridden members cannot also be marked as virtual.
Override member cannot change access rights The visibility of overridden members must match inherited visibility.
Parameter modifier ‘this’ should be the first parameter of extension method An extension method’s first parameter must include the “this” modifier.
Partial method cannot have access modifiers or the virtual, abstract, override, new, sealed, or extern modifiers This partial method has an invalid modifier (e.g., virtual, abstract, override, new, sealed, extern, or an access modifier).
Partial method cannot have out parameters Out parameters are not allowed inside partial methods.
Partial method must be declared within a partial class or partial struct Partial methods can only reside inside a partial class or a partial structure.
Property cannot have void type Properties must return a type that is not void.
Protected member cannot be declared in struct Protected members are not allowed inside structs.
Sealed class cannot be abstract This class is sealed and cannot also be abstract.
Static class cannot be abstract This class is static and cannot also be abstract.
Static class cannot be sealed This class is static and cannot also be sealed.
Static class cannot contain protected member This class is static and cannot also contain protected or protected internal members.
Static constructors cannot have access modifiers Access modifiers are not allowed on static constructors.
Static constructors must be parameterless Parameters are not allowed on static constructors.
Struct cannot contain parameterless constructor Constructors inside structs must have at least one parameter.
The params parameter must be a single dimensional array The ‘params’ parameter is invalid.
The params parameter must be the last parameter in a formal parameter list The ‘params’ parameter must be the last parameter declared.
Try statement without catch or finally This try block is missing a corresponding catch or finally block.
Undeclared element This element is undeclared.
Virtual member cannot be private Virtual members must have a visibility greater than private.
Virtual member cannot be declared in sealed class The class is sealed and cannot contain virtual members.
Virtual member cannot be declared in structures Virtual members are only allowed in types that can be descended from.

Code Smells

Issue name

Description

Case statement has incorrect range of integers expression This case statement’s range expression may be invalid (e.g., “Case 10-20” rather than “Case 10 to 20”).
Complex Member This member is complex, and may be more useful and easier to read if broken down into smaller methods.

The actual list for your installation is available on the EditorCode IssuesCatalog options page in the Options Dialog: CodeRush Code Issues Catalog options page

This post is a part of post series about CodeRush Code Issues technology. To learn more about code issues, please refer to the appropriate topics:

  1. Code Issues technology overview
  2. Code Issues types overview
  3. Code Issues visual presentation
  4. Code Issues fixes and suppression
  5. Code Issues navigation techniques
  6. Code Issues tool window
  7. Code Issues configuration and options
  8. Code Issues overall list (current post)
  9. Creating your own code issue
—–
Products: CodeRush Pro
Versions: 12.1 and up
VS IDEs: 2008 and up
Updated: Nov/12/2012
ID: C070

Similar Posts: