Welcome! This document provides the essential guidelines, conventions, and workflows required to contribute to the Kokomo project.
Kokomo is a tool designed to augment the Go experience through precision code generation. Every contribution should prioritize:
- Minimalism: Only add what is necessary.
- Precision: Respect the AST and ensure generated code is idiomatic.
- Safety: Maintain the semantic integrity of the host package.
- Main Entry: The
mainpackage is at the repository root. It should only callinternal/cli/root.Run(). - Encapsulation: Use the
internal/directory for all implementation details. Only the following are exported:pkg/astutil- The plugin interface definitions.
- Functions/methods used for registering new plugins.
- Immutability: Prefer immutable types whenever possible.
- Style Guide: All code must conform to the Uber Go Style Guide.
- Commit Messages: Use Conventional Commits (e.g.,
feat:,fix:,docs:,refactor:). - Unit Testing:
- Use blackbox testing.
- For a file
foo.go, place tests infoo_test.gousingpackage foo_test.
- Integration Testing:
- Tests must cover a complete package hierarchy.
- Use the
gotest.tools/v3/goldenpackage to compare generated files against "golden" snapshots.
- Validation: Utilize field tags and
github.com/go-playground/validator/v10for data validation.
To maintain code quality and automated release integrity, all changes must follow this cycle:
- Local Development: Write code and run tests locally. Ensure all
pre-commithooks pass. - Pull Requests: All changes must be submitted via a Pull Request. Use
Squash mergefor all Pull Requests. Direct commits to themainbranch are prohibited. - Conventional Commits: Your PR commits must follow the Conventional Commits specification. This is critical because
release-pleaseuses these commit messages to automatically generate the changelog and determine version bumps (e.g.,feat:triggers a minor bump,fix:triggers a patch). - Review: Once a PR is opened, it will undergo automated linting and human review.
Kokomo uses an automated release process driven by release-please:
- Automated PRs: When you merge a PR that follows Conventional Commits,
release-pleasewill automatically create a "Release PR." - Changelog Generation: This Release PR will contain the updated
CHANGELOG.mdwith your changes categorized. - Finalizing: Merging the Release PR triggers the creation of a GitHub Release and a new Git Tag (e.g.,
v0.1.0).
Adding a new plugin follows these steps:
- Requirement Analysis: Define the target boilerplate and necessary AST inputs (fields, tags, etc.).
- Implementation:
- Implement the logic as a
cobra.Command. - Use
pkg/astutilto parse the target AST node. - Use the
jenpackage for all code generation. Never manually concatenate strings to build Go code. - Append code to the end of the generated file.
- Implement the logic as a
- Testing:
- Write unit tests for your parsing logic.
- Write integration tests that validate the output against a golden file.
We use asdf for version management and pre-commit for linting. Ensure you have run asdf install and pre-commit install --install-hooks before submitting your first PR.