Code Quality Standards
This guide covers code quality standards, testing practices, and technical requirements for Waldur HomePort.
Technical Standards
Architecture Principles
- Composition over inheritance - Use dependency injection
- Interfaces over singletons - Enable testing and flexibility
- Explicit over implicit - Clear data flow and dependencies
- Test-driven when possible - Never disable tests, fix them
Code Quality Requirements
- Every commit must:
- Compile successfully
- Pass all existing tests
- Include tests for new functionality
-
Follow project formatting/linting
-
Before committing:
- Run formatters/linters
- Self-review changes
- Ensure commit message explains "why"
Error Handling
- Fail fast with descriptive messages
- Include context for debugging
- Handle errors at appropriate level
- Never silently swallow exceptions
Development Guidelines
TypeScript Configuration
- Uses
@/*path mapping for internal imports - Strict TypeScript checking disabled for legacy compatibility
- Module resolution set to "Bundler" for Vite compatibility
Code Style
- ESLint with flat config format enforced with TypeScript, React, and accessibility rules
- Prettier for code formatting (2 spaces, semicolons, single quotes)
- Import ordering enforced with
@waldurimports grouped separately - SCSS/CSS linting with Stylelint
- Husky for git hooks and pre-commit checks
Check Code Style Tool Versions
1 2 3 | |
TypeScript and SDK Types
- Always prefer SDK types over custom types from
waldur-js-clientpackage - Import types using
typekeyword:import { type ComponentUsageCreateRequest } from 'waldur-js-client' - Common SDK types to use instead of custom interfaces:
ResourcePlanPeriod- for plan periods with componentsBaseComponentUsage- for component usage data in periodsComponentUsageCreateRequest- for usage submission request bodiesComponentUserUsageCreateRequest- for user usage submission request bodiesComponentUsage- for general component usage data- All marketplace API request/response types are available in the SDK
- When using React Final Form, use standard pattern:
<Field component={NumberField} /> - Convert between SDK string types and numbers when necessary (e.g.,
parseFloat(component.usage)) - Handle nullable SDK types properly with optional chaining (
period.value?.components)
Tooling
Essential Commands
Code Quality
yarn lint:check- Run ESLint checksyarn lint:fix- Fix ESLint issues automaticallyyarn format:check- Check code formatting with Prettieryarn format:fix- Auto-format code with Prettieryarn style:check- Check SCSS/CSS styles with Stylelintyarn deps:unused- Check for unused dependencies with Knipyarn tsc- Typescript type check
Dependency Management
yarn deps:unused- Find unused dependencies and exports with Knipyarn deps:circular- Check for circular dependencies with Madge
Tooling Standards
- Use project's existing build system
- Use project's test framework
- Use project's formatter/linter settings
- Don't introduce new tools without strong justification
Quality Assurance
Code Quality & Analysis
- Knip for unused dependency detection
- Madge for circular dependency analysis
- Lint-staged for pre-commit code formatting
- PostCSS with autoprefixer and cssnano for CSS optimization
Modern Development Practices
- ESM (ES Modules) throughout the codebase
- TypeScript with comprehensive typing
- Flat ESLint config format
- Husky git hooks for automated quality checks
- Yarn package management with lockfile integrity