Coding conventions¶
Conventions for writing code across all Jersal projects. These apply regardless of the specific framework or project.
Language preferences¶
| Priority | Language | Use case |
|---|---|---|
| Primary | TypeScript | Frontend, backend, tooling, scripting |
| Secondary | Python | Data processing, ML, infrastructure tooling (MkDocs) |
| Secondary | C# | When required by integration targets |
TypeScript is the default choice. Use Python or C# when there's a specific reason (e.g., a library ecosystem, integration requirement, or team expertise).
TypeScript¶
Strict mode¶
All TypeScript projects use strict mode. The tsconfig.json should include:
Module system¶
- Target:
ES2022or later - Module resolution:
bundler - Output: ES modules
Formatting and linting¶
To be established
Specific ESLint and Prettier configurations are being standardized. Until then, use the configurations provided by the project template.
Recommended baseline:
- Use consistent indentation (2 spaces for TypeScript)
- Prefer
constoverlet, avoidvar - Use explicit return types on exported functions
- Prefer named exports over default exports
Infrastructure code (Terraform)¶
HCL conventions¶
- Use
snake_casefor all Terraform identifiers (resources, variables, outputs) - Pin provider versions with pessimistic constraints (
~>) - Pin Terraform version with minimum constraint (
>=) - Use modules for any resource pattern that appears in more than one environment
- Validate variable inputs where possible (see
sku_namevalidation inpostgres-flex)
Variable defaults¶
- Provide sensible defaults for non-sensitive variables
- Never provide defaults for sensitive variables (passwords, tokens)
- Use
sensitive = truefor all secret variables
General principles¶
- Explicit over implicit -- Type annotations, named parameters, clear variable names
- Fail fast -- Validate inputs, use strict mode, catch errors early
- Small modules -- Keep modules, functions, and components focused on a single responsibility
- No dead code -- Remove unused imports, variables, and functions