sedona icon indicating copy to clipboard operation
sedona copied to clipboard

A list of the top Java and / or Scala tools that can be wrapped as pre-commit hooks. Gemini can make mistakes, so double-check it

Open jbampton opened this issue 5 months ago • 4 comments

Here are 18 top Java and/or Scala tools that can be wrapped as pre-commit hooks, categorized by their primary function:

I. Code Formatting & Style:

  1. Spotless: A universal formatter that can integrate with many language-specific formatters (including Java and Scala ones). It's highly configurable and can automatically fix issues.
  2. Scalafmt: The official Scala code formatter, widely used for maintaining consistent code style in Scala projects.
  3. Checkstyle (Java): A highly configurable static code analysis tool used to check Java source code for adherence to coding standards (e.g., Google Java Style Guide, Sun Code Conventions).
  4. Palantir Java Format: An opinionated Java code formatter from Palantir, often used for a consistent style.
  5. Ktlint (Kotlin, JVM Ecosystem): While primarily for Kotlin, it's relevant in the JVM ecosystem for projects with mixed Kotlin and Java/Scala code, ensuring consistent formatting.

II. Linting & Static Analysis:

  1. PMD (Java): A static source code analyzer that reports on a range of potential problems, including common programming flaws, dead code, and suboptimal code.
  2. SpotBugs (Java): A program that uses static analysis to look for bugs in Java code. It's the spiritual successor to FindBugs.
  3. SonarLint (Java/Scala): The IDE extension of SonarQube, providing real-time feedback on code quality and security issues. While it typically runs in the IDE, its underlying analysis engine can be leveraged for pre-commit checks.
  4. Scalastyle (Scala): A style checker for Scala code, similar to Checkstyle for Java, enforcing coding conventions.
  5. WartRemover (Scala): A configurable code linting tool for Scala that can detect various "warts" or anti-patterns in code.
  6. Scalafix (Scala): A rewrite and linting tool for Scala that can perform intelligent analysis and automatically fix many issues, including refactorings.

III. Dependency Management & Security:

  1. OWASP Dependency-Check (Java/Scala): A Software Composition Analysis (SCA) tool that identifies known vulnerabilities in project dependencies by analyzing their Common Platform Enumeration (CPE) identifiers.
  2. Maven Enforcer Plugin (Maven projects): A Maven plugin that allows you to enforce various environmental constraints and best practices, including dependency convergence and banning undesirable dependencies. It can be integrated into pre-commit setups.

IV. Testing & Code Coverage (for quick checks):

  1. JUnit (Java): While full test suites are usually run in CI, simple unit tests critical to the committed changes can be run via a pre-commit hook to catch immediate regressions.
  2. ScalaTest (Scala): Similar to JUnit, allowing for quick execution of a subset of Scala tests.
  3. JaCoCo (Java): A code coverage library for Java. A pre-commit hook could enforce a minimum coverage percentage for modified files.

V. Other Useful Tools (General, but applicable to Java/Scala projects):

  1. GitLint: Ensures commit messages adhere to a defined format, which is crucial for good commit hygiene and automated changelog generation.
  2. TruffleHog/Gitleaks: Tools for finding secrets (e.g., API keys, passwords) accidentally committed to the repository. Highly recommended as a pre-commit hook for security.

jbampton avatar Jul 29 '25 06:07 jbampton

I would like to contribute by adding Checkstyle and Scalafmt as pre-commit hooks. These tools will help enforce code quality for Java and Scala files automatically when changes are committed. I plan to carefully configure these hooks to run the appropriate commands and test them thoroughly locally before creating a pull request.

Subham-KRLX avatar Jul 30 '25 09:07 Subham-KRLX

Spotless already formats Scala code. So we probably don't need Scalafmt.

Originally I just created this list but we need to double check each tool to see whether they apply.

https://github.com/diffplug/spotless

jbampton avatar Jul 30 '25 13:07 jbampton

Thanks for the clarification and link to the Spotless docs. I see that Spotless already covers Scala formatting so I will focus on adding Checkstyle next for Java code quality. Please let me know if you have other priorities or suggestions.

Subham-KRLX avatar Jul 30 '25 14:07 Subham-KRLX

I have opened PR #2189 to add a Checkstyle pre-commit hook for Java code quality as requested in this issue.

Subham-KRLX avatar Aug 02 '25 04:08 Subham-KRLX