-
Notifications
You must be signed in to change notification settings - Fork 3
Preview/pmd #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Preview/pmd #49
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
reviews: | ||
path_filters: ["**/ruleset.xml","ruleset.xml", "**/bad.java", "bad.java"] |
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,24 @@ | ||||||||||||||||
public class BadExample { | ||||||||||||||||
|
||||||||||||||||
private int unusedField; | ||||||||||||||||
|
||||||||||||||||
public BadExample() { | ||||||||||||||||
// unnecessary constructor | ||||||||||||||||
} | ||||||||||||||||
Comment on lines
+5
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove unnecessary constructor. The default constructor adds no value and can be removed. - public BadExample() {
- // unnecessary constructor
- } 📝 Committable suggestion
Suggested change
🧰 Tools🪛 PMD (7.15.0)[Medium] 5-5: Avoid unnecessary constructors - the compiler will generate these for you (UnnecessaryConstructor) (Code Style) 🤖 Prompt for AI Agents
|
||||||||||||||||
|
||||||||||||||||
public void DOStuff() { | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Follow Java naming conventions for methods. Method names should start with a lowercase letter. - public void DOStuff() {
+ public void doStuff() { 🧰 Tools🪛 PMD (7.15.0)[High] 9-9: The instance method name 'DOStuff' doesn't match '[a-z][a-zA-Z0-9]*' (MethodNamingConventions) (Code Style) 🤖 Prompt for AI Agents
|
||||||||||||||||
try { | ||||||||||||||||
int FooBar = 1; | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Follow Java naming conventions for local variables. Local variable names should start with a lowercase letter. - int FooBar = 1;
+ int fooBar = 1; 📝 Committable suggestion
Suggested change
🧰 Tools🪛 PMD (7.15.0)[High] 11-11: The local variable name 'FooBar' doesn't match '^[a-z][a-zA-Z0-9]*$' (LocalVariableNamingConventions) (Code Style) 🤖 Prompt for AI Agents
|
||||||||||||||||
System.out.println("Start"); | ||||||||||||||||
|
||||||||||||||||
for (int i = 0; i < 30; i++) { | ||||||||||||||||
System.out.println("Line " + i); | ||||||||||||||||
} | ||||||||||||||||
} catch (Exception e) { | ||||||||||||||||
// silently ignored | ||||||||||||||||
} finally { | ||||||||||||||||
Comment on lines
+17
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid empty catch blocks. Empty catch blocks silently swallow exceptions, making debugging difficult. At minimum, log the exception. } catch (Exception e) {
- // silently ignored
+ // Log the exception or handle it appropriately
+ e.printStackTrace(); // Or use proper logging
} finally { 📝 Committable suggestion
Suggested change
🧰 Tools🪛 PMD (7.15.0)[Medium] 17-19: Avoid empty catch blocks (EmptyCatchBlock) (Error Prone) 🤖 Prompt for AI Agents
|
||||||||||||||||
return; // forbidden in finally block | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Never return from a finally block. Returning from a finally block suppresses any exceptions thrown in the try or catch blocks and can lead to unexpected behavior. } finally {
- return; // forbidden in finally block
+ // Cleanup code if needed, but no return statement
} 📝 Committable suggestion
Suggested change
🧰 Tools🪛 PMD (7.15.0)[Medium] 20-20: Avoid returning from a finally block (ReturnFromFinallyBlock) (Error Prone) 🤖 Prompt for AI Agents
|
||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ruleset name="CodeRabbit PMD Ruleset" | ||
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 | ||
http://pmd.sourceforge.net/ruleset_2_0_0.xsd" | ||
description="PMD rules aligned with CodeRabbit standards for general-purpose Java projects."> | ||
|
||
<!-- Keep existing valid rules --> | ||
<rule ref="category/java/bestpractices.xml/UnusedPrivateField"/> | ||
<rule ref="category/java/errorprone.xml/EmptyCatchBlock"/> | ||
<rule ref="category/java/errorprone.xml/ReturnFromFinallyBlock"/> | ||
<rule ref="category/java/codestyle.xml/UnnecessaryConstructor"/> | ||
|
||
<!-- Replace deprecated VariableNamingConventions with specific naming rules --> | ||
<rule ref="category/java/codestyle.xml/LocalVariableNamingConventions"> | ||
<properties> | ||
<property name="localVarPattern" value="^[a-z][a-zA-Z0-9]*$"/> | ||
</properties> | ||
</rule> | ||
|
||
<!-- Replace deprecated ExcessiveMethodLength with NcssCount --> | ||
<rule ref="category/java/design.xml/NcssCount"> | ||
<properties> | ||
<property name="methodReportLevel" value="25"/> | ||
<property name="classReportLevel" value="500"/> | ||
</properties> | ||
</rule> | ||
|
||
<!-- Optional: Add other specific naming convention rules --> | ||
<rule ref="category/java/codestyle.xml/FieldNamingConventions"/> | ||
<rule ref="category/java/codestyle.xml/MethodNamingConventions"/> | ||
<rule ref="category/java/codestyle.xml/ClassNamingConventions"/> | ||
|
||
</ruleset> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove unused private field.
The field
unusedField
is declared but never used in the class.- private int unusedField;
📝 Committable suggestion
🧰 Tools
🪛 PMD (7.15.0)
[Medium] 3-3: Avoid unused private fields such as 'unusedField'. (UnusedPrivateField)
(Best Practices)
🤖 Prompt for AI Agents