Home > Code Analysis > CodeRush Code Issues overall list

CodeRush Code Issues overall list

February 11th, 2011 Leave a comment Go to comments

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 conditionallyThe initialization can be moved to an else block of the following conditional statement, and may result in more efficient code.
Can combine initialization with declarationThe initialization and declaration can be combined into a single statement, which may improve readability.
Can implement base type constructorsThe current type can implement constructors from a base type, which may be a sign of incomplete code.
Can inline temporary variableThe expression assigned to the temporary variable that is used only once can be inlined, which may improve readability.
Declaration can be a constantThe declaration can be made constant.
Delegate can be replaced with lambda expressionThe anonymous method expression can replaced with a lambda expression, which may improve readability.
Environment.NewLine can be usedThe 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-onlyThe field can be made read-only.
ForEach Action can be calledThe 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 usedThe explicitly-typed variable declaration can be an implicit one, which may improve readability.
Initializer can be usedThe instantiation and subsequent property assignments can be converted into an initializer expression, which is more compact and may improve readability.
Member can be staticThe instance member can be made static, which increases the scope for which it may be called.
Nested code can be flattenedThe 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 usedThe ternary expression can be expressed as a null coalescing operation, which may improve readability.
Partial class has only single partThe partial class has only one declaration part, and does not need to be declared as partial.
Partial method has only single partThe partial method has only a single declaration, and does not need to be declared as partial.
Property can be auto-implementedThe simple property can be more simply declared as auto-implemented, removing the backing store, which may improve readability.
Redundant delegate creationThe explicit delegate creation is redundant and can be removed, which may improve readability.
Redundant sealed modifierThe member resides inside a sealed class, and the redundant sealed modifier can be removed, which may improve readability.
Redundant constructorThe redundant constructor can be removed, which may improve readability.
Redundant String.Format callThe redundant String.Format call (having only one argument) can be removed, which may improve readability.
Redundant ToString() callThe ToString call is redundant and can be removed, which may improve readability.
String.Compare can be usedThe string comparison can be replaced with a String.Compare call, which may improve readability and offer additional options for comparison.
String.Format can be usedThe string composition can be converted into a single String.Format call, which can improve readability and prepare code for localization.
Ternary expression can be usedThe 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 fileThe 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 nameThe 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 qualifierThe type qualifier is redundant and can be removed, which may improve readability.
Empty case statementThe case statement is empty and can be removed.
Empty event handlerThe 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 namespace declarationThe namespace is empty and can be removed.
Redundant base constructor callThe call to the base constructor can be removed, which may improve readability.
Redundant base qualifierThe “base” qualifier is redundant and can be removed, which may improve readability.
Redundant destructorThe redundant destructor can be removed, which may improve readability.
Redundant else statementThe else statement is redundant and can be removed.
Redundant field initializationThe fields initialization is redundant and can be removed.
Redundant finally blockThe finally block is empty and can be removed.
Lambda parameter has redundant type specificationThe type specifier to the lambda expression parameter is redundant and can be removed, which may improve readability.
Redundant namespace referenceThe namespace reference is redundant and can be removed, which may improve readability.
Redundant private setterThe private setter simply assigns a value to the field and can be removed without side-effects, which may improve readability.
Redundant this qualifierThe “this” or “Me” qualifier is redundant and can be removed, which may improve readability.
Redundant type qualifierThe type qualifier is redundant and can be removed, which may improve readability.
Unused memberThe member has no references and can be removed, which may improve readability.
Unused variableThe variable has no references and can be removed, which may improve readability.
Unused setterThe property setter has no references and can be removed, which may improve readability.
Unused type parameterThe 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 valuesThe 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.
Default branch is missingThe switch or select statement is missing a default branch and may be unintentional.
Catch block is emptyThe catch block is empty and will suppress all errors. This may be a sign of incomplete code.
Member is not implementedThe member is not implemented and may be a sign of incomplete code.
Protected member in sealed type will be privateMembers in sealed types cannot have a protected visibility.
Undisposed localThe local variable implements the IDisposable interface and it is not disposed inside this method. This may be a sign of incomplete code.
Virtual member in constructorThe order in which constructors are called is different from the order in which virtual methods are called. It can produce unexpected results.

Errors

