CodeRush Code Issues types overview
There are different types of code issues that the Code Analysis technology provides. Each issue is highlighted with the appropriate color, and has its own icon, depending on its type. These types are:
- Dead Code
- Duplicate Code
- Code Smells
Errors are highlighted with a red wavy underline:
Code errors indicate that the code is invalid. Errors will definitely lead to the corresponding compile-time errors. Such errors indicate code defects (for example, syntax errors or rules violations of the programming language) that must be fixed before the code can be compiled. Seeing errors in the code editor allows you to fix them before starting the compile process, which may take significant time.
Examples of error code issues:
- Cannot create an instance of interface
- Static constructors must be parameterless
- Try statement without catch or finally
Warnings are highlighted with an orange wavy underline:
Warnings indicate syntactically valid but very suspicious code. A warning indicates you’ve done something bad, but not something that will prevent the code from being compiled. You should fix whatever causes warnings, since they often lead to other problems that will not be so easy to find.
Examples of warning code issues:
Hints are highlighted with a blue wavy underline:
Hints bring your attention to specific code blocks, and may suggest useful recommendations for their improvement and refactoring. These recommendations can be completely ignored; it is up to you to apply or skip them.
Examples of code hints:
Dead Code issues highlight the source code in gray:
Dead code means unnecessary, inoperative code that can be, or better yet, should be removed. You can significantly improve the source code quality by removing dead code. While the functionality won’t be changed, it will improve the internal quality – the readability of the source code. This will help in maintenance by decreasing the maintained code size, making it easier to understand the program, and preventing errors from being introduced.
There are several types of dead code, such as unused declarations (methods, properties, variables, parameters, return values, event handlers, constants, enumerations, classes, interfaces), unreachable code or statement, unused files, unused visual controls, etc.
Examples of Dead Code issues:
This type of a code issue highlights duplicated code. Duplicate code occurs two or more times, either within a single program or across different programs. Code duplication is considered an expensive practice that should be avoided because it complicates the maintenance and evolution of the software. The duplicate code is highlighted in purple.
Code Smells are highlighted in green:
A code smell is a hint that something might be wrong with your source code, but not necessarily. Smells are indicators of where your code might be hard to read, maintain or evolve, rather than things that are specifically wrong. A smell usually indicates that the code has low quality, for example: large complex methods, long parameters lists, duplicated code, huge classes, inconsistent names, etc.
Sometimes a code smell issue may also detect logic errors. A logic error occurs when your program simply doesn’t do what you want it to.
Examples of code smell issues:
You can tweak colors of code issues inside the Visual Studio Fonts and Colors configuration dialog.
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:
- Code Issues technology overview
- Code Issues types overview (current post)
- Code Issues visual presentation
- Code Issues fixes and suppression
- Code Issues navigation techniques
- Code Issues tool window
- Code Issues configuration and options
- Code Issues overall list
- Creating your own code issue