Questions tagged [checkstyle]

Checkstyle is a static analysis tool for checking compliance of Java code to standards. It can be configured with various sets of coding standards. It is integrated in various other tools, such as IDEs (like Eclipse, NetBeans or IntelliJ), Maven, Gradle, or the continuous inspection platform SonarQube.

From the official website:

Overview

Checkstyle is a development tool to help programmers write Java code that adheres to a coding standard. It automates the process of checking Java code to spare humans of this boring (but important) task. This makes it ideal for projects that want to enforce a coding standard.

Checkstyle is highly configurable and can be made to support almost any coding standard. An example configuration file is supplied supporting the Sun Code Conventions. As well, other sample configuration files are supplied for other well known conventions.

A good example of a report that can be produced using Checkstyle and Maven can be seen here.

Features

Checkstyle can check many aspects of your source code. Historically it's main functionality has been to check code layout issues, but since the internal architecture was changed in version 3, more and more checks for other purposes have been added. Now Checkstyle provides checks that find class design problems, duplicate code, or bug patterns like double checked locking.

For a detailed list of available checks please refer to the Standard Checks page.

Links

1320 questions
217
votes
9 answers

Disable a particular Checkstyle rule for a particular line of code?

I have a Checkstyle validation rule configured in my project, that prohibits to define class methods with more than 3 input parameters. The rule works fine for my classes, but sometimes I have to extend third-party classes, which do not obey this…
yegor256
  • 102,010
  • 123
  • 446
  • 597
141
votes
5 answers

Why is package-info.java useful?

When I run CheckStyle over my Java project it says Missing package-info.java file. for some classes, but not all of them. I can't really figure out why this message appears only sometimes. Furthermore my project runs perfectly fine without the…
Socrates
  • 8,724
  • 25
  • 66
  • 113
132
votes
5 answers

Disable maven checkstyle

I want to execute a maven target but checkstyle errors forbids that. I have no time right now to correct checkstyle error (my checkstyle rules have been recently updated and I can't handle all of them right now). Is there a way to disable…
RandomCoder
  • 6,606
  • 6
  • 22
  • 28
126
votes
8 answers

Is SonarQube Replacement for Checkstyle, PMD, FindBugs?

We are working on a web project from scratch and are looking at the following static code analysis tools. Conventions (Checkstyle) Bad practices (PMD) Potential bugs (FindBugs) The project is built on Maven. Instead of using multiple tools for…
Johnny
  • 1,317
  • 2
  • 10
  • 6
94
votes
17 answers

Checkstyle vs. PMD

We are introducing static analysis tools into the build system for our Java product. We are using Maven2 so Checkstyle and PMD integration come for free. However it looks like there is a large overlap in functionality between these two tools, in…
John Stauffer
  • 16,150
  • 10
  • 40
  • 35
83
votes
3 answers

Ignoring of Checkstyle warnings with annotation @SuppressWarnings

I try to ignore or disable some useless warnings in eclipse by checkstyle with annotation @SuppressWarnings like How to disable a particular checkstyle rule for a particular line of code? but this don't work for me. Here is the…
Mark
  • 17,887
  • 13
  • 66
  • 93
75
votes
7 answers

Checkstyle: How to Resolve "Hidden Field" Error

I am getting this checkstyle error: 'serverURL' hides a field in this private static void setServerURL(final String serverURL) { Utility.serverURL = serverURL; } What could be the reason, and how to resolve it?
Romi
  • 4,833
  • 28
  • 81
  • 113
63
votes
9 answers

Empty new line at the end of the Java source files

In my current project, we always insert an empty new line at the end of the Java source files. We also enforce this with CheckStyle (with error level). I was searching for this topic for a long time, but unfortunately I can't find any convincing…
tenshi
  • 26,268
  • 8
  • 76
  • 90
63
votes
7 answers

How to suppress all checks for a file in Checkstyle?

I'm doing an override for a third party class and I want to suppress all checks for it (since I'm only keeping it around until the patch is accepted). Is there a way to suppress all checks for a file? I tried using "*" but that fails.
Alceu Costa
  • 9,733
  • 19
  • 65
  • 83
62
votes
12 answers

Checkstyle, Unable to create Root Module

I'm trying to configure Checkstyle in the project. I've added: apply plugin: 'checkstyle' checkstyle { // assign the latest checkstyle version explicitly // default version is very old, likes 5.9 toolVersion = '8.6' …
Dawid Hyży
  • 3,581
  • 5
  • 26
  • 41
57
votes
4 answers

Checkstyle Eclipse plugin doesn't work

I'm using eclipse checkstyle plugin with Juno Eclipse distribution. Anytime the code is checked for checkstyle error I get the following error: cannot initialize module TreeWalker - Unable to instantiate DoubleCheckedLocking Does anybody know how…
Alex Objelean
  • 3,893
  • 2
  • 27
  • 36
55
votes
6 answers

IntelliJ IDEA code format from checkstyle configuration

I've decided to contribute to android maven plugin. They use quite specific code style format. It will take some time for me to modify IDEA code format rules to satisfy their requirements. Fortunately there is checkstyle configuration. I've…
Eugen Martynov
  • 19,888
  • 10
  • 61
  • 114
53
votes
2 answers

Preventing checkstyle from running in a specific maven submodule

I would like to define a checkstyle run in a pom file, and have it run on all the submodules except certain specified ones. In other words, I need some sort of (which exists but applies to filenames) but which targets modules. Any idea…
Miquel
  • 15,405
  • 8
  • 54
  • 87
49
votes
6 answers

Excluding classes in Maven Checkstyle plugin reports

I have a Maven 2 project and I want to configure my Checkstyle report plugin so that only some of my classes are analysed. I have found the maven.checkstyle.excludes property, but despite passing this as a command line parameter (using…
Andrew Harmel-Law
  • 7,739
  • 12
  • 44
  • 55
48
votes
3 answers

Is there a static analysis tool like Lint or Perl::Critic for shell scripts?

Are there any shell (specifically bash or ksh) checkers that test shell scripts for style, best practices, naming conventions, etc? (Something like Lint for C, or Perl::Critic for Perl.) I know with ksh you can do syntax checking by running ksh -n…
BrianH
  • 7,932
  • 10
  • 50
  • 71
1
2 3
87 88