-
Follow Go conventions: Use
mage fix lintfor formatting (fallback:gofmt), and standard Go idioms -
Naming: Use clear, descriptive names for variables, functions, and types
-
Error handling: Always handle errors appropriately with context. Use the following pattern:
// ErrOperationFailed is a global error for operation failures var ErrOperationFailed = errors.New("operation failed") // someOperation returns an error func someOperation() error { return fmt.Errorf("failed to connect to service: %w", ErrOperationFailed) } // Example usage in a function func performOperation() error { err := someOperation() // Wrap the error with context if err != nil { return fmt.Errorf("performing operation: %w", err) } return nil }
-
Comments: Document exported functions, types, and complex logic
-
Package organization: Follow the existing package structure
-
String formatting: Prefer
%#qformat specifier for strings
- Linting: All code must pass
golangci-lintchecks (usemage check lintandmage fix lintto fix some issues automatically)- Avoid using
//nolintcomments unless absolutely necessary. If you must use it, specify the linter (e.g.,//nolint:golint).
- Avoid using
- Testing: New functionality requires unit tests
- Coverage: Maintain reasonable test coverage for critical paths
- Documentation: Update relevant documentation for user-facing changes
- Business logic: Place in
internal/packages - Command handlers: Keep minimal logic in
cmd/packages - Unit Tests: Co-locate with source files using
_test.gosuffix - Scenario Tests: Use
scenario/for scenario tests - Configuration: Use TOML format, provide defaults in
defaultconfigs/
- See azldev command guidelines for details on command structure and naming conventions.
- Use structured logging with the
slogpackage - Include relevant context in log messages
- Use appropriate log levels (Debug, Info, Warn, Error)