Ultracite Code Standards
Enforce strict code quality standards using **Ultracite**, a zero-config Biome preset that provides extremely fast Rust-based linting and formatting. This skill helps you write accessible, performant, type-safe, and maintainable code across JavaScript/TypeScript projects.
Overview
Ultracite provides automated code quality enforcement through Biome. When working on code, apply these standards to ensure consistency and catch common issues before they reach production.
Quick Commands
When you encounter code quality issues or need to format code:
**Auto-fix issues**: `npx ultracite fix`**Check for problems**: `npx ultracite check`**Diagnose setup**: `npx ultracite doctor`Core Principles to Apply
Focus on code that is **accessible, performant, type-safe, and maintainable**. Prioritize clarity and explicit intent over brevity.
Type Safety & Explicitness
When writing TypeScript code:
Add explicit types for function parameters and return values when they enhance clarityUse `unknown` instead of `any` when the type is genuinely unknownApply const assertions (`as const`) for immutable values and literal typesRely on TypeScript's type narrowing rather than type assertionsExtract magic numbers into named constants with descriptive namesModern JavaScript/TypeScript Patterns
Apply these modern patterns consistently:
Use arrow functions for callbacks and short functionsPrefer `for...of` loops over `.forEach()` and indexed `for` loopsUse optional chaining (`?.`) and nullish coalescing (`??`) for safer property accessUse template literals instead of string concatenationDestructure objects and arrays for cleaner assignmentsUse `const` by default, `let` only when reassignment is needed, never `var`Async & Promises
When working with asynchronous code:
Always `await` promises in async functions and use the return valueUse `async/await` syntax instead of promise chains for better readabilityHandle errors with try-catch blocks in async codeNever use async functions as Promise executorsReact & JSX Best Practices
When writing React components:
Use function components over class componentsCall hooks at the top level only, never conditionallySpecify all dependencies correctly in hook dependency arraysUse the `key` prop for elements in iterables (prefer unique IDs over array indices)Nest children between opening and closing tags instead of passing as propsNever define components inside other componentsUse semantic HTML and ARIA attributes for accessibility: - Provide meaningful alt text for images
- Use proper heading hierarchy (h1 → h2 → h3)
- Add labels for all form inputs
- Include keyboard event handlers alongside mouse events
- Use semantic elements (`<button>`, `<nav>`, `<header>`) instead of divs with roles
Error Handling & Debugging
Keep production code clean:
Remove `console.log`, `debugger`, and `alert` statements before committingThrow `Error` objects with descriptive messages, not strings or other valuesUse `try-catch` blocks meaningfully - avoid catching errors just to rethrow themPrefer early returns over nested conditionals for error casesCode Organization
Keep code maintainable:
Keep functions focused and under reasonable cognitive complexity limitsExtract complex conditions into well-named boolean variablesUse early returns to reduce nestingPrefer simple conditionals over nested ternary operatorsGroup related code together and separate concernsSecurity Guidelines
Protect against common vulnerabilities:
Add `rel="noopener"` when using `target="_blank"` on linksAvoid `dangerouslySetInnerHTML` unless absolutely necessaryNever use `eval()` or assign directly to `document.cookie`Always validate and sanitize user inputPerformance Optimization
Write efficient code:
Avoid spread syntax in accumulators within loopsUse top-level regex literals instead of creating them in loopsPrefer specific imports over namespace importsAvoid barrel files (index files that re-export everything)Use proper image components (e.g., Next.js `<Image>`) over `<img>` tagsFramework-Specific Guidance
**Next.js:**
Use Next.js `<Image>` component for imagesUse `next/head` or App Router metadata API for head elementsUse Server Components for async data fetching instead of async Client Components**React 19+:**
Use ref as a prop instead of `React.forwardRef`**Solid/Svelte/Vue/Qwik:**
Use `class` and `for` attributes (not `className` or `htmlFor`)Testing Standards
When writing tests:
Write assertions inside `it()` or `test()` blocksAvoid done callbacks in async tests - use async/await insteadNever commit `.only` or `.skip` in test codeKeep test suites reasonably flat - avoid excessive `describe` nestingBeyond Automated Linting
While Biome catches most issues automatically, focus your attention on:
1. **Business logic correctness** - Validate your algorithms and logic flows
2. **Meaningful naming** - Use descriptive names for functions, variables, and types
3. **Architecture decisions** - Component structure, data flow, and API design
4. **Edge cases** - Handle boundary conditions and error states thoughtfully
5. **User experience** - Consider accessibility, performance, and usability
6. **Documentation** - Add comments for complex logic, but prefer self-documenting code
File Scope
This skill applies to all TypeScript and JavaScript files: `**/*.{ts,tsx,js,jsx}`
Workflow Integration
Before committing code, always run:
```bash
npx ultracite fix
```
This ensures all automatically fixable issues are resolved and code is formatted consistently.