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

How to write a custom checkstyle check to verify content of XML file?

I'm wondering is it posssible to write a custom checkstyle check that checks a file other then java source? For instance from src/main/resources? fiels like a liquibase changeset (it is a XML file)? *I do not have liquibase PRO licence to write my…
tomasz-mer
  • 3,753
  • 10
  • 50
  • 69
-1
votes
1 answer

Missing Ctor sonar issue with Lombok

I have gradle(6.9) springboot(2.7.0) project with following dependecy compileOnly 'org.projectlombok:lombok:1.18.22' annotationProcessor 'org.projectlombok:lombok:1.18.22' testCompileOnly 'org.projectlombok:lombok:1.18.22' testAnnotationProcessor…
-1
votes
1 answer

Is SonarQube sufficient for static code reviews?

My applications are based on Java, Kotlin and React. Besides SonarQube there are other popular tools like: Amazon CodeGuru helps you improve code quality and automate code reviews by scanning and profiling Java and Python applications. CodeGuru…
-1
votes
1 answer

Warning "Consider using varargs for methods or constructors which take an array the last parameter"

I have a method similar to below with the same array type (Java), and I get the below warning from PMD when the checks are run. How do I resolve it? public static double calculateSum(Double[] numArray) { .... } PMD warning: Consider using…
Oasis001
  • 79
  • 2
  • 17
-1
votes
1 answer

I got checkstyle warning: WhitespaceAround: WhitespaceAround: '{' is not preceded with whitespace

When I build my project, So I got this checkstyle warning : WhitespaceAround: WhitespaceAround: '{' is not preceded with whitespace. Can you please help me to remove this warning. public List createEntities(Long connectorId,…
-1
votes
1 answer

How to restrict the @parma of javadoc to have comments in checkstyle

How to restrict the @parma of javadoc to have comments in checkstyle such as /** * text * @param args //Error reported here, must have comment */ public static void main(String[] args) {}
-1
votes
1 answer

Avoiding checkstyle MagicNumber error when filling object with magic numbers

I use magic numbers in class member initialization: private static final RangeMap MY_MAP = new ImmutableRangeMap.Builder() .put(Range.closed(10, 31), "random string 1") .put(Range.closed(32, 36),…
Michal Špondr
  • 1,337
  • 2
  • 21
  • 44
-1
votes
1 answer

Where do I put the braces in this multi block statement?

public static int countPopular(int count0, int count1, int count2) { int result; if (count0 > count1 && count0 > count2) { result = 0; } else if (count1 > count0 && count1 > count2) { result = 1; } else if…
-1
votes
1 answer

I need Regex which ensure that there will be single white space between method signature and opening curly braces

I am writing checkstyle rules for my project where I want only one whitespace between method signature and opening curly braces. I have tried with existing maven-checkstyle-plugin but it is not working. public class CheckStyleDemo { public…
pradip318
  • 9
  • 3
-1
votes
1 answer

Checkstyle plugin for IntelliJ IDEA

Is there a specification that rules Checkstyle plugins across different Java development platforms? I work at a company that uses this one from eclipse: https://marketplace.eclipse.org/content/checkstyle-plug but I would like to try IntelliJ IDEA…
OneNoOne
  • 587
  • 7
  • 23
-1
votes
1 answer

Checkstyle for subclass of BaseEvents

I am using checkstyle plugin for Java. However I want to design a checkstyle that: subclass of BaseEvents should only have class variables as final.
Mohammed Rampurawala
  • 3,033
  • 2
  • 22
  • 32
-1
votes
1 answer

Regex for anything but 'package-info.java' for checkstyle suppression

I have a checkstyle check RegexpHeader which checks for a regular expression in every files in my source. However, I want to suppress the check for all the files except package-info files. The suppression.xml file has the following suppress…
-1
votes
1 answer

How to configure checkstyle rule in Jenkins

I have configured Check-style plugin in Jenkins. I wanted to know how can i provide custom check-style rule File(Rule.xml) to Jenkins. Can any one help on this
Ganesh Rao B
  • 461
  • 2
  • 8
  • 23
-1
votes
1 answer

How to code a checkStyle method in Java?

Our teacher asked us to make a method which takes a Class as a parameter then checks the fields and methods if they follow the rules of Checkstyle (Upper case, lower case, final attribute, etc.) He gave us a piece of code to start with but I don't…
MOULCHWA
  • 17
  • 4
-1
votes
1 answer

checkstyle regex is not working

This regex should find java classes witch no '@Configuration' word and more than one '@Inject' word. In java Matcher it works, but not in checkstyle.
jdorosz
  • 34
  • 5
1 2 3
87
88