checkstyle

Checkstyle vs. PMD

 ̄綄美尐妖づ 提交于 2019-12-17 21:26:47
问题 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 terms of enforcing basic style rules. Is there a benefit from utilizing both of these? I don't want to maintain 2 tools if one will work. If we choose one, which one should we use and why? We are also planning on using FindBugs. Are there other static

Java CheckStyle usage

独自空忆成欢 提交于 2019-12-14 01:27:07
问题 I'd like to write my own Check using CheckStyle and incorporate this in my ant build.xml. The documentation doesn't seem to provide detailed instructions on how to do so. Does anyone have experience doing this, and if so, can they provide a HelloWorldCheck example along with the changes one needs in their build.xml to create a target that runs this? Here is a reference to my question on their sourceforge mail dist 回答1: Here is an example for writing an ant task to run checkstyle. You should

Checkstyle - How to exclude any file, but the ones ending with 'Impl.java', with a regex?

醉酒当歌 提交于 2019-12-13 21:27:19
问题 I have been thinking some time about this problem. I have a huge Maven multi module project and using build-tools I share a custom set of rules for all modules (no problem around here). The problem comes when I want to apply one rule to just one set of files in just one of the modules. By using checkstyle suppressions file I can easyly exclude all files that I don't want the rule to apply, but it has its limitations. Lets put this into an example: Files: a/b/c/d/FileImpl.java a/b/c/d/File

How to implement a Checkstyle Regexp rule in SonarQube

女生的网名这么多〃 提交于 2019-12-13 15:21:53
问题 In my team, we have switched from using Checkstyle and FindBugs to SonarQube, for many reasons, and particularly because of the dashboards, as they make it easier to have a global view of where we stand. However, in the process, we have lost a few useful checks that I am trying to convert / reimplement with SonarQube. In particular, our Java code (legacy and newer) is plagued by a use of several logging platforms/libraries: slf4j+logback, Commons Logging, Java Util Logging, etc. My use case

Checkstyle config used by Maven and Eclipse

余生长醉 提交于 2019-12-13 03:55:40
问题 I am try to use the same Checkstyle configuration file with both Maven and Eclipse. The module SuppressionCommentFilter works as expected in Eclipse, but Maven reports TreeWalker is not allowed as a parent of SuppressionCommentFilter If I move it from TreeWalker to Checker the error goes away, but Checkstyle does not process the ignore comments. I am using Checkstyle 8.12 with Eclipse, but have not found a way to use other than 6.18 with Maven. Since this module had been part of Checkstyle

Checkstyle not working

一世执手 提交于 2019-12-12 18:15:40
问题 I am new to maven and chekstyle, so need to ask some question... I want to use checkstyle in my maven based project, so in my pom.xml I have add the dependency <dependency> <groupId>checkstyle</groupId> <artifactId>checkstyle</artifactId> <version>2.4</version> </dependency> and also I have added the entry in plugin tag: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-checkstyle-plugin</artifactId> <version>2.4</version> <configuration> <enableRulesSummary>true<

Can the CheckStyle module “NeedBraces” work with nested if/else blocks?

♀尐吖头ヾ 提交于 2019-12-12 13:28:39
问题 We are using CheckStyle to enforce our style standards. One of the style rules we opted to include was the NeedBraces module. NeedBraces specifies that every block type statement (such as if , else , for ) must have opening and closing curly braces. However, as far as I can tell it isn't working entirely correctly. This example will trigger a CheckStyle error. if (true) { System.out.println("20"); } else System.out.println("30"); Because the else case doesn't have braces. However, the next

How to prevent fully qualified names in Java code

老子叫甜甜 提交于 2019-12-12 10:46:35
问题 Is it possible to check with checkstyle if a java project is using fully qualified names in the code. We want to prevent code like if (org.apache.commons.lang3.StringUtils.isBlank(name)) { .... .... } and want to enforce that packages are instead imported instead. Are there are other tools that can help us accomplish it? 回答1: As far as I know, Checkstyle cannot do this. However, there is a PMD rule called UnnecessaryFullyQualifiedName which may be worth a look. IntelliJ plugins for PMD exist,

Eclipse CheckStyle

百般思念 提交于 2019-12-12 04:33:02
问题 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 made. Please advise me on how to apply my checkstyle changes. Note: I do not have Eclipse configured to build. I only use it for changing code, and then I build using maven on the command-line. Thanks 回答1: I don't know what Eclipse plugin you use,

Checkstyle on class variable

旧街凉风 提交于 2019-12-12 03:35:31
问题 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 would give error on initializing it in the constructor. What's the catch? 回答1: It is a bad style to make private and static field accessible for modifications through setter. You have to do one of the following things: 1) make field x final and remove set method for it.