into-md 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/CLAUDE.md +251 -0
- package/.claude/settings.json +15 -0
- package/.claude/settings.local.json +9 -0
- package/.cursor/hooks.json +10 -0
- package/.vscode/settings.json +53 -0
- package/AGENTS.md +284 -0
- package/CLAUDE.md +111 -0
- package/GEMINI.md +123 -0
- package/README.md +133 -0
- package/biome.jsonc +4 -0
- package/bun.lock +413 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.mjs +446 -0
- package/dist/index.mjs.map +1 -0
- package/docs/SPEC.md +201 -0
- package/package.json +39 -0
- package/src/cache.ts +79 -0
- package/src/converter.ts +96 -0
- package/src/extractor.ts +85 -0
- package/src/fetcher.ts +236 -0
- package/src/images.ts +27 -0
- package/src/index.ts +143 -0
- package/src/metadata.ts +30 -0
- package/src/tables.ts +80 -0
- package/src/types/jsdom.d.ts +10 -0
- package/src/utils.ts +28 -0
- package/tsconfig.json +29 -0
- package/tsdown.config.ts +14 -0
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
# Ultracite Code Standards
|
|
2
|
+
|
|
3
|
+
This project uses **Ultracite**, a zero-config preset that enforces strict code quality standards through automated formatting and linting.
|
|
4
|
+
|
|
5
|
+
## Quick Reference
|
|
6
|
+
|
|
7
|
+
- **Format code**: `bun x ultracite fix`
|
|
8
|
+
- **Check for issues**: `bun x ultracite check`
|
|
9
|
+
- **Diagnose setup**: `bun x ultracite doctor`
|
|
10
|
+
|
|
11
|
+
Oxlint + Oxfmt (the underlying engine) provides robust linting and formatting. Most issues are automatically fixable.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Core Principles
|
|
16
|
+
|
|
17
|
+
Write code that is **accessible, performant, type-safe, and maintainable**. Focus on clarity and explicit intent over brevity.
|
|
18
|
+
|
|
19
|
+
### Type Safety & Explicitness
|
|
20
|
+
|
|
21
|
+
- Use explicit types for function parameters and return values when they enhance clarity
|
|
22
|
+
- Prefer `unknown` over `any` when the type is genuinely unknown
|
|
23
|
+
- Use const assertions (`as const`) for immutable values and literal types
|
|
24
|
+
- Leverage TypeScript's type narrowing instead of type assertions
|
|
25
|
+
- Use meaningful variable names instead of magic numbers - extract constants with descriptive names
|
|
26
|
+
|
|
27
|
+
### Modern JavaScript/TypeScript
|
|
28
|
+
|
|
29
|
+
- Use arrow functions for callbacks and short functions
|
|
30
|
+
- Prefer `for...of` loops over `.forEach()` and indexed `for` loops
|
|
31
|
+
- Use optional chaining (`?.`) and nullish coalescing (`??`) for safer property access
|
|
32
|
+
- Prefer template literals over string concatenation
|
|
33
|
+
- Use destructuring for object and array assignments
|
|
34
|
+
- Use `const` by default, `let` only when reassignment is needed, never `var`
|
|
35
|
+
|
|
36
|
+
### Async & Promises
|
|
37
|
+
|
|
38
|
+
- Always `await` promises in async functions - don't forget to use the return value
|
|
39
|
+
- Use `async/await` syntax instead of promise chains for better readability
|
|
40
|
+
- Handle errors appropriately in async code with try-catch blocks
|
|
41
|
+
- Don't use async functions as Promise executors
|
|
42
|
+
|
|
43
|
+
### React & JSX
|
|
44
|
+
|
|
45
|
+
- Use function components over class components
|
|
46
|
+
- Call hooks at the top level only, never conditionally
|
|
47
|
+
- Specify all dependencies in hook dependency arrays correctly
|
|
48
|
+
- Use the `key` prop for elements in iterables (prefer unique IDs over array indices)
|
|
49
|
+
- Nest children between opening and closing tags instead of passing as props
|
|
50
|
+
- Don't define components inside other components
|
|
51
|
+
- Use semantic HTML and ARIA attributes for accessibility:
|
|
52
|
+
- Provide meaningful alt text for images
|
|
53
|
+
- Use proper heading hierarchy
|
|
54
|
+
- Add labels for form inputs
|
|
55
|
+
- Include keyboard event handlers alongside mouse events
|
|
56
|
+
- Use semantic elements (`<button>`, `<nav>`, etc.) instead of divs with roles
|
|
57
|
+
|
|
58
|
+
### Error Handling & Debugging
|
|
59
|
+
|
|
60
|
+
- Remove `console.log`, `debugger`, and `alert` statements from production code
|
|
61
|
+
- Throw `Error` objects with descriptive messages, not strings or other values
|
|
62
|
+
- Use `try-catch` blocks meaningfully - don't catch errors just to rethrow them
|
|
63
|
+
- Prefer early returns over nested conditionals for error cases
|
|
64
|
+
|
|
65
|
+
### Code Organization
|
|
66
|
+
|
|
67
|
+
- Keep functions focused and under reasonable cognitive complexity limits
|
|
68
|
+
- Extract complex conditions into well-named boolean variables
|
|
69
|
+
- Use early returns to reduce nesting
|
|
70
|
+
- Prefer simple conditionals over nested ternary operators
|
|
71
|
+
- Group related code together and separate concerns
|
|
72
|
+
|
|
73
|
+
### Security
|
|
74
|
+
|
|
75
|
+
- Add `rel="noopener"` when using `target="_blank"` on links
|
|
76
|
+
- Avoid `dangerouslySetInnerHTML` unless absolutely necessary
|
|
77
|
+
- Don't use `eval()` or assign directly to `document.cookie`
|
|
78
|
+
- Validate and sanitize user input
|
|
79
|
+
|
|
80
|
+
### Performance
|
|
81
|
+
|
|
82
|
+
- Avoid spread syntax in accumulators within loops
|
|
83
|
+
- Use top-level regex literals instead of creating them in loops
|
|
84
|
+
- Prefer specific imports over namespace imports
|
|
85
|
+
- Avoid barrel files (index files that re-export everything)
|
|
86
|
+
- Use proper image components (e.g., Next.js `<Image>`) over `<img>` tags
|
|
87
|
+
|
|
88
|
+
### Framework-Specific Guidance
|
|
89
|
+
|
|
90
|
+
**Next.js:**
|
|
91
|
+
|
|
92
|
+
- Use Next.js `<Image>` component for images
|
|
93
|
+
- Use `next/head` or App Router metadata API for head elements
|
|
94
|
+
- Use Server Components for async data fetching instead of async Client Components
|
|
95
|
+
|
|
96
|
+
**React 19+:**
|
|
97
|
+
|
|
98
|
+
- Use ref as a prop instead of `React.forwardRef`
|
|
99
|
+
|
|
100
|
+
**Solid/Svelte/Vue/Qwik:**
|
|
101
|
+
|
|
102
|
+
- Use `class` and `for` attributes (not `className` or `htmlFor`)
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## Testing
|
|
107
|
+
|
|
108
|
+
- Write assertions inside `it()` or `test()` blocks
|
|
109
|
+
- Avoid done callbacks in async tests - use async/await instead
|
|
110
|
+
- Don't use `.only` or `.skip` in committed code
|
|
111
|
+
- Keep test suites reasonably flat - avoid excessive `describe` nesting
|
|
112
|
+
|
|
113
|
+
## When Oxlint + Oxfmt Can't Help
|
|
114
|
+
|
|
115
|
+
Oxlint + Oxfmt's linter will catch most issues automatically. Focus your attention on:
|
|
116
|
+
|
|
117
|
+
1. **Business logic correctness** - Oxlint + Oxfmt can't validate your algorithms
|
|
118
|
+
2. **Meaningful naming** - Use descriptive names for functions, variables, and types
|
|
119
|
+
3. **Architecture decisions** - Component structure, data flow, and API design
|
|
120
|
+
4. **Edge cases** - Handle boundary conditions and error states
|
|
121
|
+
5. **User experience** - Accessibility, performance, and usability considerations
|
|
122
|
+
6. **Documentation** - Add comments for complex logic, but prefer self-documenting code
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
Most formatting and common issues are automatically fixed by Oxlint + Oxfmt. Run `bun x ultracite fix` before committing to ensure compliance.
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
# Ultracite Code Standards
|
|
130
|
+
|
|
131
|
+
This project uses **Ultracite**, a zero-config preset that enforces strict code quality standards through automated formatting and linting.
|
|
132
|
+
|
|
133
|
+
## Quick Reference
|
|
134
|
+
|
|
135
|
+
- **Format code**: `bun x ultracite fix`
|
|
136
|
+
- **Check for issues**: `bun x ultracite check`
|
|
137
|
+
- **Diagnose setup**: `bun x ultracite doctor`
|
|
138
|
+
|
|
139
|
+
Biome (the underlying engine) provides robust linting and formatting. Most issues are automatically fixable.
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## Core Principles
|
|
144
|
+
|
|
145
|
+
Write code that is **accessible, performant, type-safe, and maintainable**. Focus on clarity and explicit intent over brevity.
|
|
146
|
+
|
|
147
|
+
### Type Safety & Explicitness
|
|
148
|
+
|
|
149
|
+
- Use explicit types for function parameters and return values when they enhance clarity
|
|
150
|
+
- Prefer `unknown` over `any` when the type is genuinely unknown
|
|
151
|
+
- Use const assertions (`as const`) for immutable values and literal types
|
|
152
|
+
- Leverage TypeScript's type narrowing instead of type assertions
|
|
153
|
+
- Use meaningful variable names instead of magic numbers - extract constants with descriptive names
|
|
154
|
+
|
|
155
|
+
### Modern JavaScript/TypeScript
|
|
156
|
+
|
|
157
|
+
- Use arrow functions for callbacks and short functions
|
|
158
|
+
- Prefer `for...of` loops over `.forEach()` and indexed `for` loops
|
|
159
|
+
- Use optional chaining (`?.`) and nullish coalescing (`??`) for safer property access
|
|
160
|
+
- Prefer template literals over string concatenation
|
|
161
|
+
- Use destructuring for object and array assignments
|
|
162
|
+
- Use `const` by default, `let` only when reassignment is needed, never `var`
|
|
163
|
+
|
|
164
|
+
### Async & Promises
|
|
165
|
+
|
|
166
|
+
- Always `await` promises in async functions - don't forget to use the return value
|
|
167
|
+
- Use `async/await` syntax instead of promise chains for better readability
|
|
168
|
+
- Handle errors appropriately in async code with try-catch blocks
|
|
169
|
+
- Don't use async functions as Promise executors
|
|
170
|
+
|
|
171
|
+
### React & JSX
|
|
172
|
+
|
|
173
|
+
- Use function components over class components
|
|
174
|
+
- Call hooks at the top level only, never conditionally
|
|
175
|
+
- Specify all dependencies in hook dependency arrays correctly
|
|
176
|
+
- Use the `key` prop for elements in iterables (prefer unique IDs over array indices)
|
|
177
|
+
- Nest children between opening and closing tags instead of passing as props
|
|
178
|
+
- Don't define components inside other components
|
|
179
|
+
- Use semantic HTML and ARIA attributes for accessibility:
|
|
180
|
+
- Provide meaningful alt text for images
|
|
181
|
+
- Use proper heading hierarchy
|
|
182
|
+
- Add labels for form inputs
|
|
183
|
+
- Include keyboard event handlers alongside mouse events
|
|
184
|
+
- Use semantic elements (`<button>`, `<nav>`, etc.) instead of divs with roles
|
|
185
|
+
|
|
186
|
+
### Error Handling & Debugging
|
|
187
|
+
|
|
188
|
+
- Remove `console.log`, `debugger`, and `alert` statements from production code
|
|
189
|
+
- Throw `Error` objects with descriptive messages, not strings or other values
|
|
190
|
+
- Use `try-catch` blocks meaningfully - don't catch errors just to rethrow them
|
|
191
|
+
- Prefer early returns over nested conditionals for error cases
|
|
192
|
+
|
|
193
|
+
### Code Organization
|
|
194
|
+
|
|
195
|
+
- Keep functions focused and under reasonable cognitive complexity limits
|
|
196
|
+
- Extract complex conditions into well-named boolean variables
|
|
197
|
+
- Use early returns to reduce nesting
|
|
198
|
+
- Prefer simple conditionals over nested ternary operators
|
|
199
|
+
- Group related code together and separate concerns
|
|
200
|
+
|
|
201
|
+
### Security
|
|
202
|
+
|
|
203
|
+
- Add `rel="noopener"` when using `target="_blank"` on links
|
|
204
|
+
- Avoid `dangerouslySetInnerHTML` unless absolutely necessary
|
|
205
|
+
- Don't use `eval()` or assign directly to `document.cookie`
|
|
206
|
+
- Validate and sanitize user input
|
|
207
|
+
|
|
208
|
+
### Performance
|
|
209
|
+
|
|
210
|
+
- Avoid spread syntax in accumulators within loops
|
|
211
|
+
- Use top-level regex literals instead of creating them in loops
|
|
212
|
+
- Prefer specific imports over namespace imports
|
|
213
|
+
- Avoid barrel files (index files that re-export everything)
|
|
214
|
+
- Use proper image components (e.g., Next.js `<Image>`) over `<img>` tags
|
|
215
|
+
|
|
216
|
+
### Framework-Specific Guidance
|
|
217
|
+
|
|
218
|
+
**Next.js:**
|
|
219
|
+
- Use Next.js `<Image>` component for images
|
|
220
|
+
- Use `next/head` or App Router metadata API for head elements
|
|
221
|
+
- Use Server Components for async data fetching instead of async Client Components
|
|
222
|
+
|
|
223
|
+
**React 19+:**
|
|
224
|
+
- Use ref as a prop instead of `React.forwardRef`
|
|
225
|
+
|
|
226
|
+
**Solid/Svelte/Vue/Qwik:**
|
|
227
|
+
- Use `class` and `for` attributes (not `className` or `htmlFor`)
|
|
228
|
+
|
|
229
|
+
---
|
|
230
|
+
|
|
231
|
+
## Testing
|
|
232
|
+
|
|
233
|
+
- Write assertions inside `it()` or `test()` blocks
|
|
234
|
+
- Avoid done callbacks in async tests - use async/await instead
|
|
235
|
+
- Don't use `.only` or `.skip` in committed code
|
|
236
|
+
- Keep test suites reasonably flat - avoid excessive `describe` nesting
|
|
237
|
+
|
|
238
|
+
## When Biome Can't Help
|
|
239
|
+
|
|
240
|
+
Biome's linter will catch most issues automatically. Focus your attention on:
|
|
241
|
+
|
|
242
|
+
1. **Business logic correctness** - Biome can't validate your algorithms
|
|
243
|
+
2. **Meaningful naming** - Use descriptive names for functions, variables, and types
|
|
244
|
+
3. **Architecture decisions** - Component structure, data flow, and API design
|
|
245
|
+
4. **Edge cases** - Handle boundary conditions and error states
|
|
246
|
+
5. **User experience** - Accessibility, performance, and usability considerations
|
|
247
|
+
6. **Documentation** - Add comments for complex logic, but prefer self-documenting code
|
|
248
|
+
|
|
249
|
+
---
|
|
250
|
+
|
|
251
|
+
Most formatting and common issues are automatically fixed by Biome. Run `bun x ultracite fix` before committing to ensure compliance.
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
|
3
|
+
"typescript.tsdk": "node_modules/typescript/lib",
|
|
4
|
+
"editor.formatOnSave": true,
|
|
5
|
+
"editor.formatOnPaste": true,
|
|
6
|
+
"emmet.showExpandedAbbreviation": "never",
|
|
7
|
+
"[javascript]": {
|
|
8
|
+
"editor.defaultFormatter": "biomejs.biome"
|
|
9
|
+
},
|
|
10
|
+
"[typescript]": {
|
|
11
|
+
"editor.defaultFormatter": "biomejs.biome"
|
|
12
|
+
},
|
|
13
|
+
"[javascriptreact]": {
|
|
14
|
+
"editor.defaultFormatter": "biomejs.biome"
|
|
15
|
+
},
|
|
16
|
+
"[typescriptreact]": {
|
|
17
|
+
"editor.defaultFormatter": "biomejs.biome"
|
|
18
|
+
},
|
|
19
|
+
"[json]": {
|
|
20
|
+
"editor.defaultFormatter": "biomejs.biome"
|
|
21
|
+
},
|
|
22
|
+
"[jsonc]": {
|
|
23
|
+
"editor.defaultFormatter": "biomejs.biome"
|
|
24
|
+
},
|
|
25
|
+
"[html]": {
|
|
26
|
+
"editor.defaultFormatter": "biomejs.biome"
|
|
27
|
+
},
|
|
28
|
+
"[vue]": {
|
|
29
|
+
"editor.defaultFormatter": "biomejs.biome"
|
|
30
|
+
},
|
|
31
|
+
"[svelte]": {
|
|
32
|
+
"editor.defaultFormatter": "biomejs.biome"
|
|
33
|
+
},
|
|
34
|
+
"[css]": {
|
|
35
|
+
"editor.defaultFormatter": "biomejs.biome"
|
|
36
|
+
},
|
|
37
|
+
"[yaml]": {
|
|
38
|
+
"editor.defaultFormatter": "biomejs.biome"
|
|
39
|
+
},
|
|
40
|
+
"[graphql]": {
|
|
41
|
+
"editor.defaultFormatter": "biomejs.biome"
|
|
42
|
+
},
|
|
43
|
+
"[markdown]": {
|
|
44
|
+
"editor.defaultFormatter": "biomejs.biome"
|
|
45
|
+
},
|
|
46
|
+
"[mdx]": {
|
|
47
|
+
"editor.defaultFormatter": "biomejs.biome"
|
|
48
|
+
},
|
|
49
|
+
"editor.codeActionsOnSave": {
|
|
50
|
+
"source.fixAll.biome": "explicit",
|
|
51
|
+
"source.organizeImports.biome": "explicit"
|
|
52
|
+
}
|
|
53
|
+
}
|
package/AGENTS.md
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
# Repository Guidelines
|
|
2
|
+
|
|
3
|
+
## Project Structure & Module Organization
|
|
4
|
+
|
|
5
|
+
- Source lives in `src/`; `src/index.ts` is the CLI entry point (currently a scaffold) and should orchestrate fetch → extract → convert flow described in `docs/SPEC.md`.
|
|
6
|
+
- `docs/SPEC.md` captures the intended CLI behavior, options, and future module layout (fetcher, extractor, converter, tables, images, metadata, cache). Mirror that structure when adding files.
|
|
7
|
+
- Root configs: `package.json` (Bun/TypeScript module), `tsconfig.json` (strict, bundler-style ESM), `bun.lock` (deps). Keep new assets alongside the code they serve and prefer co-locating fixtures/tests with their modules.
|
|
8
|
+
|
|
9
|
+
## Build, Test, and Development Commands
|
|
10
|
+
|
|
11
|
+
- `bun install` — install dependencies.
|
|
12
|
+
- `bun run index.ts -- <url>` — run the CLI locally; currently prints a stub, expand to follow `docs/SPEC.md`.
|
|
13
|
+
- `bun test` — use Bun’s test runner once tests are added (no tests yet). Add focused scripts if needed, but favor Bun-native commands over npm aliases.
|
|
14
|
+
|
|
15
|
+
## Coding Style & Naming Conventions
|
|
16
|
+
|
|
17
|
+
- Language: TypeScript with ESM imports; respect `tsconfig.json` strictness (`noImplicitOverride`, `noUncheckedIndexedAccess`, etc.).
|
|
18
|
+
- Formatting: 2-space indentation; favor small, pure functions and explicit return types. Keep module names descriptive (`fetcher.ts`, `converter.ts`, etc.) to match the spec.
|
|
19
|
+
- Error handling: surface actionable messages; prefer typed errors or result objects over silent failures. Keep side effects in the CLI layer; keep helpers deterministic.
|
|
20
|
+
- Dependency stance: prefer stdlib/Bun-first utilities; add new deps only when they materially reduce complexity.
|
|
21
|
+
|
|
22
|
+
## Testing Guidelines
|
|
23
|
+
|
|
24
|
+
- Runner: Bun’s built-in test runner. Place tests as `*.test.ts` or in `__tests__/` near the code under test.
|
|
25
|
+
- Aim for coverage on fetch/extract/convert paths, option parsing, and cache behavior. Use small HTML fixtures for extraction/markdown conversion scenarios.
|
|
26
|
+
- Keep tests deterministic: avoid network calls; mock fetch/playwright layers and cache I/O; freeze time where ordering matters.
|
|
27
|
+
|
|
28
|
+
## Commit & Pull Request Guidelines
|
|
29
|
+
|
|
30
|
+
- Commit messages follow the existing pattern `type: description` (e.g., `feat: bun init`). Use imperative mood and keep scope narrow.
|
|
31
|
+
- PRs should include: summary of changes, linked issues/tasks, notable decisions or trade-offs, and sample CLI output when it changes behavior. Add screenshots only if user-facing formatting is affected.
|
|
32
|
+
- Keep diffs focused; prefer separate PRs for refactors vs. feature work. Update docs (`README.md`, `docs/SPEC.md`) alongside code changes that affect them.
|
|
33
|
+
|
|
34
|
+
# Ultracite Code Standards
|
|
35
|
+
|
|
36
|
+
This project uses **Ultracite**, a zero-config preset that enforces strict code quality standards through automated formatting and linting.
|
|
37
|
+
|
|
38
|
+
## Quick Reference
|
|
39
|
+
|
|
40
|
+
- **Format code**: `bun x ultracite fix`
|
|
41
|
+
- **Check for issues**: `bun x ultracite check`
|
|
42
|
+
- **Diagnose setup**: `bun x ultracite doctor`
|
|
43
|
+
|
|
44
|
+
Oxlint + Oxfmt (the underlying engine) provides robust linting and formatting. Most issues are automatically fixable.
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## Core Principles
|
|
49
|
+
|
|
50
|
+
Write code that is **accessible, performant, type-safe, and maintainable**. Focus on clarity and explicit intent over brevity.
|
|
51
|
+
|
|
52
|
+
### Type Safety & Explicitness
|
|
53
|
+
|
|
54
|
+
- Use explicit types for function parameters and return values when they enhance clarity
|
|
55
|
+
- Prefer `unknown` over `any` when the type is genuinely unknown
|
|
56
|
+
- Use const assertions (`as const`) for immutable values and literal types
|
|
57
|
+
- Leverage TypeScript's type narrowing instead of type assertions
|
|
58
|
+
- Use meaningful variable names instead of magic numbers - extract constants with descriptive names
|
|
59
|
+
|
|
60
|
+
### Modern JavaScript/TypeScript
|
|
61
|
+
|
|
62
|
+
- Use arrow functions for callbacks and short functions
|
|
63
|
+
- Prefer `for...of` loops over `.forEach()` and indexed `for` loops
|
|
64
|
+
- Use optional chaining (`?.`) and nullish coalescing (`??`) for safer property access
|
|
65
|
+
- Prefer template literals over string concatenation
|
|
66
|
+
- Use destructuring for object and array assignments
|
|
67
|
+
- Use `const` by default, `let` only when reassignment is needed, never `var`
|
|
68
|
+
|
|
69
|
+
### Async & Promises
|
|
70
|
+
|
|
71
|
+
- Always `await` promises in async functions - don't forget to use the return value
|
|
72
|
+
- Use `async/await` syntax instead of promise chains for better readability
|
|
73
|
+
- Handle errors appropriately in async code with try-catch blocks
|
|
74
|
+
- Don't use async functions as Promise executors
|
|
75
|
+
|
|
76
|
+
### React & JSX
|
|
77
|
+
|
|
78
|
+
- Use function components over class components
|
|
79
|
+
- Call hooks at the top level only, never conditionally
|
|
80
|
+
- Specify all dependencies in hook dependency arrays correctly
|
|
81
|
+
- Use the `key` prop for elements in iterables (prefer unique IDs over array indices)
|
|
82
|
+
- Nest children between opening and closing tags instead of passing as props
|
|
83
|
+
- Don't define components inside other components
|
|
84
|
+
- Use semantic HTML and ARIA attributes for accessibility:
|
|
85
|
+
- Provide meaningful alt text for images
|
|
86
|
+
- Use proper heading hierarchy
|
|
87
|
+
- Add labels for form inputs
|
|
88
|
+
- Include keyboard event handlers alongside mouse events
|
|
89
|
+
- Use semantic elements (`<button>`, `<nav>`, etc.) instead of divs with roles
|
|
90
|
+
|
|
91
|
+
### Error Handling & Debugging
|
|
92
|
+
|
|
93
|
+
- Remove `console.log`, `debugger`, and `alert` statements from production code
|
|
94
|
+
- Throw `Error` objects with descriptive messages, not strings or other values
|
|
95
|
+
- Use `try-catch` blocks meaningfully - don't catch errors just to rethrow them
|
|
96
|
+
- Prefer early returns over nested conditionals for error cases
|
|
97
|
+
|
|
98
|
+
### Code Organization
|
|
99
|
+
|
|
100
|
+
- Keep functions focused and under reasonable cognitive complexity limits
|
|
101
|
+
- Extract complex conditions into well-named boolean variables
|
|
102
|
+
- Use early returns to reduce nesting
|
|
103
|
+
- Prefer simple conditionals over nested ternary operators
|
|
104
|
+
- Group related code together and separate concerns
|
|
105
|
+
|
|
106
|
+
### Security
|
|
107
|
+
|
|
108
|
+
- Add `rel="noopener"` when using `target="_blank"` on links
|
|
109
|
+
- Avoid `dangerouslySetInnerHTML` unless absolutely necessary
|
|
110
|
+
- Don't use `eval()` or assign directly to `document.cookie`
|
|
111
|
+
- Validate and sanitize user input
|
|
112
|
+
|
|
113
|
+
### Performance
|
|
114
|
+
|
|
115
|
+
- Avoid spread syntax in accumulators within loops
|
|
116
|
+
- Use top-level regex literals instead of creating them in loops
|
|
117
|
+
- Prefer specific imports over namespace imports
|
|
118
|
+
- Avoid barrel files (index files that re-export everything)
|
|
119
|
+
- Use proper image components (e.g., Next.js `<Image>`) over `<img>` tags
|
|
120
|
+
|
|
121
|
+
### Framework-Specific Guidance
|
|
122
|
+
|
|
123
|
+
**Next.js:**
|
|
124
|
+
|
|
125
|
+
- Use Next.js `<Image>` component for images
|
|
126
|
+
- Use `next/head` or App Router metadata API for head elements
|
|
127
|
+
- Use Server Components for async data fetching instead of async Client Components
|
|
128
|
+
|
|
129
|
+
**React 19+:**
|
|
130
|
+
|
|
131
|
+
- Use ref as a prop instead of `React.forwardRef`
|
|
132
|
+
|
|
133
|
+
**Solid/Svelte/Vue/Qwik:**
|
|
134
|
+
|
|
135
|
+
- Use `class` and `for` attributes (not `className` or `htmlFor`)
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
## Testing
|
|
140
|
+
|
|
141
|
+
- Write assertions inside `it()` or `test()` blocks
|
|
142
|
+
- Avoid done callbacks in async tests - use async/await instead
|
|
143
|
+
- Don't use `.only` or `.skip` in committed code
|
|
144
|
+
- Keep test suites reasonably flat - avoid excessive `describe` nesting
|
|
145
|
+
|
|
146
|
+
## When Oxlint + Oxfmt Can't Help
|
|
147
|
+
|
|
148
|
+
Oxlint + Oxfmt's linter will catch most issues automatically. Focus your attention on:
|
|
149
|
+
|
|
150
|
+
1. **Business logic correctness** - Oxlint + Oxfmt can't validate your algorithms
|
|
151
|
+
2. **Meaningful naming** - Use descriptive names for functions, variables, and types
|
|
152
|
+
3. **Architecture decisions** - Component structure, data flow, and API design
|
|
153
|
+
4. **Edge cases** - Handle boundary conditions and error states
|
|
154
|
+
5. **User experience** - Accessibility, performance, and usability considerations
|
|
155
|
+
6. **Documentation** - Add comments for complex logic, but prefer self-documenting code
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
Most formatting and common issues are automatically fixed by Oxlint + Oxfmt. Run `bun x ultracite fix` before committing to ensure compliance.
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
# Ultracite Code Standards
|
|
163
|
+
|
|
164
|
+
This project uses **Ultracite**, a zero-config preset that enforces strict code quality standards through automated formatting and linting.
|
|
165
|
+
|
|
166
|
+
## Quick Reference
|
|
167
|
+
|
|
168
|
+
- **Format code**: `bun x ultracite fix`
|
|
169
|
+
- **Check for issues**: `bun x ultracite check`
|
|
170
|
+
- **Diagnose setup**: `bun x ultracite doctor`
|
|
171
|
+
|
|
172
|
+
Biome (the underlying engine) provides robust linting and formatting. Most issues are automatically fixable.
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## Core Principles
|
|
177
|
+
|
|
178
|
+
Write code that is **accessible, performant, type-safe, and maintainable**. Focus on clarity and explicit intent over brevity.
|
|
179
|
+
|
|
180
|
+
### Type Safety & Explicitness
|
|
181
|
+
|
|
182
|
+
- Use explicit types for function parameters and return values when they enhance clarity
|
|
183
|
+
- Prefer `unknown` over `any` when the type is genuinely unknown
|
|
184
|
+
- Use const assertions (`as const`) for immutable values and literal types
|
|
185
|
+
- Leverage TypeScript's type narrowing instead of type assertions
|
|
186
|
+
- Use meaningful variable names instead of magic numbers - extract constants with descriptive names
|
|
187
|
+
|
|
188
|
+
### Modern JavaScript/TypeScript
|
|
189
|
+
|
|
190
|
+
- Use arrow functions for callbacks and short functions
|
|
191
|
+
- Prefer `for...of` loops over `.forEach()` and indexed `for` loops
|
|
192
|
+
- Use optional chaining (`?.`) and nullish coalescing (`??`) for safer property access
|
|
193
|
+
- Prefer template literals over string concatenation
|
|
194
|
+
- Use destructuring for object and array assignments
|
|
195
|
+
- Use `const` by default, `let` only when reassignment is needed, never `var`
|
|
196
|
+
|
|
197
|
+
### Async & Promises
|
|
198
|
+
|
|
199
|
+
- Always `await` promises in async functions - don't forget to use the return value
|
|
200
|
+
- Use `async/await` syntax instead of promise chains for better readability
|
|
201
|
+
- Handle errors appropriately in async code with try-catch blocks
|
|
202
|
+
- Don't use async functions as Promise executors
|
|
203
|
+
|
|
204
|
+
### React & JSX
|
|
205
|
+
|
|
206
|
+
- Use function components over class components
|
|
207
|
+
- Call hooks at the top level only, never conditionally
|
|
208
|
+
- Specify all dependencies in hook dependency arrays correctly
|
|
209
|
+
- Use the `key` prop for elements in iterables (prefer unique IDs over array indices)
|
|
210
|
+
- Nest children between opening and closing tags instead of passing as props
|
|
211
|
+
- Don't define components inside other components
|
|
212
|
+
- Use semantic HTML and ARIA attributes for accessibility:
|
|
213
|
+
- Provide meaningful alt text for images
|
|
214
|
+
- Use proper heading hierarchy
|
|
215
|
+
- Add labels for form inputs
|
|
216
|
+
- Include keyboard event handlers alongside mouse events
|
|
217
|
+
- Use semantic elements (`<button>`, `<nav>`, etc.) instead of divs with roles
|
|
218
|
+
|
|
219
|
+
### Error Handling & Debugging
|
|
220
|
+
|
|
221
|
+
- Remove `console.log`, `debugger`, and `alert` statements from production code
|
|
222
|
+
- Throw `Error` objects with descriptive messages, not strings or other values
|
|
223
|
+
- Use `try-catch` blocks meaningfully - don't catch errors just to rethrow them
|
|
224
|
+
- Prefer early returns over nested conditionals for error cases
|
|
225
|
+
|
|
226
|
+
### Code Organization
|
|
227
|
+
|
|
228
|
+
- Keep functions focused and under reasonable cognitive complexity limits
|
|
229
|
+
- Extract complex conditions into well-named boolean variables
|
|
230
|
+
- Use early returns to reduce nesting
|
|
231
|
+
- Prefer simple conditionals over nested ternary operators
|
|
232
|
+
- Group related code together and separate concerns
|
|
233
|
+
|
|
234
|
+
### Security
|
|
235
|
+
|
|
236
|
+
- Add `rel="noopener"` when using `target="_blank"` on links
|
|
237
|
+
- Avoid `dangerouslySetInnerHTML` unless absolutely necessary
|
|
238
|
+
- Don't use `eval()` or assign directly to `document.cookie`
|
|
239
|
+
- Validate and sanitize user input
|
|
240
|
+
|
|
241
|
+
### Performance
|
|
242
|
+
|
|
243
|
+
- Avoid spread syntax in accumulators within loops
|
|
244
|
+
- Use top-level regex literals instead of creating them in loops
|
|
245
|
+
- Prefer specific imports over namespace imports
|
|
246
|
+
- Avoid barrel files (index files that re-export everything)
|
|
247
|
+
- Use proper image components (e.g., Next.js `<Image>`) over `<img>` tags
|
|
248
|
+
|
|
249
|
+
### Framework-Specific Guidance
|
|
250
|
+
|
|
251
|
+
**Next.js:**
|
|
252
|
+
- Use Next.js `<Image>` component for images
|
|
253
|
+
- Use `next/head` or App Router metadata API for head elements
|
|
254
|
+
- Use Server Components for async data fetching instead of async Client Components
|
|
255
|
+
|
|
256
|
+
**React 19+:**
|
|
257
|
+
- Use ref as a prop instead of `React.forwardRef`
|
|
258
|
+
|
|
259
|
+
**Solid/Svelte/Vue/Qwik:**
|
|
260
|
+
- Use `class` and `for` attributes (not `className` or `htmlFor`)
|
|
261
|
+
|
|
262
|
+
---
|
|
263
|
+
|
|
264
|
+
## Testing
|
|
265
|
+
|
|
266
|
+
- Write assertions inside `it()` or `test()` blocks
|
|
267
|
+
- Avoid done callbacks in async tests - use async/await instead
|
|
268
|
+
- Don't use `.only` or `.skip` in committed code
|
|
269
|
+
- Keep test suites reasonably flat - avoid excessive `describe` nesting
|
|
270
|
+
|
|
271
|
+
## When Biome Can't Help
|
|
272
|
+
|
|
273
|
+
Biome's linter will catch most issues automatically. Focus your attention on:
|
|
274
|
+
|
|
275
|
+
1. **Business logic correctness** - Biome can't validate your algorithms
|
|
276
|
+
2. **Meaningful naming** - Use descriptive names for functions, variables, and types
|
|
277
|
+
3. **Architecture decisions** - Component structure, data flow, and API design
|
|
278
|
+
4. **Edge cases** - Handle boundary conditions and error states
|
|
279
|
+
5. **User experience** - Accessibility, performance, and usability considerations
|
|
280
|
+
6. **Documentation** - Add comments for complex logic, but prefer self-documenting code
|
|
281
|
+
|
|
282
|
+
---
|
|
283
|
+
|
|
284
|
+
Most formatting and common issues are automatically fixed by Biome. Run `bun x ultracite fix` before committing to ensure compliance.
|