Skip to content

Commit b2e121f

Browse files
committed
AI: Add code formatting guide, update utils guide with indent, add code comment guide to css guide
1 parent e10bb5e commit b2e121f

File tree

5 files changed

+203
-5
lines changed

5 files changed

+203
-5
lines changed

ai/00-START-HERE.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ Workflows contain required steps (testing, types, exports, documentation) that a
8989
**Start with:** [Build System Guide](/ai/guides/development/build-system.md)
9090
**Contains:** Two-system architecture (JS libraries vs web components), build commands reference, esbuild plugins, export conditions, wireit orchestration, common workflows, idiosyncrasies
9191

92+
### Code Formatting & Style
93+
**Need to:** Understand formatting rules, comment hierarchy, code style conventions
94+
**Start with:** [Code Formatting Guide](/ai/guides/development/code-formatting.md)
95+
**Contains:** dprint configuration, three-level comment hierarchy, formatting best practices
96+
9297
### HTML & CSS Guidelines
9398
**Need to:** Writing templates, styling components, design tokens, theming
9499
**Start with:** [HTML Guide](/ai/guides/html/style-guide.md)[CSS Guide](/ai/guides/css/css-guide.md)[Theming](/ai/guides/css/theming.md)[CSS Tokens](/ai/guides/css/tokens/token-usage.md)

ai/guides/css/css-guide.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
# Semantic UI CSS Guide
22

3-
**Purpose**: Canonical patterns for CSS architecture and styling
3+
> Last Updated: 2025-11-14
4+
5+
**Purpose**: Canonical patterns for CSS architecture and styling
46
**Audience**: All developers building custom components
57

68
## Core Philosophy
79

810
Write minimal, maintainable CSS that leverages the design token system and mirrors HTML structure through natural nesting patterns.
911

12+
> **Code formatting and comment hierarchy**: See `/ai/guides/development/code-formatting.md` for dprint rules and the three-level comment hierarchy for organizing large files.
13+
1014
## CSS Architecture
1115

1216
### Nesting Patterns
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Code Formatting Guide
2+
3+
> Last Updated: 2025-11-14
4+
5+
**Purpose**: Code formatting standards and comment hierarchy
6+
**Audience**: All developers
7+
8+
## Formatting Rules
9+
10+
All code formatting follows `/dprint.json`:
11+
12+
- 2-space indentation (no tabs)
13+
- 120 character line width
14+
- Single quotes preferred
15+
- Always use semicolons
16+
- Always use braces
17+
- Sorted imports (case-insensitive)
18+
- Trailing commas only on multi-line structures
19+
20+
**When in doubt**: Run the formatter or match existing code style.
21+
22+
> **Note**: CSS files are not formatted by dprint. Follow CSS nesting patterns from the CSS guide.
23+
24+
## Comment Hierarchy
25+
26+
For large CSS files, config files, and organized code files, use three-level comment hierarchy:
27+
28+
### Level 1: Major Sections
29+
30+
```css
31+
/*******************************
32+
Groups
33+
*******************************/
34+
```
35+
36+
**Use for**: File headers, major functional groups (every 50-100+ lines)
37+
38+
### Level 2: Sub-sections
39+
40+
```css
41+
/*-------------------
42+
Or Buttons
43+
--------------------*/
44+
```
45+
46+
**Use for**: Related content within major sections (every 20-50 lines)
47+
48+
### Level 3: Minor Divisions
49+
50+
```css
51+
/* Types */
52+
```
53+
54+
**Use for**: Small logical groupings (5-15 lines)
55+
56+
## Comment Guidelines
57+
58+
- **Use title case, not all caps**: `/* Primary Button */` not `/* PRIMARY BUTTON */`
59+
- **Don't overuse comments** - only where they provide value as breadcrumbs
60+
- Use simple, concise comments: `/* Remove duplicates from an array */`
61+
- Consider how Vue, Vite, Svelte use comments - minimal and purposeful
62+
- Match existing style in the file you're editing
63+
64+
## Application
65+
66+
**CSS Files** (`src/css/`, `src/primitives/*/css/`):
67+
- Level 1: Theme sections, major groups
68+
- Level 2: Variations, states, components
69+
- Level 3: Types, small divisions
70+
71+
**Config Files** (build configurations):
72+
- Level 1: Configuration domains
73+
- Level 2: Specific tools, features
74+
- Level 3: Options, flags
75+
76+
**Large Files** (>200 lines):
77+
- Level 1: Major functional areas
78+
- Level 2: Sub-features, groupings
79+
- Level 3: Implementation details
80+
81+
## Best Practices
82+
83+
**DO:**
84+
- Use consistent spacing
85+
- Center-align Level 1 and Level 2 headers
86+
- Keep headers concise (2-4 words)
87+
- Match indentation to code
88+
89+
**DON'T:**
90+
- Mix comment styles in one file
91+
- Over-use Level 1 headers
92+
- Skip levels (Level 1 → Level 3)
93+
- Use for tiny sections (< 5 lines)

