Skip to content

Latest commit

 

History

History
202 lines (142 loc) · 5.94 KB

CONTRIBUTING.md

File metadata and controls

202 lines (142 loc) · 5.94 KB

Contributing

Development Setup

Installation

  1. Install dependencies:
pnpm install
  1. Start the development server:
pnpm run dev
  1. Open your browser and navigate to http://localhost:5174

Scripts

  • pnpm run build - Build for production
  • pnpm run lint:fix - Run ESLint (and fix most of them automatically)
  • pnpm run test - Run unit tests
  • pnpm run test:e2e - Run e2e tests

Code Guidelines

No inline comments

Code should be self-documenting through clear naming. Don't explain what the code does with comments — use a well-named function or variable instead. Don't use {/* ... */} JSX comments either — the surrounding structure and data-testid attributes already convey intent. Only add a comment when documenting a non-obvious why (a hidden constraint, subtle invariant, or external workaround) that can't be expressed in a name — and put it in the JSDoc of the enclosing function, not inline.

// ❌
// get present players
const v = arr.filter(p => p.present); 

// ✅
const presentPlayers = arr.filter(p => p.present);

JSDoc style

Use JSDoc only on exported functions and classes. Describe why or what at a high level; omit @param and @returns tags — the type signatures and names are already self-documenting.

// ❌
/**
 * @param bracketSize Power-of-2 total slot count
 * @returns Array of rounds
 */
export function computeWBTree(bracketSize: number): BracketNode[][] { ... }

// ✅
/**
 * Computes a round-by-round bracket tree. Indices beyond teams.length are treated as byes.
 */
export function computeWBTree(bracketSize: number): BracketNode[][] { ... }

Node.js built-in imports

Always use the node: protocol prefix for Node.js built-in modules:

// ❌
import fs from 'fs';
import path from 'path';

// ✅
import fs from 'node:fs';
import path from 'node:path';

This applies to all built-ins: node:fs, node:path, node:url, node:crypto, etc.

TypeScript

  • Use interface for object shapes and class contracts.
  • Use type for unions, aliases, and simple literals.
interface Court {
  courtNumber: number;
  players: Player[];
}

type EngineType = 'sa' | 'sl';

Components

  • Functional components only, typed as React.FC<Props>.
  • Use named export const declarations, not default exports.
  • Define a Props interface directly above the component.
  • Destructure props in the function signature with defaults where relevant.
  • Prefix event handlers with handle (e.g. handleTeamClick).

No duplication

Before adding a helper, check whether it already exists:

  • Unit test utilities → tests/shared.ts, tests/setup.ts, tests/data/*,
  • E2E utilities → e2e/helpers.ts

Extend those files rather than copy-pasting setup logic across test files.

Unit tests vs E2E tests

Unit (tests/) E2E (e2e/)
Scope A single function or class A full user workflow
Framework Vitest + Testing Library Playwright
File suffix .test.ts .spec.ts
What to test Algorithm correctness, edge cases, state management UI interactions, cross-page navigation, real browser behaviour

Prefer unit tests for logic. Only reach for E2E when the value comes from testing the real browser.

Test file structure mirrors src/

src/engines/SimulatedAnnealingEngine.ts
tests/engines/SimulatedAnnealingEngine.test.ts

Unit test structure for classes

Wrap all tests for a class in a top-level describe('ClassName'). Inside it, use a nested describe('methodName') only when a method has more than one test. Single-test methods use a bare it directly inside the class describe.

describe('MyClass', () => {
  // single test → bare it, no nested describe
  it('someMethod returns the expected value', () => { ... });

  // multiple tests → nested describe
  describe('otherMethod', () => {
    it('returns X when ...', () => { ... });
    it('returns Y when ...', () => { ... });
  });
});

Use it.each or describe.each to limit duplication for test setup.

Internationalization (i18n)

Translations are defined in YAML files under src/i18n/locales/<lang>.yml, with en.yml as the source of truth. Nested YAML structures are flattened into dot-separated keys (e.g. app.title) at build time.

Usage in components

const { t } = useTranslation();
<h1>{t('app.title')}</h1>

Rules

  • Key parity: Every key in en.yml must exist in every other locale file — no missing keys, no extra keys.
  • Non-empty values: Values must be non-empty strings.
  • Build-time enforcement: The Vite YAML plugin validates parity and non-empty values on dev and build; mismatched keys fail compilation.

Adding a new locale

  1. Create src/i18n/locales/<lang>.yml matching all keys from en.yml.
  2. Register <lang> in SUPPORTED_LOCALES (src/i18n/detectLocale.ts), lazy imports (src/i18n/index.ts), and LANGUAGE_LABELS (src/i18n/LanguageSelector.tsx).
  3. Verify parity:
pnpm vitest run tests/i18n/localeParity.test.ts

Pull Request Guidelines

Commit messages

Use the imperative mood — write the message as a command:

# ❌
Added rotation button
Fixing bench fairness bug

# ✅
Add rotation button
Fix bench fairness bug

Prefer rebase to merge commits

Keep the history linear. Rebase your branch on main before marking a PR ready for review instead of merging main into your branch.

git fetch origin
git rebase origin/main