Stop fighting useless battles: automate code style, architecture compliance by Roberto Franchini

Automate code style and architecture compliance with tools like pre-commit, ArcUnit, and OpenRewrite to reduce useless battles, improve productivity, and enforce coding standards.

Key takeaways
  • Automate code style and architecture compliance to reduce useless battles and improve productivity.
  • Use tools like pre-commit, ArcUnit, and OpenRewrite to enforce coding standards, detect architectural violations, and perform automated refactoring.
  • Start small and gradually introduce automation to avoid overwhelming developers and causing resistance.
  • Use pre-commit hooks to run checks and enforce rules before committing code.
  • Utilize ArcUnit to analyze bytecode and identify architectural issues, such as cyclic dependencies or violations of layering principles.
  • Leverage OpenRewrite to perform automated refactoring and enforce coding best practices, such as removing unused imports or migrating from one logging framework to another.
  • Configure these tools to run on both local machines and CI systems to ensure consistent enforcement of rules.
  • Encourage developers to contribute to the definition and refinement of rules to foster a sense of ownership and collaboration.
  • Use a combination of automatic refactoring and manual review to strike a balance between automation and human oversight.
  • Consider using a dedicated workflow or CI job for automated refactoring to avoid conflicts with other tasks.
  • Explore the use of pre-commit and ArcUnit for other languages beyond Java, such as .NET or Python.
  • Continuously monitor and refine the rules and processes to ensure they remain effective and aligned with evolving best practices.