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
0
votes
1 answer

sonar-maven3-plugin to analyze a multi-language project using a customer checkstyle file

My project has a .checkstyle file created using Eclipse that references a checkstyle file held at a svn url. Below is an example of how the file is referencing the external URL:
Mike Van
  • 1,048
  • 7
  • 26
0
votes
1 answer

Can't Install Eclipse Juno CheckStyle Plugin

I heard that a good plugin for metrics for Java Eclipse was the CheckStyle plugin. So I try and follow their instructions on how to install it, but I keep getting the following: Can someone kindly point out how I can fix this problem? Thank You.
J86
  • 14,345
  • 47
  • 130
  • 228
0
votes
2 answers

Checkstyle working differently for same condition

On applying check style i am getting " hides a field" if the name of formal and actual parameters are same. private String limitedDimensionId; /** * Sets the limited dimension id. * * @param limitedDimensionId * the new limited…
Farrukh Chishti
  • 7,652
  • 10
  • 36
  • 60
0
votes
3 answers

Checkstyle on class variable

Check style says that for a private class variable "must be declared final". class Test { private int x=1; public void set(int x) { this.x = x; } } In the above case it calls to declare x as final however declaring x as final…
Farrukh Chishti
  • 7,652
  • 10
  • 36
  • 60
0
votes
1 answer

Was the FileTypesFilter deprecated in eclipse-cs 5.6 plugin?

I recently noticed that my checkstyle configuration which I thought used to only check .java files was no longer doing so:
Bradley
  • 1,644
  • 3
  • 15
  • 24
0
votes
4 answers

Checkstyle and Jenkins: check modified/added lines in SVN commit

We have big-old Java project with a lot of legacy code. Now we have code conventions and Checkstyle rules to check it. We want to configure Jenkins job, which runs after every commit to SVN, to check, if modified/added lines are not violate any our…
dds
  • 2,335
  • 1
  • 31
  • 45
0
votes
1 answer

Checkstyle DetailAST, StringLiteral

public void visitToken(DetailAST aAST) {} I am trying to write a custom checkstyle rule. I am interested in the TokenTypes.STRING_LITERAL. The problem with this approach is, A string might be a concatenated string, StringBuffer, StringBuilder or…
AchuSai
  • 93
  • 1
  • 1
  • 6
0
votes
1 answer

Is there a checkstyle plugin for blacklisting words

Does someone know of a checkstyle plugin that can be configured with a set of words, and will mark all occurences of those words as warnings (in identifiers or in string values) ? The project we're working on requires that all code is in english.…
ARRG
  • 2,476
  • 17
  • 28
0
votes
1 answer

java.lang.ClassCastException: antlr.CommonToken cannot be cast to antlr.Token in Jenkins Checkstyle report

I am using checkstyle 5.5 for my project and building using Jenkins 1.462. My project builds successfully, but every java class in my project causes Checkstyle to create a high priority, TreeWalker error like below: ProductComparisonService.java:0,…
Aaron
  • 23,450
  • 10
  • 49
  • 48
0
votes
1 answer

Checkstyle Multiline regex for specific methods

I'm working on java checkstyle configuration in Eclipse. I need to add warning for all public methods that don't consist specific code in the first line. Example: public void doA(){ blabla(); //some code } public String doB(int i){ …
0
votes
2 answers

Setup checkstyle as part of java project build process

I am working on adding checkstyle to the build process of a java project. The results of the checkstyle will be later displayed on jenkins. I am using java7 & netbeans 7.2.1 For most of the work I am following the instructions on this page:…
static0886
  • 784
  • 9
  • 25
0
votes
2 answers

Checkstyle: Usage of ParenPad Check

I am new to Checkstyle though I use it mainly through the Maven Checkstyle plugin. I have a situation where I think Checkstyle lacks flexibility. It could be me, not being familiar with Checkstyle and its configuration options. The problem I have is…
Brett Walker
  • 3,566
  • 1
  • 18
  • 36
0
votes
3 answers

JavadocPackage usage in checkstyle

I am in the process of converting my checkstyle version 4.0 configurations to version 5.0. Hence, I have added the following to replace older "PackageHtml",
Abhishek
  • 6,862
  • 22
  • 62
  • 79
0
votes
4 answers

Checkstyle and bug detectors in Java

I need to perform some validations to some of my classes, for example: Every class field must be final or have one write per program (singleton); If the field it's not final, then it must be private; Every array must be private. I've already saw…
rnunes
  • 2,785
  • 7
  • 28
  • 56
0
votes
1 answer

Checkstyle Suppression For Just Annotations

Is there a way you can suppress a checkstyle rule only for the annotations in a file. Example I am getting a magic number in my annotation and I want to suppress magic number rule but only for the annotation not the whole file.
user1786822
  • 107
  • 1
  • 6