@canonical/code-standards 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/.mcp.json +8 -0
- package/README.md +297 -0
- package/data/code.ttl +437 -0
- package/data/css.ttl +265 -0
- package/data/icons.ttl +359 -0
- package/data/packaging.ttl +464 -0
- package/data/react.ttl +752 -0
- package/data/rust.ttl +1806 -0
- package/data/storybook.ttl +403 -0
- package/data/styling.ttl +165 -0
- package/data/tsdoc.ttl +216 -0
- package/data/turtle.ttl +179 -0
- package/definitions/CodeStandard.ttl +80 -0
- package/docs/code.md +720 -0
- package/docs/css.md +275 -0
- package/docs/icons.md +367 -0
- package/docs/index.md +15 -0
- package/docs/react.md +766 -0
- package/docs/rust.md +1784 -0
- package/docs/storybook.md +413 -0
- package/docs/styling.md +163 -0
- package/docs/tsdoc.md +213 -0
- package/docs/turtle.md +179 -0
- package/package.json +9 -0
- package/skills/add-standard/SKILL.md +288 -0
- package/src/scripts/generate-docs.ts +131 -0
- package/src/scripts/index.ts +19 -0
package/.mcp.json
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
# Code Standards Ontology
|
|
2
|
+
|
|
3
|
+
An OWL ontology for codifying software development standards as structured, queryable knowledge graphs. Standards become machine-readable, versionable, and programmatically accessible to both humans and AI agents.
|
|
4
|
+
|
|
5
|
+
**Core Philosophy:** Code standards are institutional knowledge. By modeling them ontologically, we transform tribal wisdom into queryable data—enabling automated linting context, AI-assisted code review, and consistent onboarding across teams.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Quick Start
|
|
10
|
+
|
|
11
|
+
### 1. Core Concepts
|
|
12
|
+
|
|
13
|
+
Each code standard is a structured record with:
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
CodeStandard
|
|
17
|
+
├── name - Domain path (e.g., "react/component/folder-structure")
|
|
18
|
+
├── description - What and why
|
|
19
|
+
├── dos - Correct examples with code
|
|
20
|
+
├── donts - Incorrect examples with explanation
|
|
21
|
+
├── hasCategory - Grouping (React, CSS, Storybook...)
|
|
22
|
+
└── extends - Parent standard (optional)
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Standards are organized by **Categories** (technology domains) and can **extend** other standards for specialization.
|
|
26
|
+
|
|
27
|
+
### 2. Defining a Standard
|
|
28
|
+
|
|
29
|
+
```turtle
|
|
30
|
+
@prefix cs: <http://pragma.canonical.com/codestandards#> .
|
|
31
|
+
@prefix cs: <http://pragma.canonical.com/codestandards#> .
|
|
32
|
+
|
|
33
|
+
cs:ComponentFolderStructure a cs:CodeStandard ;
|
|
34
|
+
cs:name "react/component/structure/folder" ;
|
|
35
|
+
cs:hasCategory cs:ReactCategory ;
|
|
36
|
+
cs:description "Each component must reside in its own folder containing all related files." ;
|
|
37
|
+
cs:dos """
|
|
38
|
+
(Do) Place all component-related files within a single folder.
|
|
39
|
+
```bash
|
|
40
|
+
Button/
|
|
41
|
+
├── Button.tsx
|
|
42
|
+
├── Button.stories.tsx
|
|
43
|
+
├── Button.test.tsx
|
|
44
|
+
├── index.ts
|
|
45
|
+
├── styles.css
|
|
46
|
+
└── types.ts
|
|
47
|
+
```
|
|
48
|
+
""" ;
|
|
49
|
+
cs:donts """
|
|
50
|
+
(Don't) Scatter component files across different directories.
|
|
51
|
+
```bash
|
|
52
|
+
# Bad: Files are not co-located
|
|
53
|
+
components/Button.tsx
|
|
54
|
+
stories/Button.stories.tsx
|
|
55
|
+
styles/Button.css
|
|
56
|
+
```
|
|
57
|
+
""" .
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
### 3. Name Convention
|
|
61
|
+
|
|
62
|
+
Standard names follow a domain path pattern:
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
{category}/{domain}/{subdomain}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
| Pattern | Example |
|
|
69
|
+
|---------|---------|
|
|
70
|
+
| `react/component/folder-structure` | React component folder layout |
|
|
71
|
+
| `css/selector/nesting` | CSS selector nesting rules |
|
|
72
|
+
| `storybook/story/naming` | Storybook story naming conventions |
|
|
73
|
+
| `rust/error/result-type` | Rust error handling with Result |
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## Categories
|
|
78
|
+
|
|
79
|
+
Standards are grouped by technology domain:
|
|
80
|
+
|
|
81
|
+
| Category | Slug | Standards | Focus |
|
|
82
|
+
|----------|------|-----------|-------|
|
|
83
|
+
| **React** | `react` | 20+ | Component structure, hooks, patterns |
|
|
84
|
+
| **CSS** | `css` | 8+ | Selectors, nesting, custom properties |
|
|
85
|
+
| **Storybook** | `storybook` | 10+ | Stories, documentation, controls |
|
|
86
|
+
| **Code** | `code` | 12+ | General TypeScript/JavaScript |
|
|
87
|
+
| **Styling** | `styling` | 6+ | Design system styling patterns |
|
|
88
|
+
| **Icons** | `icons` | 4+ | SVG icon implementation |
|
|
89
|
+
| **Rust** | `rust` | 15+ | Idiomatic Rust, monadic composition |
|
|
90
|
+
| **Turtle** | `turtle` | 5+ | RDF/Turtle file authoring |
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## How-To Guides
|
|
95
|
+
|
|
96
|
+
### How to Add a New Standard
|
|
97
|
+
|
|
98
|
+
1. Identify the category (React, CSS, etc.)
|
|
99
|
+
2. Determine the domain path name
|
|
100
|
+
3. Create or edit the category's `.ttl` file in `data/`
|
|
101
|
+
4. Define required properties
|
|
102
|
+
|
|
103
|
+
```turtle
|
|
104
|
+
cs:MyNewStandard a cs:CodeStandard ;
|
|
105
|
+
cs:name "react/hooks/use-effect-cleanup" ;
|
|
106
|
+
cs:hasCategory cs:ReactCategory ;
|
|
107
|
+
cs:description """
|
|
108
|
+
useEffect hooks that create subscriptions, timers, or listeners must
|
|
109
|
+
return a cleanup function to prevent memory leaks.
|
|
110
|
+
""" ;
|
|
111
|
+
cs:dos """
|
|
112
|
+
(Do) Return a cleanup function for subscriptions.
|
|
113
|
+
```typescript
|
|
114
|
+
useEffect(() => {
|
|
115
|
+
const subscription = source.subscribe(handler);
|
|
116
|
+
return () => subscription.unsubscribe();
|
|
117
|
+
}, [source]);
|
|
118
|
+
```
|
|
119
|
+
""" ;
|
|
120
|
+
cs:donts """
|
|
121
|
+
(Don't) Forget cleanup for resources that persist.
|
|
122
|
+
```typescript
|
|
123
|
+
// Bad: Timer never cleared
|
|
124
|
+
useEffect(() => {
|
|
125
|
+
setInterval(poll, 1000);
|
|
126
|
+
}, []);
|
|
127
|
+
```
|
|
128
|
+
""" .
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
### Writing Effective Do's and Don'ts
|
|
132
|
+
|
|
133
|
+
**Do's should:**
|
|
134
|
+
- Start with "(Do)" for parsing consistency
|
|
135
|
+
- Include realistic, copy-pasteable code
|
|
136
|
+
- Show the pattern in context
|
|
137
|
+
|
|
138
|
+
**Don'ts should:**
|
|
139
|
+
- Start with "(Don't)" for parsing consistency
|
|
140
|
+
- Explain *why* the pattern is problematic
|
|
141
|
+
- Show realistic mistakes developers actually make
|
|
142
|
+
|
|
143
|
+
### How to Extend a Standard
|
|
144
|
+
|
|
145
|
+
Use `cs:extends` when a standard builds on or specializes another:
|
|
146
|
+
|
|
147
|
+
```turtle
|
|
148
|
+
cs:ComponentContextStructure a cs:CodeStandard ;
|
|
149
|
+
cs:name "react/component/structure/context" ;
|
|
150
|
+
cs:extends cs:ComponentFolderStructure ;
|
|
151
|
+
cs:hasCategory cs:ReactCategory ;
|
|
152
|
+
cs:description """
|
|
153
|
+
Context provider components follow the standard folder structure with
|
|
154
|
+
additional files for the context definition and hook.
|
|
155
|
+
""" ;
|
|
156
|
+
cs:dos """
|
|
157
|
+
(Do) Include Context.tsx and useContext hook.
|
|
158
|
+
```bash
|
|
159
|
+
AuthProvider/
|
|
160
|
+
├── AuthProvider.tsx # Provider component
|
|
161
|
+
├── Context.tsx # Context definition
|
|
162
|
+
├── useAuth.ts # Consumer hook
|
|
163
|
+
├── index.ts
|
|
164
|
+
└── types.ts
|
|
165
|
+
```
|
|
166
|
+
""" .
|
|
167
|
+
|
|
168
|
+
The `extends` relationship enables:
|
|
169
|
+
- Inheritance queries (find all folder structure variants)
|
|
170
|
+
- Hierarchical documentation
|
|
171
|
+
- Progressive specificity
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
## Reference
|
|
175
|
+
|
|
176
|
+
### Classes
|
|
177
|
+
|
|
178
|
+
| Class | Description | Instances |
|
|
179
|
+
|-------|-------------|-----------|
|
|
180
|
+
| `CodeStandard` | A coding guideline with do's and don'ts | 64 |
|
|
181
|
+
| `Category` | Grouping for related standards | 8 |
|
|
182
|
+
|
|
183
|
+
### CodeStandard Properties
|
|
184
|
+
|
|
185
|
+
| Property | Range | Description |
|
|
186
|
+
|----------|-------|-------------|
|
|
187
|
+
| `name` | NamePattern | Domain path identifier (e.g., `react/component/folder`) |
|
|
188
|
+
| `description` | string | What the standard requires and why |
|
|
189
|
+
| `dos` | string | Correct examples with code blocks |
|
|
190
|
+
| `donts` | string | Incorrect examples with explanations |
|
|
191
|
+
| `hasCategory` | Category | Technology domain classification |
|
|
192
|
+
| `extends` | CodeStandard | Parent standard for specialization |
|
|
193
|
+
|
|
194
|
+
### Category Properties
|
|
195
|
+
|
|
196
|
+
| Property | Range | Description |
|
|
197
|
+
|----------|-------|-------------|
|
|
198
|
+
| `slug` | string | Short identifier (e.g., `react`, `css`) |
|
|
199
|
+
| `label` | string | Display name |
|
|
200
|
+
| `comment` | string | Category description |
|
|
201
|
+
|
|
202
|
+
### Name Pattern
|
|
203
|
+
|
|
204
|
+
Standard names must match:
|
|
205
|
+
|
|
206
|
+
```regex
|
|
207
|
+
^[a-z]+(/[a-z0-9-]+){2,}$
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
Valid: `react/component/folder-structure`, `css/selector/nesting`
|
|
211
|
+
Invalid: `React/Component`, `component-structure`
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
## Architecture
|
|
216
|
+
|
|
217
|
+
```
|
|
218
|
+
code-standards/
|
|
219
|
+
├── definitions/
|
|
220
|
+
│ └── CodeStandard.ttl # TBox: Classes, properties, constraints
|
|
221
|
+
├── data/
|
|
222
|
+
│ ├── react.ttl # React standards
|
|
223
|
+
│ ├── css.ttl # CSS standards
|
|
224
|
+
│ ├── storybook.ttl # Storybook standards
|
|
225
|
+
│ ├── code.ttl # General code standards
|
|
226
|
+
│ ├── styling.ttl # Styling standards
|
|
227
|
+
│ ├── icons.ttl # Icon standards
|
|
228
|
+
│ ├── rust.ttl # Rust standards
|
|
229
|
+
│ └── turtle.ttl # Turtle authoring standards
|
|
230
|
+
├── skills/
|
|
231
|
+
│ └── audit/ # Standard compliance checking skill
|
|
232
|
+
├── sem.toml # Package manifest
|
|
233
|
+
└── README.md
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### Namespaces
|
|
237
|
+
|
|
238
|
+
```turtle
|
|
239
|
+
@prefix cs: <http://pragma.canonical.com/codestandards#> .
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### Dependencies
|
|
243
|
+
|
|
244
|
+
- **skos** — Category as SKOS Concept
|
|
245
|
+
|
|
246
|
+
---
|
|
247
|
+
|
|
248
|
+
## Integration
|
|
249
|
+
|
|
250
|
+
### AI Code Review
|
|
251
|
+
|
|
252
|
+
Standards are designed for AI consumption. When reviewing code, AI assistants can:
|
|
253
|
+
|
|
254
|
+
1. Query relevant standards for the code being reviewed
|
|
255
|
+
2. Apply the structured do's/don'ts to evaluate the diff
|
|
256
|
+
3. Generate precise feedback based on standard violations
|
|
257
|
+
|
|
258
|
+
The structured format enables consistent, actionable code review feedback.
|
|
259
|
+
|
|
260
|
+
### IDE Integration
|
|
261
|
+
|
|
262
|
+
Standards can power:
|
|
263
|
+
- Real-time linting hints
|
|
264
|
+
- Autocomplete suggestions
|
|
265
|
+
- Documentation popups
|
|
266
|
+
- Refactoring recommendations
|
|
267
|
+
|
|
268
|
+
### Onboarding
|
|
269
|
+
|
|
270
|
+
New team members can query standards by domain:
|
|
271
|
+
|
|
272
|
+
```
|
|
273
|
+
# "What are the React component rules?"
|
|
274
|
+
"Show me all standards for React components"
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
### Design System Ontology
|
|
278
|
+
|
|
279
|
+
Code standards complement the [Design System Ontology](https://github.com/canonical/design-system):
|
|
280
|
+
|
|
281
|
+
| Ontology | Focus |
|
|
282
|
+
|----------|-------|
|
|
283
|
+
| Design System | What to build (components, patterns, modifiers) |
|
|
284
|
+
| Code Standards | How to build (structure, patterns, conventions) |
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
---
|
|
288
|
+
|
|
289
|
+
## Version
|
|
290
|
+
|
|
291
|
+
0.1.0 — Initial release with React, CSS, Storybook, and general code standards
|
|
292
|
+
|
|
293
|
+
## Links
|
|
294
|
+
|
|
295
|
+
- [Source](https://github.com/canonical/code-standards)
|
|
296
|
+
- [Design System Ontology](https://github.com/canonical/design-system)
|
|
297
|
+
- [Pragma Monorepo](https://github.com/canonical/pragma)
|