ai/meta/context-manifest.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@
7474
"approxTokens": 26000,
7575
"description": "Comprehensive guide to Semantic UI's build system: commands, architecture, scripts, plugins, and the two-system design for JS libraries and web components"
7676
},
77+
{
78+
"id": "development/code-formatting",
79+
"path": "ai/guides/development/code-formatting.md",
80+
"category": "specialized",
81+
"tags": ["formatting", "code-style", "comments", "dprint"],
82+
"approxTokens": 450
83+
},
7784
{
7885
"id": "html/style-guide",
7986
"path": "ai/guides/html/style-guide.md",
@@ -95,8 +102,8 @@
95102
"path": "ai/guides/css/css-guide.md",
96103
"category": "specialized",
97104
"tags": ["css", "architecture", "responsive"],
98-
"dependsOn": ["html/style-guide"],
99-
"approxTokens": 4200
105+
"dependsOn": ["html/style-guide", "development/code-formatting"],
106+
"approxTokens": 4400
100107
},
101108
{
102109
"id": "css/token-usage",

ai/packages/utils.md

Lines changed: 91 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,18 @@ The `@semantic-ui/utils` package is a comprehensive standalone utility library p
88

99
## Package Structure
1010

11-
The package is organized into **17 specialized modules**, each focused on a specific domain:
11+
The package is organized into **18 specialized modules**, each focused on a specific domain:
1212

1313
```
1414
@semantic-ui/utils
1515
├── arrays.js ← Array manipulation and processing (27+ functions)
16-
├── objects.js ← Object operations and property access (15+ functions)
16+
├── objects.js ← Object operations and property access (15+ functions)
1717
├── types.js ← Type checking and validation (15+ functions)
1818
├── strings.js ← String formatting and transformation (8+ functions)
1919
├── functions.js ← Function utilities and higher-order functions
2020
├── colors.js ← OKLCH to RGB/Hex color conversion
2121
├── css.js ← CSS stylesheet adoption, extraction, and scoping
22+
├── html.js ← HTML indentation and text formatting
2223
├── browser.js ← Browser-specific operations and XHR
2324
├── looping.js ← Iteration utilities for objects and arrays
2425
├── dates.js ← Date formatting with internationalization
@@ -437,6 +438,94 @@ const rootScoped = scopeStyles(rootCSS, '.app', { appendToRootElements: false })
437438
// Result: .app html { font-size: 16px; } .app body { margin: 0; }
438439
```
439440

441+
## HTML Utilities (html.js)
442+
443+
### Text Indentation
444+
```javascript
445+
import { indentLines } from '@semantic-ui/utils';
446+
447+
// Add consistent indentation to all lines
448+
const code = 'line 1\nline 2\nline 3';
449+
indentLines(code); // ' line 1\n line 2\n line 3' (2 spaces)
450+
indentLines(code, 4); // ' line 1\n line 2\n line 3' (4 spaces)
451+
452+
// Useful for template processing
453+
const template = `
454+
function example() {
455+
return true;
456+
}
457+
`;
458+
const indented = indentLines(template.trim(), 2);
459+
```
460+
461+
### HTML Indentation
462+
```javascript
463+
import { indentHTML } from '@semantic-ui/utils';
464+
465+
// Basic HTML indentation
466+
const html = '<div>\n<p>Content</p>\n</div>';
467+
indentHTML(html);
468+
// Result:
469+
// <div>
470+
// <p>Content</p>
471+
// </div>
472+
473+
// Handles nested structures
474+
const nested = `
475+
<div class="ui segment">
476+
<div class="ui header">Title</div>
477+
<p>Content here</p>
478+
<div class="ui list">
479+
<div class="item">
480+
<img src="image.jpg" />
481+
<div class="content">Item 1</div>
482+
</div>
483+
</div>
484+
</div>
485+
`;
486+
487+
indentHTML(nested);
488+
// Result:
489+
// <div class="ui segment">
490+
// <div class="ui header">Title</div>
491+
// <p>Content here</p>
492+
// <div class="ui list">
493+
// <div class="item">
494+
// <img src="image.jpg" />
495+
// <div class="content">Item 1</div>
496+
// </div>
497+
// </div>
498+
// </div>
499+
500+
// Custom indentation
501+
indentHTML(html, { indent: ' ' }); // 4 spaces
502+
indentHTML(html, { indent: '\t' }); // Tabs
503+
504+
// Start at specific nesting level
505+
indentHTML(html, { startLevel: 1 }); // Start with one level of indent
506+
507+
// Preserve empty lines
508+
indentHTML(html, { trimEmptyLines: false });
509+
```
510+
511+
**Common use cases:**
512+
- Cleaning up HTML extracted from JavaScript template literals
513+
- Formatting documentation examples
514+
- Processing HTML snippets from various sources
515+
- Preparing HTML for display in code editors
516+
517+
**Handles correctly:**
518+
- Void elements (img, br, hr, input, etc.) - no closing tag needed
519+
- Self-closing syntax (`<component />`)
520+
- Comments (`<!-- comment -->`)
521+
- Elements with opening/closing on same line
522+
- Multiple nesting levels
523+
524+
**Limitations:**
525+
- Works best with one tag per line (typical documentation format)
526+
- Multiple tags on same line are not split
527+
- Designed for well-formed HTML snippets, not error correction
528+
440529
## Browser Integration (browser.js)
441530

442531
### Clipboard and Navigation

0 commit comments

Comments
 (0)