Checkstyle
Encyclopedia
Checkstyle is a static code analysis
tool used in software development
for checking if Java
source code
complies with coding rules
.
adopted by a software development project can help to comply with good programming practices which improve the code quality, readability, re-usability, and reduce the cost of development. The performed checks mainly limit themselves to the presentation and don't analyze content, and do not confirm the correctness or completeness of the program. In practice, it can be fastidious to comply with all the style constraints, some of which could possibly harm the programming stages' dynamic; so, it may be useful to determine which level of check is needed for a certain type of program.
It permits to check for instance:
which can run inside a Java VM or as an Apache Ant
task. It can also integrate into an IDE
or other tools.
A Checkstyle plug-in can provide new functionalities, like:
Thus, the developer can directly access to the code parts highlighted by Checkstyle.
The current stable release is version 5.3 which is targeted towards the Java 5 language.
Static code analysis
Static program analysis is the analysis of computer software that is performed without actually executing programs built from that software In most cases the analysis is performed on some version of the source code and in the other cases some form of the object code...
tool used in software development
Software development
Software development is the development of a software product...
for checking if Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...
source code
Source code
In computer science, source code is text written using the format and syntax of the programming language that it is being written in. Such a language is specially designed to facilitate the work of computer programmers, who specify the actions to be performed by a computer mostly by writing source...
complies with coding rules
Programming style
Programming style is a set of rules or guidelines used when writing the source code for a computer program. It is often claimed that following a particular programming style will help programmers to read and understand source code conforming to the style, and help to avoid introducing errors.A...
.
Advantages and limits
The programming styleProgramming style
Programming style is a set of rules or guidelines used when writing the source code for a computer program. It is often claimed that following a particular programming style will help programmers to read and understand source code conforming to the style, and help to avoid introducing errors.A...
adopted by a software development project can help to comply with good programming practices which improve the code quality, readability, re-usability, and reduce the cost of development. The performed checks mainly limit themselves to the presentation and don't analyze content, and do not confirm the correctness or completeness of the program. In practice, it can be fastidious to comply with all the style constraints, some of which could possibly harm the programming stages' dynamic; so, it may be useful to determine which level of check is needed for a certain type of program.
Examples of available modules
Checkstyle defines a set of available modules, each of which provides rules checking with a configurable level of strictness (mandatory, optional...). Each rule can raise notifications, warnings, and errors.It permits to check for instance:
- JavadocJavadocJavadoc is a documentation generator from Sun Microsystems for generating API documentation in HTML format from Java source code.The "doc comments" format used by Javadoc is the de facto industry standard for documenting Java classes. Some IDEs, such as Netbeans and Eclipse automatically generate...
comments for classes, attributes and methods; - Naming conventions of attributes and methods;
- Limit of the number of function parameters, line lengths;
- Presence of mandatory headers;
- The use of packets imports, of classes, of scope modifiers and of instructions blocks;
- The spaces between some charactersCharacter (computing)In computer and machine-based telecommunications terminology, a character is a unit of information that roughly corresponds to a grapheme, grapheme-like unit, or symbol, such as in an alphabet or syllabary in the written form of a natural language....
; - The good practices of class construction;
- Duplicated code sectionsDuplicate codeDuplicate code is a computer programming term for a sequence of source code that occurs more than once, either within a program or across different programs owned or maintained by the same entity. Duplicate code is generally considered undesirable for a number of reasons...
; - Multiple complexity measurements, among which expressions.
Usage
Checkstyle is built in a JAR fileJAR (file format)
In software, JAR is an archive file format typically used to aggregate many Java class files and associated metadata and resources into one file to distribute application software or libraries on the Java platform.JAR files are built on the ZIP file format and have the .jar file extension...
which can run inside a Java VM or as an Apache Ant
Apache Ant
Apache Ant is a software tool for automating software build processes. It is similar to Make but is implemented using the Java language, requires the Java platform, and is best suited to building Java projects....
task. It can also integrate into an IDE
Integrated development environment
An integrated development environment is a software application that provides comprehensive facilities to computer programmers for software development...
or other tools.
A Checkstyle plug-in can provide new functionalities, like:
- overload syntax coloring or decorations in code editor;
- decorate the project explorer to highlight problem-posing resources;
- add warnings and errors outputs to the outputs.
Thus, the developer can directly access to the code parts highlighted by Checkstyle.
History
Checkstyle, originally developed by Oliver Burn back in 2001, is maintained by a team of several developers around the world.The current stable release is version 5.3 which is targeted towards the Java 5 language.
See also
- List of tools for static code analysis
- EclipseCS - Eclipse plugin for checkstyle.
- SevNTU-Checkstyle - extension for EclipseCS with number of check that are not part of checkstyle upstream.