Coding Standards
Purpose: For contributors, provides language-specific style guides and linting rules.
Go (openCenter-cli)
| Rule | Enforcement |
|---|---|
| Formatting | gofmt -w . — must produce no diff |
| Naming | Exported identifiers use PascalCase; unexported use camelCase. Avoid single-letter names outside trivial loops. |
| Error handling | Always return or handle errors. Wrap with context: fmt.Errorf("loading config: %w", err) |
| Dependencies | Injected via constructors (internal/di/). No global mutable state. |
| Comments | Exported functions require doc comments explaining why, not what. |
| Struct tags | yaml for serialization, validate for go-playground/validator rules, json for JSON schema generation. |
| Testing | Every behavior change requires tests. Use testify/assert for assertions, gopter for property tests, godog for BDD. |
Run all checks:
mise run fmt
mise run test
mise run godog
Python (openCenter-AirGap)
| Rule | Enforcement |
|---|---|
| Formatting | black (line length 100, target Python 3.10+) |
| Type annotations | Required on all functions. mypy strict mode (disallow_untyped_defs = true). |
| Linting | pylint with project-specific config in pyproject.toml |
| Naming | snake_case for functions and variables, PascalCase for classes |
| Error handling | Use custom exceptions from exceptions.py. No bare except: clauses. |
| Imports | Standard library → third-party → local, separated by blank lines |
| Testing | pytest with strict markers. Property tests use Hypothesis. Coverage minimum 80%. |
Run all checks:
black --check src/ tests/
mypy src/
pylint src/opencenter_build/
pytest
TypeScript (headlamp-branding-plugin)
| Rule | Enforcement |
|---|---|
| Formatting | Prettier |
| Linting | ESLint with project config |
| Types | Strict TypeScript — avoid any without justification |
| Naming | camelCase for variables/functions, PascalCase for components/classes |
| Testing | Jest for unit tests |
| Package naming | @opencenter/headlamp-plugin-<name> |
Run all checks:
pnpm run format:check
pnpm run lint
pnpm test
Cross-cutting rules
These apply to all repositories:
- No secrets in code. Use environment variables or SOPS encryption.
- Pin all dependencies (lockfiles committed:
go.sum,bun.lock,pnpm-lock.yaml,Gemfile.lock). - Commits follow Conventional Commits:
feat:,fix:,docs:,chore:,test:. - PRs must pass all CI checks before merge.
- Dead code and debugging artifacts must be removed before merge.
- Comments explain why (constraints, tradeoffs), not what the code does.