Skip to content

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 #2189

@jbampton

Description

@jbampton

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.

Sub-issues

Metadata

Metadata

Assignees

Labels

improvementjavaPull requests that update Java code

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions