|
| 1 | +--- |
| 2 | +description: Ultracite Rules - AI-Ready Formatter and Linter |
| 3 | +globs: "**/*.{ts,tsx,js,jsx,json,jsonc,html,vue,svelte,astro,css,yaml,yml,graphql,gql,md,mdx,grit}" |
| 4 | +alwaysApply: false |
| 5 | +--- |
| 6 | + |
| 7 | +# Ultracite Code Standards |
| 8 | + |
| 9 | +This project uses **Ultracite**, a zero-config Biome preset that enforces strict code quality standards through automated formatting and linting. |
| 10 | + |
| 11 | +## Quick Reference |
| 12 | + |
| 13 | +- **Format code**: `npx ultracite fix` |
| 14 | +- **Check for issues**: `npx ultracite check` |
| 15 | +- **Diagnose setup**: `npx ultracite doctor` |
| 16 | + |
| 17 | +Biome (the underlying engine) provides extremely fast Rust-based linting and formatting. Most issues are automatically fixable. |
| 18 | + |
| 19 | +--- |
| 20 | + |
| 21 | +## Core Principles |
| 22 | + |
| 23 | +Write code that is **accessible, performant, type-safe, and maintainable**. Focus on clarity and explicit intent over brevity. |
| 24 | + |
| 25 | +### Type Safety & Explicitness |
| 26 | + |
| 27 | +- Use explicit types for function parameters and return values when they enhance clarity |
| 28 | +- Prefer `unknown` over `any` when the type is genuinely unknown |
| 29 | +- Use const assertions (`as const`) for immutable values and literal types |
| 30 | +- Leverage TypeScript's type narrowing instead of type assertions |
| 31 | +- Use meaningful variable names instead of magic numbers - extract constants with descriptive names |
| 32 | + |
| 33 | +### Modern JavaScript/TypeScript |
| 34 | + |
| 35 | +- Use arrow functions for callbacks and short functions |
| 36 | +- Prefer `for...of` loops over `.forEach()` and indexed `for` loops |
| 37 | +- Use optional chaining (`?.`) and nullish coalescing (`??`) for safer property access |
| 38 | +- Prefer template literals over string concatenation |
| 39 | +- Use destructuring for object and array assignments |
| 40 | +- Use `const` by default, `let` only when reassignment is needed, never `var` |
| 41 | + |
| 42 | +### Async & Promises |
| 43 | + |
| 44 | +- Always `await` promises in async functions - don't forget to use the return value |
| 45 | +- Use `async/await` syntax instead of promise chains for better readability |
| 46 | +- Handle errors appropriately in async code with try-catch blocks |
| 47 | +- Don't use async functions as Promise executors |
| 48 | + |
| 49 | +### Error Handling & Debugging |
| 50 | + |
| 51 | +- Remove `console.log`, `debugger`, and `alert` statements from production code |
| 52 | +- Throw `Error` objects with descriptive messages, not strings or other values |
| 53 | +- Use `try-catch` blocks meaningfully - don't catch errors just to rethrow them |
| 54 | +- Prefer early returns over nested conditionals for error cases |
| 55 | + |
| 56 | +### Code Organization |
| 57 | + |
| 58 | +- Keep functions focused and under reasonable cognitive complexity limits |
| 59 | +- Extract complex conditions into well-named boolean variables |
| 60 | +- Use early returns to reduce nesting |
| 61 | +- Prefer simple conditionals over nested ternary operators |
| 62 | +- Group related code together and separate concerns |
| 63 | + |
| 64 | +### Security |
| 65 | + |
| 66 | +- Add `rel="noopener"` when using `target="_blank"` on links |
| 67 | +- Avoid `dangerouslySetInnerHTML` unless absolutely necessary |
| 68 | +- Don't use `eval()` or assign directly to `document.cookie` |
| 69 | +- Validate and sanitize user input |
| 70 | + |
| 71 | +### Performance |
| 72 | + |
| 73 | +- Avoid spread syntax in accumulators within loops |
| 74 | +- Use top-level regex literals instead of creating them in loops |
| 75 | +- Prefer specific imports over namespace imports |
| 76 | +- Avoid barrel files (index files that re-export everything) |
| 77 | +- Use proper image components (e.g., Next.js `<Image>`) over `<img>` tags |
| 78 | + |
| 79 | +--- |
| 80 | + |
| 81 | +## Testing |
| 82 | + |
| 83 | +- Write assertions inside `it()` or `test()` blocks |
| 84 | +- Avoid done callbacks in async tests - use async/await instead |
| 85 | +- Don't use `.only` or `.skip` in committed code |
| 86 | +- Keep test suites reasonably flat - avoid excessive `describe` nesting |
| 87 | + |
| 88 | +## When Biome Can't Help |
| 89 | + |
| 90 | +Biome's linter will catch most issues automatically. Focus your attention on: |
| 91 | + |
| 92 | +1. **Business logic correctness** - Biome can't validate your algorithms |
| 93 | +2. **Meaningful naming** - Use descriptive names for functions, variables, and types |
| 94 | +3. **Architecture decisions** - Component structure, data flow, and API design |
| 95 | +4. **Edge cases** - Handle boundary conditions and error states |
| 96 | +5. **User experience** - Accessibility, performance, and usability considerations |
| 97 | +6. **Documentation** - Add comments for complex logic, but prefer self-documenting code |
| 98 | + |
| 99 | +--- |
| 100 | + |
| 101 | +Most formatting and common issues are automatically fixed by Biome. Run `npx ultracite fix` before committing to ensure compliance. |
0 commit comments