Issue nameDescription
Abstract member cannot be declared in nonabstract classThe class that holds this abstract member must be marked as abstract.
Abstract member cannot be privateThe abstract member is private. The visibility must be greater than private.
Abstract member cannot be marked as sealedThe abstract member is sealed (this is not allowed).
Abstract member cannot be marked as virtualThe abstract member is virtual (this is not allowed).
Abstract member cannot declare a bodyThe abstract member declares a member body.
Anonymous method cannot have ‘params’ parameterThe anonymous method contains a ‘params’ parameter.
Array elements cannot be of static typeElements of an array may not be of the static type.
Base type constructors are not implementedThe 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 classAttempting to construct an instance of an abstract class.
Cannot create an instance of interfaceInterfaces cannot be instantiated.
Cannot create an instance of static classAttempting to construct an instance of a static class.
Cannot declare instance member in a static classAn instance member exists inside this static class.
Cannot declare variable of static typeThe variable is of a static type.
Cannot inherit from sealed typeThe 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 classInheriting from a static class is not permitted.
Cannot override inherited sealed memberThe sealed member cannot be overridden.
Cannot yield in the body of a catch clauseYield statements are not permitted inside a catch clause body.
Cannot yield in the body of a finally clauseYield statements are not permitted inside a finally clause body.
Cannot yield in the body of a try block with a catch clauseYield statements are not permitted inside a try block with a catch clause.
Constant cannot be marked staticConstant may not be marked as static.
Constructor cannot call itselfConstructors may not include an initializer that calls itself.
Constructor must declare a bodyConstructors must declare a constructor body.
Control cannot leave the body of a finally clauseFlow redirection (e.g., through “return” or “goto” statements) are not permitted inside finally blocks.
Delegate cannot be marked staticDelegates may not be marked as static.
Destructor must declare a bodyDestructors must declare a destructor body.
Interface events cannot have add or remove accessorsInterface events must be declared without add or remove accessors.
Extension method cannot have a parameter array used with ‘this’ modifierThe first parameter to an extension method cannot be a parameter array.
Extension methods cannot have a pointer type used with ‘this’ modifierThe first parameter to an extension method must not be of pointer type.
Extension method must be defined in a non-generic static classThe class holding extension methods must be static and must not be generic.
Extension method must be defined in a top level static classThe class holding extension methods must be top level, and may not be nested.
Extern member cannot declare a bodyExternal members must be declared without a member body.
Generic class cannot derive from AttributeThe generic class may not derive from an attribute class.
Indexer cannot be staticIndexer properties must not be static.
Interface cannot contain constructorsConstructors are not permitted inside interfaces.
Interface member cannot have a definitionInterface members may not declare a body.
Interface expectedInterfaces may only descend from interfaces.
Keyword “base” is not valid in a static memberStatic members may not reference base members.
Keyword this/Me is not valid in a static memberSelf-referencing from static members is not possible.
Lambda expression cannot have ‘params’ parameterLambda expressions must have an unchanging number of parameters.
Member cannot be sealed because it is not an overrideThe “sealed” keyword is only permitted on overridden members.
Member must declare a body because it is not marked abstract or externMembers which are not abstract and not externally implemented must declare a member body.
Member names cannot be the same as their enclosing typeMembers names must not match the name of their enclosing type.
Method must have a return typeFunctions must have a return type.
Only class types can contain destructorsDestructors are only permitted inside class types.
Operator cannot be abstractOperators must be implemented.
Operator cannot have ‘params’ parameterOperators must have an unchanging number of parameters.
Operator must be declared static and publicOperators must be static and have a public visibility.
Operator must declare a bodyOperators not marked with the external modifier must declare a member body.
Overloaded unary operator takes one parameterImplicit and explicit unary operators must accept a single parameter.
Override member cannot be marked as newOverridden members cannot also be marked as new.
Override member cannot be marked as virtualOverridden members cannot also be marked as virtual.
Override member cannot change access rightsThe visibility of overridden members must match inherited visibility.
Parameter modifier ‘this’ should be the first parameter of extension methodAn 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 modifiersThis partial method has an invalid modifier (e.g., virtual, abstract, override, new, sealed, extern, or an access modifier).
Partial method cannot have out parametersOut parameters are not allowed inside partial methods.
Partial method must be declared within a partial class or partial structPartial methods can only reside inside a partial class or a partial structure.
Property cannot have void typeProperties must return a type that is not void.
Protected member cannot be declared in structProtected members are not allowed inside structs.
Sealed class cannot be abstractThis class is sealed and cannot also be abstract.
Static class cannot be abstractThis class is static and cannot also be abstract.
Static class cannot be sealedThis class is static and cannot also be sealed.
Static class cannot contain protected memberThis class is static and cannot also contain protected or protected internal members.
Static constructors cannot have access modifiersAccess modifiers are not allowed on static constructors.
Static constructors must be parameterlessParameters are not allowed on static constructors.
Struct cannot contain parameterless constructorConstructors inside structs must have at least one parameter.
The params parameter must be a single dimensional arrayThe ‘params’ parameter is invalid.
The params parameter must be the last parameter in a formal parameter listThe ‘params’ parameter must be the last parameter declared.
Try statement without catch or finallyThis try block is missing a corresponding catch or finally block.
Undeclared elementThis element is undeclared.
Virtual member cannot be privateVirtual members must have a visibility greater than private.
Virtual member cannot be declared in sealed classThe class is sealed and cannot contain virtual members.
Virtual member cannot be declared in structuresVirtual members are only allowed in types that can be descended from.

Code Smells

Issue name

Description

Case statement has incorrect range of integers expressionThis case statement’s range expression may be invalid (e.g., “Case 10-20″ rather than “Case 10 to 20″).
Complex MemberThis 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: 11.2 and up
VS IDEs: any
Updated: Dec/27/2011
ID: C070

Similar Posts:

  1. No comments yet. Be the first and leave a comment!
  1. No trackbacks yet.