This file provides guidelines for agentic coding agents working in this repository.
npm run build- Build the main library package (runs in packages/react-hotkeys-hook)npm run build:documentation- Build documentation sitenpm run -w packages/react-hotkeys-hook dev- Start development server for librarynpm run -w packages/react-hotkeys-hook build- Build library only (TypeScript + Vite)
npm run lint- Run Biome linter with auto-fix (applies to all packages)npm run format- Run Biome formatter (applies to all packages)npx @biomejs/biome lint --write packages- Lint with write directlynpx @biomejs/biome format --write packages- Format with write directly
npm run test- Run all tests (Vitest in packages/react-hotkeys-hook)npm run -w packages/react-hotkeys-hook test- Run tests in library packagenpm run -w packages/react-hotkeys-hook vitest run- Run tests once (no watch mode)npx vitest run --testNamePattern "test name"- Run single test matching patternnpx vitest run src/test/useHotkeys.test.tsx- Run specific test filenpx vitest run -t "should listen to key presses"- Run tests matching name
- Line width: 120 characters
- Indentation: Spaces (2 spaces)
- Quotes: Single quotes
- Semicolons: As needed (optional)
- Biome auto-organizes imports on save
- Use
import typefor type-only imports:import type { Hotkey } from './types' - Group imports: external React hooks first, then local modules
- Keep imports at top of file, grouped by purpose
- Use explicit type annotations for function parameters and returns
- Prefer
readonlyfor arrays that shouldn't be modified:readonly FormTags[] - Use
typeoverinterfacefor object types (this codebase usestype) - Use generic type parameters with constraints:
function foo<T extends HTMLElement>() - Use
as constfor literal types where appropriate - Use
@ts-expect-errorfor intentional type errors with explanation
- Variables and functions: camelCase (
isHotkeyEnabled,recordedKeys) - Components: PascalCase (
HotkeysProvider,BoundHotkeysProxyProvider) - Types: PascalCase (
HotkeyCallback,Options,HotkeysContextType) - Constants: UPPER_SNAKE_CASE (
FORM_TAGS_AND_ROLES) - Private/internal variables: Prefix with underscore (
_options,_deps)
- Use functional components with hooks
- Use
useCallbackfor event handlers and functions passed to children - Use
useReffor mutable refs and DOM elements - Use
useStatefor component state - Use
useEffectoruseLayoutEffectfor side effects - Prefer
useLayoutEffectoveruseEffectfor DOM mutations - Use TypeScript generics for refs:
useRef<T>(null) - Export default hooks for main API:
export default function useHotkeys()
- Use conditional checks instead of try-catch where possible
- Return early from functions on error conditions
- Use type guards:
isReadonlyArray(enabledOnTags) - Check for undefined/null before accessing properties
- Use optional chaining:
e.target?.isContentEditable
- Use TODO comments for future improvements:
// TODO: Make modifiers work with sequences - Use biome-ignore comments for intentional lint violations:
// biome-ignore lint/correctness/useExhaustiveDependencies - Avoid inline comments for obvious code
- Add comments for complex logic or non-obvious behavior
- Use console.warn for developer-facing warnings in production code
- Test files use
.test.tsxextension insrc/test/directory - Use
test()from vitest (notit()) - Use
expect()for assertions - Mock functions with
vi.fn() - Use
vi.useFakeTimers()for timer-related tests - Use
userEvent.setup()for user interactions - Test files in
src/test/, source insrc/lib/ - Use
renderHook()for testing hooks - Use
render()for testing components - Use
beforeEach()for setup - Use
.only()sparingly for debugging only (remove before commit)
- Main source:
packages/react-hotkeys-hook/src/lib/ - Tests:
packages/react-hotkeys-hook/src/test/ - Types: Defined in
src/lib/types.ts - Entry point:
src/lib/index.ts - Monorepo: Multiple packages in
packages/directory
- This is an ES modules project (type: "module" in package.json)
- Use
typeimports for type-only imports to reduce bundle size - Avoid parameter reassignment (Biome rule)
- Use single variable declarators (Biome rule)
- Avoid unnecessary else statements (Biome rule)
- Self-closing JSX elements (Biome rule)
- Use as const assertions for literal types (Biome rule)
- This project uses Vitest, not Jest
- Build system: Vite + TypeScript
- Testing environment: jsdom