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

PHP CheckStyle: Can't configure indentation

I am trying to use phpcheckstyle. I can't figure out how to configure it for functional brackets on a new line (using 4 spaces for indentation): 1. class MyClass 2. { 3. public function __construct() 4. { 5. // do something 6. …
Elliot Chance
  • 5,526
  • 10
  • 49
  • 80
0
votes
1 answer

Checkstyle method name rule regexp modification

I am running Sonar and checkstyle has a regexp rule like this: ^[a-z][a-zA-Z0-9]*$ I would like to modify it so that one or more underscores are allowed. How would I change this? Thanks!
user1340582
  • 19,151
  • 35
  • 115
  • 171
0
votes
2 answers

Eclipse CheckStyle

Recently I added a new checkstyle (XML) file in Eclipse. After I ran mvn checkstyle:checkstyle, I saw a bunch of checkstyle errors in A.java. Then, in Eclipse, I right-clicked A.java, and picked "Apply Checkstyle Fixes." However, no changes were…
Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384
0
votes
7 answers

Best coding Style - Checking if a character is a valid character

I am coding a method that returns whether a given character is valid, which looks like this: - private static boolean isValid(char c) { return c == '.' || c == ',' || c == '+' || c == '/' || c == ';' || c == ':'; } Check style flagged this up…
Tarski
  • 5,360
  • 4
  • 38
  • 47
0
votes
2 answers

Publishing a checkstyle report in Jenkins

I have the following problem - I'm running a checkstyle ant task when building with Jenkins and the respective report DOES get produced, but the thing is that when the build finishes I get a message that there has been an error during the parsing…
asenovm
  • 6,397
  • 2
  • 41
  • 52
0
votes
2 answers

Netty compilation throws checkstyle error on windows

I did a git clone from github git://github.com/netty/netty.git followed by mvn clean install. However I got the following errors from maven checkstyle plugin C:\git\netty\common\src\main\java\io\netty\util\UniqueName.java:106: Line matches the…
Abe
  • 8,623
  • 10
  • 50
  • 74
0
votes
1 answer

Can checkstype use regex in "files from package" filter

The code generated by xjc.exe to create classes from an XML Schema has lots of Checkstyle warnings. I can use a Checkstyle "files from package" filter in a project to ignore the source generated by xjc.exe but I have to select each package…
sedge
  • 385
  • 1
  • 4
  • 15
0
votes
1 answer

Findbugs for Ant XML files

We have a pretty big project and ant xmls grow fast as hell. We already have different static code analysis tools integrated, and I am looking for something like checkstyle+findbugs, but for ANT XMLs, to validate the correctness of the file, maybe…
Alex Luberg
  • 247
  • 3
  • 10
0
votes
1 answer

Jenkins doesn't run a maven plugin (checkstyle) on the build process

I'm running a maven project using Jenkins. The project is using the checkstyle plugin to verify the java code and fail the build if errors are found. I've added the plugin to my parent pom file and added it to the "validate" phase. When running "mvn…
Omri
  • 1,058
  • 3
  • 14
  • 26
0
votes
1 answer

Disable Checkstyle rule for class names matching pattern

For classes ending with "**Setup", the default format rule of ClassName should be replaced with a rule allowing inner class names to start with a lowercase letter - if it extends another class. How can I do this? A concrete example: class…
user3001
  • 3,437
  • 5
  • 28
  • 54
0
votes
2 answers

CheckStyle Custom Check -- Retrieve All Parameter Names

I'm attempting to retrieve all parameter names in all methods found in a given source file using CheckStyle. Here is the relevant code: public int[] getDefaultTokens() { return new int[] { TokenTypes.METHOD_DEF}; } public void…
0
votes
1 answer

Static analysis of probable wrong responsibility

I started seeing lot of smalll private methods that takes in some object and solely interact with it, These methods should actually being added in wrong place, Which in reality should atleast be a static method in that class. I am actually looking…
vinothkr
  • 1,270
  • 12
  • 23
0
votes
1 answer

In Checkstyle, is it possible to warn at one value and error at another?

I'd like to configure checkstyle to have 2 levels of validation for certain rules. For example, for the "Maximum Line Length" rule, I'd like to have a severity of warn if the line length exceeds 120 characters, but escalate to a severity of error…
Snekse
  • 15,474
  • 10
  • 62
  • 77
0
votes
1 answer

How to use a regex replace to correct "Equals avoid Null" from checkstyle

EDIT : I edited my post at the end to give the regex I used Having sonar to monitor quality of a code is great, but on the downside, with crappy project, you have to correct a lot. My problem is that I need to correct about 500 "Equals avoid Null"…
Dolanor
  • 822
  • 9
  • 19
-1
votes
2 answers

Checkstyle: Results file not being generated.

I am running checkstyle in an ANT task:
jayunit100
  • 17,388
  • 22
  • 92
  • 167