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

how can I achieve in Maven 'fan out complexity' rule with PMD static analysis tool

I am new to PMD tool with Maven, I have to define rules for some Cyclic Complexity, Fan Out Complexity, and Depth in method. I found solution for Cyclic Complexity, and Depth in method but i am not able to find direct rule class for Fan Out…
Sun
  • 3,444
  • 7
  • 53
  • 83
0
votes
1 answer

Best list of static analysis rules

How to achieve better code in-terms of style, practical issues, logical issues, duplicate code, cyclic issues. Could i know your best list of static analysis rules for 1. Java 2. JSP or JSF 3. JavaScript, JQuery... 4. css How to…
Sun
  • 3,444
  • 7
  • 53
  • 83
0
votes
0 answers

How to write new rules of PMD for eclipse using

i followed the PMD official docs to create a new rule of PMD.(actually, the docs is out of date and had misled me ) neverTheless,the new rule which i created can only use by pmd.bat.it can not worke in eclipse pmd plugin.who can tell me how to do ?…
MiddleBen
  • 22
  • 2
0
votes
1 answer

NoClassDefFoundError when checkstyle is running

I have written a new checkstyle check as a filescanner. I modeled my junits after the code I found in the checkstyle code. The junits run just fine and everything looks good. But then, I add the check to my project.
scphantm
  • 4,293
  • 8
  • 43
  • 77
0
votes
1 answer

Disable maven checkstyle, pmd for groovy sources in multimodule project

I have a multimodule maven project and I can't find a way to disable pmd, checktyle for groovy sources. I do run a command from the top level: mvn clean install pmd:pmd checktyle:checkstyle The structure of my project is: pom.xml -module1 src …
Capacytron
  • 3,425
  • 6
  • 47
  • 80
0
votes
2 answers

Customise maven checkstyle plugin

I'm trying to create custom checkstyle. Already have SNAPSHOT on sonatype however the test project where I'm trying to test it on is not able to pull depencency. Error is [INFO] Building TestProject 0.0.1 [INFO]…
peter_budo
  • 1,748
  • 4
  • 26
  • 48
0
votes
2 answers

how to fix illegal package import checkstyle warning

I am using "java.lang.reflect.Type" in web app project all working fine..but I am stuck with code review how to fix "java.lang.reflect.Type illegal package import " -checkstyle warning.. I am more intrested in explanation of this warning. Thanks
Gan
  • 624
  • 1
  • 10
  • 31
0
votes
2 answers

StackOverflowError with Checkstyle 4.4 RegExp check

Hello, Background: I'm using Checkstyle 4.4.2 with a RegExp checker module to detect when the file name in out java source headers do not match the file name of the class or interface in which they reside. This can happen when a developer copies a…
jtsampson
  • 218
  • 1
  • 11
0
votes
1 answer

How can I suppress only specific codes for specific checkstyle rules?

I'm trying to customize checkstyle checkers. For example, I want the MagicNumber checker to detect only constant 0 for all code patterns except for-statement. 'for statement' is allowed to use -1, 0 and 1. Could you let me know how I can customize…
500004dolkong
  • 725
  • 3
  • 12
  • 19
0
votes
1 answer

Eclipse java/ant checkstyle issue

While working on a project I need to format my Java code in a specific manner. If it is not formatted in correct way, the build will create problems: Correct way: public static void main(String[] args) { // Code } Incorrect way: //Check the…
0
votes
1 answer

Gradle : custom task executes only once

I have added checkstyle checks to my gradle bulid. The configuration is : checkstyle { configFile = new File("${project.projectDir}/config/checkstyle/sun_checks.xml") showViolations = false } checkstyleMain { doLast{ …
StKiller
  • 7,631
  • 10
  • 43
  • 56
0
votes
1 answer

Making GWT JSNI code legal to Checkstyle's TrailingComment metric

Checkstyle's TrailingComment module detects the following as an invalid trailing comment in line 001: 000 private native void doSomething()/*-{ 001 .. javascript code here .. 002 }-*/ Which is of course right, but I want to configure…
Miquel
  • 15,405
  • 8
  • 54
  • 87
0
votes
1 answer

Does Checkstyle false positive on resource files?

'Activating Checkstyle' on a project dishes out two violations for every of the (.wav, .png) resource file in my project : 1. File does not end with a newline. 2. File contains tab characters (this is the first instance). Normally, both of those…
0
votes
2 answers

Use checkstyle to require space on either side of equals

How do you set checkstyle to enforce the following: int i = 0; if(i == 0) { // do something } if(i > 0) { // do something } instead of: int i=0; if(i==0) { // do something } if(i>0) { // do something }
Jay
  • 19,649
  • 38
  • 121
  • 184
0
votes
2 answers

Restriction on J2SE inbuilt method

As per my company rule I can not use stop() of thread For that I want something like when I use stop(), eclipse should shows error/warning It is difficult to achieve by using checkstyle and PMD.