Skip to content

1.x: Add PMD #4064

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

Closed
wants to merge 6 commits into from
Closed

1.x: Add PMD #4064

wants to merge 6 commits into from

Conversation

vanniktech
Copy link
Collaborator

As discussed in #3164

Right now there are 10243 PMD rule violations.

For now I activated all checks though it is recommend to disable some of them.

}
}

build.dependsOn 'pmd'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: put newline at the end

screen shot 2016-06-22 at 1 10 26 pm

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I did the change through Sublime. I have it activated on my AS + IntelliJ. 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this task dependency for now, it fails the build

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please remove this for now. We'll run PMD in our IDEs and post fixes for it. Once the master builds without errors, this can be re-enabled.

@akarnokd akarnokd added the Build label Jun 22, 2016
<rule ref="rulesets/java/coupling.xml"/>
<rule ref="rulesets/java/design.xml"/>
<rule ref="rulesets/java/empty.xml"/>
<rule ref="rulesets/java/naming.xml"/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's disable it for now, mostly it complains about short variable names like s/etc

@akarnokd
Copy link
Member

I'm not against adding these checks, however, I see these problems:

  • rule violations doesn't allow running the tests
  • the build report is on the Travis server and thus not accessible

I don't want the rule violations to block merging the PRs but rather consider them as warnings, just like the coverage tests

@artem-zinnatullin
Copy link
Contributor

+1 to not fail the build for now, @vanniktech let's try to apply only useful warnings and remove all false-positives/non-needed.

@@ -0,0 +1,31 @@
<?xml version="1.0"?>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd put this solo file into the root directory.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Later there would be also one for Checkstyle & Findbugs so I thought a common folder would be adequate.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could live with these in the root:

/pmd.xml
/checkstyle.xml
/findbugs.xml

I'd create a separate dir only if you have like many extra files with odd filenames with underscores or something.

@akarnokd
Copy link
Member

Rules to disable:

  • CommentSize
  • CommentRequired - other tools will take care of this
  • LocalVariableCouldBeFinal
  • MethodArgumentCouldBeFinal
  • LawOfDemeter
  • BeanMembersShouldSerialize
  • AbstractNaming
  • AtLeastOneConstructor
  • ShortVariable
  • LongVariable
  • EmptyMethodInAbstractClassShouldBeAbstract
  • AvoidFieldNameMatchingTypeName
  • ConfusingTernary
  • CollapsibleIfStatements (maybe leave?)
  • AvoidUsingVolatile - this is a concurrency library after all
  • DefaultPackage
  • AvoidCatchingThrowable we have an error handling convention of throwIfFatal + signal otherwise
  • AvoidInstantiatingObjectsInLoops
  • OnlyOneReturn
  • TooManyMethods
  • AvoidReassigningParameters - oddly, reassigning avoids JIT problems around register allocation
  • GodClass
  • CompareObjectsWithEquals - we have reference equality checks deliberately
  • NullAssignment - ours are there for GC support
  • UseVarargs - Java 6 target
  • AvoidFieldNameMatchingMethodName
  • CyclomaticComplexity - unavoidable
  • AssignmentInOperand - looks concise and rarely ambiguous
  • StdCyclomaticComplexity
  • CallSuperInConstructor
  • ModifiedCyclomaticComplexity
  • AvoidLiteralsInIfCondition - to many false positives, such as checking a special array.length
  • NPathComplexity
  • AvoidDuplicateLiterals - reports arguments to @SuppressWarnings!
  • ExcessivePublicCount
  • ExcessiveClassLength
  • ShortClassName
  • UselessParentheses - I'd rather have these to avoid first-look ambiguity
  • GenericsNaming
  • DontImportSun - affects only UnsafeAccess though
  • AvoidDeeplyNestedIfStmts
  • ExcessiveMethodLength
  • ArrayIsStoredDirectly - few places, all acceptable
  • TooManyFields
  • AvoidThrowingNullPointerException - established convention
  • ExcessiveParameterList
  • DoNotUseThreads

With these disabled, I have around 500 violations that can be managed.

@akarnokd
Copy link
Member

@vanniktech
Copy link
Collaborator Author

@akarnokd should I manually disable them or use the configuration from the file you uploaded?

@akarnokd
Copy link
Member

I guess you don't want to walk through my list when you could just use the config file.

@vanniktech
Copy link
Collaborator Author

True. I updated it. 👍

@akarnokd
Copy link
Member

This PMD doesn't like the rule:

[ant:pmd] net.sourceforge.pmd.RuleSetNotFoundException: Can't find resource 'rulesets/ecmascript/basic.xml' for rule 'AssignmentInOperand'.  Make sure the resource is a valid file or URL and is on the CLASSPATH. Here's the current classpath: 

@vanniktech
Copy link
Collaborator Author

Now it seems like Travis kills our gradle :(

@akarnokd
Copy link
Member

Error 137 is typically due to out-of-memory situation

@akarnokd
Copy link
Member

Did some experiments in my own: #4068. Should print some of the violations into the build log.

@vanniktech
Copy link
Collaborator Author

Yeah also yours seems to be running on Travis. If you want you can close this one in favor of #4068

@akarnokd
Copy link
Member

Sure, thanks for your experiments!

@akarnokd akarnokd closed this Jun 22, 2016
@vanniktech vanniktech deleted the 1.x_pmd branch July 23, 2018 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants