@canonical/code-standards 0.1.0 → 0.1.1
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/.github/PULL_REQUEST_TEMPLATE.md +13 -0
- package/.github/workflows/ci.yml +40 -0
- package/biome.json +6 -0
- package/bun.lock +200 -0
- package/data/code.ttl +208 -167
- package/data/css.ttl +110 -91
- package/data/icons.ttl +186 -150
- package/data/packaging.ttl +428 -170
- package/data/react.ttl +306 -244
- package/data/rust.ttl +563 -467
- package/data/storybook.ttl +108 -90
- package/data/styling.ttl +40 -40
- package/data/tsdoc.ttl +111 -86
- package/data/turtle.ttl +89 -68
- package/definitions/CodeStandard.ttl +28 -20
- package/docs/code.md +37 -327
- package/docs/css.md +20 -19
- package/docs/icons.md +37 -41
- package/docs/index.md +2 -1
- package/docs/packaging.md +643 -0
- package/docs/react.md +54 -58
- package/docs/rust.md +92 -158
- package/docs/storybook.md +18 -20
- package/docs/styling.md +8 -8
- package/docs/tsdoc.md +16 -16
- package/docs/turtle.md +15 -15
- package/package.json +16 -2
- package/skills/add-standard/SKILL.md +83 -47
- package/src/scripts/generate-docs.ts +95 -13
- package/src/scripts/index.ts +4 -2
- package/tsconfig.json +8 -0
package/data/tsdoc.ttl
CHANGED
|
@@ -1,42 +1,45 @@
|
|
|
1
|
-
@prefix
|
|
2
|
-
@prefix cs: <http://pragma.canonical.com/codestandards/instances#> .
|
|
1
|
+
@prefix cs: <http://pragma.canonical.com/codestandards#> .
|
|
3
2
|
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
|
|
4
3
|
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
|
|
5
4
|
@prefix owl: <http://www.w3.org/2002/07/owl#> .
|
|
6
5
|
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
|
|
7
6
|
|
|
8
7
|
# TSDoc Category
|
|
9
|
-
cs:TSDocCategory a
|
|
8
|
+
cs:TSDocCategory a cs:Category ;
|
|
10
9
|
rdfs:label "TSDoc"@en ;
|
|
11
10
|
rdfs:comment "Standards for TypeScript documentation comments — placement, layering, and tag usage."@en ;
|
|
12
|
-
|
|
11
|
+
cs:slug "tsdoc" .
|
|
13
12
|
|
|
14
13
|
# Module Tag Location
|
|
15
|
-
cs:TSDocModuleTagLocation a
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
cs:TSDocModuleTagLocation a cs:CodeStandard ;
|
|
15
|
+
cs:name "tsdoc/module-tag-location" ;
|
|
16
|
+
cs:hasCategory cs:TSDocCategory ;
|
|
17
|
+
cs:description "The `@module` TSDoc tag must appear only on barrel files such as `index.ts`. Ordinary source files must document their exported API directly and must not use file-level `@module` tags." ;
|
|
18
|
+
cs:do [
|
|
19
|
+
cs:description "Use `@module` on a barrel file that defines a package or folder-level API." ;
|
|
20
|
+
cs:language "typescript" ;
|
|
21
|
+
cs:code """
|
|
22
22
|
/**
|
|
23
23
|
* Public protocol API.
|
|
24
24
|
* @module protocol
|
|
25
25
|
*/
|
|
26
26
|
export { createRequest, matchResponse } from './index.js';
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
"""
|
|
28
|
+
] ;
|
|
29
|
+
cs:do [
|
|
30
|
+
cs:description "Document an ordinary source file at the exported symbol instead of using `@module`." ;
|
|
31
|
+
cs:language "typescript" ;
|
|
32
|
+
cs:code """
|
|
31
33
|
/** Build a completion item for a CSS variable. */
|
|
32
34
|
export default function buildCompletionItem(name: string) {
|
|
33
35
|
// ...
|
|
34
36
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
"""
|
|
38
|
+
] ;
|
|
39
|
+
cs:dont [
|
|
40
|
+
cs:description "Add `@module` to a single-purpose implementation file." ;
|
|
41
|
+
cs:language "typescript" ;
|
|
42
|
+
cs:code """
|
|
40
43
|
/**
|
|
41
44
|
* Build a completion item.
|
|
42
45
|
* @module providers/completions/buildCompletionItem
|
|
@@ -44,34 +47,39 @@ export default function buildCompletionItem(name: string) {
|
|
|
44
47
|
export default function buildCompletionItem(name: string) {
|
|
45
48
|
// ...
|
|
46
49
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
50
|
+
"""
|
|
51
|
+
] ;
|
|
52
|
+
cs:dont [
|
|
53
|
+
cs:description "Use file-level `@module` tags as a substitute for export documentation." ;
|
|
54
|
+
cs:language "typescript" ;
|
|
55
|
+
cs:code """
|
|
51
56
|
/** @module helpers/formatCurrency */
|
|
52
57
|
export default function formatCurrency(value: number) {
|
|
53
58
|
return `$${value}`;
|
|
54
59
|
}
|
|
55
|
-
|
|
56
|
-
|
|
60
|
+
"""
|
|
61
|
+
] .
|
|
57
62
|
|
|
58
63
|
# Documentation Layers
|
|
59
|
-
cs:TSDocDocumentationLayers a
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
cs:TSDocDocumentationLayers a cs:CodeStandard ;
|
|
65
|
+
cs:name "tsdoc/documentation-layers" ;
|
|
66
|
+
cs:hasCategory cs:TSDocCategory ;
|
|
67
|
+
cs:description "File-level and export-level TSDoc serve fundamentally different purposes. Export-level documentation describes *what the symbol does* — its API contract, parameters, return semantics, and side effects. File-level documentation describes *why this module exists* — its architectural role, the design invariants it upholds, and how its exports relate to each other. In single-export files the file exists solely to house that export, so file-level documentation is redundant; document only the exported symbol. In multi-export files, a file-level block is warranted when it explains the cohesion principle that binds the exports together — the reason they live in one file rather than separate ones." ;
|
|
68
|
+
cs:do [
|
|
69
|
+
cs:description "In single-export files, document only at the export level — the API contract belongs on the symbol." ;
|
|
70
|
+
cs:language "typescript" ;
|
|
71
|
+
cs:code """
|
|
66
72
|
// resolveDefinition.ts — single export, no file-level block needed
|
|
67
73
|
/** Resolve definition locations for a CSS custom property. */
|
|
68
74
|
export default function resolveDefinition(cssVar: string, graph: TokenGraph) {
|
|
69
75
|
// ...
|
|
70
76
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
77
|
+
"""
|
|
78
|
+
] ;
|
|
79
|
+
cs:do [
|
|
80
|
+
cs:description "In multi-export files, use a file-level block to explain the module's architectural purpose — why these exports are grouped." ;
|
|
81
|
+
cs:language "typescript" ;
|
|
82
|
+
cs:code """
|
|
75
83
|
// types.ts — multiple exports, file-level explains cohesion
|
|
76
84
|
/**
|
|
77
85
|
* Shared types for diagnostic rule modules.
|
|
@@ -82,10 +90,12 @@ export default function resolveDefinition(cssVar: string, graph: TokenGraph) {
|
|
|
82
90
|
|
|
83
91
|
export interface UsageRuleContext { /* ... */ }
|
|
84
92
|
export interface FileRuleContext { /* ... */ }
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
93
|
+
"""
|
|
94
|
+
] ;
|
|
95
|
+
cs:do [
|
|
96
|
+
cs:description "Use export-level TSDoc to describe the API contract: what the symbol does, its parameters, return value, and any side effects." ;
|
|
97
|
+
cs:language "typescript" ;
|
|
98
|
+
cs:code """
|
|
89
99
|
/**
|
|
90
100
|
* Check: css/missing-fallback — var() without a fallback on an unregistered property.
|
|
91
101
|
*
|
|
@@ -95,43 +105,49 @@ export interface FileRuleContext { /* ... */ }
|
|
|
95
105
|
export default function checkMissingFallback(ctx: UsageRuleContext, results: Diagnostic[]) {
|
|
96
106
|
// ...
|
|
97
107
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
108
|
+
"""
|
|
109
|
+
] ;
|
|
110
|
+
cs:dont [
|
|
111
|
+
cs:description "Add a file-level block in a single-export file that restates what the export-level doc already says." ;
|
|
112
|
+
cs:language "typescript" ;
|
|
113
|
+
cs:code """
|
|
103
114
|
// Bad: file-level repeats the export's own description
|
|
104
115
|
/** Resolve definitions for CSS custom property usages. */
|
|
105
116
|
|
|
106
117
|
/** Resolve definitions for CSS custom property usages. */
|
|
107
118
|
export default function resolveDefinition() { /* ... */ }
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
119
|
+
"""
|
|
120
|
+
] ;
|
|
121
|
+
cs:dont [
|
|
122
|
+
cs:description "Use file-level docs to describe *what* an export does — that belongs on the export itself." ;
|
|
123
|
+
cs:language "typescript" ;
|
|
124
|
+
cs:code """
|
|
112
125
|
// Bad: file-level describes the function instead of the module's role
|
|
113
126
|
/** Build a completion item for a CSS variable. */
|
|
114
127
|
|
|
115
128
|
export default function buildCompletionItem(name: string) { /* ... */ }
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
129
|
+
"""
|
|
130
|
+
] ;
|
|
131
|
+
cs:dont [
|
|
132
|
+
cs:description "Omit file-level docs on multi-export modules where the grouping rationale is non-obvious." ;
|
|
133
|
+
cs:language "typescript" ;
|
|
134
|
+
cs:code """
|
|
120
135
|
// Bad: reader cannot tell why these live together
|
|
121
136
|
export function isCompletionRequest(req: WorkerRequest) { /* ... */ }
|
|
122
137
|
export function isHoverRequest(req: WorkerRequest) { /* ... */ }
|
|
123
138
|
export function isDiagnosticsRequest(req: WorkerRequest) { /* ... */ }
|
|
124
|
-
|
|
125
|
-
|
|
139
|
+
"""
|
|
140
|
+
] .
|
|
126
141
|
|
|
127
142
|
# Self-Contained Documentation
|
|
128
|
-
cs:TSDocSelfContained a
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
143
|
+
cs:TSDocSelfContained a cs:CodeStandard ;
|
|
144
|
+
cs:name "tsdoc/self-contained" ;
|
|
145
|
+
cs:hasCategory cs:TSDocCategory ;
|
|
146
|
+
cs:description "TSDoc comments must be self-contained — a reader should fully understand the documented symbol from its comment alone. External links (public specs, RFCs, GitHub issues) are allowed as supplementary references, but the comment itself must never depend on them for comprehension. If an external concept drives the implementation, distill the essential information into the comment." ;
|
|
147
|
+
cs:do [
|
|
148
|
+
cs:description "Explain the concept inline so the reader needs nothing else" ;
|
|
149
|
+
cs:language "typescript" ;
|
|
150
|
+
cs:code """
|
|
135
151
|
/**
|
|
136
152
|
* Encode a string as a percent-encoded URI component.
|
|
137
153
|
*
|
|
@@ -141,10 +157,12 @@ cs:TSDocSelfContained a cso:CodeStandard ;
|
|
|
141
157
|
export function encodeComponent(value: string): string {
|
|
142
158
|
// ...
|
|
143
159
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
160
|
+
"""
|
|
161
|
+
] ;
|
|
162
|
+
cs:do [
|
|
163
|
+
cs:description "Add an external link as a supplementary reference after a self-sufficient explanation" ;
|
|
164
|
+
cs:language "typescript" ;
|
|
165
|
+
cs:code """
|
|
148
166
|
/**
|
|
149
167
|
* Compare two semantic version strings.
|
|
150
168
|
*
|
|
@@ -157,10 +175,12 @@ export function encodeComponent(value: string): string {
|
|
|
157
175
|
export function compareVersions(a: string, b: string): number {
|
|
158
176
|
// ...
|
|
159
177
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
178
|
+
"""
|
|
179
|
+
] ;
|
|
180
|
+
cs:do [
|
|
181
|
+
cs:description "Reference a GitHub issue for additional context when the comment already explains the behaviour" ;
|
|
182
|
+
cs:language "typescript" ;
|
|
183
|
+
cs:code """
|
|
164
184
|
/**
|
|
165
185
|
* Truncate session tokens to 64 characters before storage.
|
|
166
186
|
*
|
|
@@ -173,11 +193,12 @@ export function compareVersions(a: string, b: string): number {
|
|
|
173
193
|
export function truncateToken(token: string): string {
|
|
174
194
|
// ...
|
|
175
195
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
196
|
+
"""
|
|
197
|
+
] ;
|
|
198
|
+
cs:dont [
|
|
199
|
+
cs:description "Point the reader to an external resource instead of explaining the behaviour" ;
|
|
200
|
+
cs:language "typescript" ;
|
|
201
|
+
cs:code """
|
|
181
202
|
/**
|
|
182
203
|
* Encode a URI component.
|
|
183
204
|
*
|
|
@@ -187,10 +208,12 @@ export function truncateToken(token: string): string {
|
|
|
187
208
|
export function encodeComponent(value: string): string {
|
|
188
209
|
// ...
|
|
189
210
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
211
|
+
"""
|
|
212
|
+
] ;
|
|
213
|
+
cs:dont [
|
|
214
|
+
cs:description "Reference a wiki or internal doc as a substitute for inline explanation" ;
|
|
215
|
+
cs:language "typescript" ;
|
|
216
|
+
cs:code """
|
|
194
217
|
/**
|
|
195
218
|
* Truncate session tokens before storage.
|
|
196
219
|
*
|
|
@@ -200,10 +223,12 @@ export function encodeComponent(value: string): string {
|
|
|
200
223
|
export function truncateToken(token: string): string {
|
|
201
224
|
// ...
|
|
202
225
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
226
|
+
"""
|
|
227
|
+
] ;
|
|
228
|
+
cs:dont [
|
|
229
|
+
cs:description "Leave the reader unable to understand the symbol without following a link" ;
|
|
230
|
+
cs:language "typescript" ;
|
|
231
|
+
cs:code """
|
|
207
232
|
/**
|
|
208
233
|
* Compare two semantic version strings.
|
|
209
234
|
*
|
|
@@ -212,5 +237,5 @@ export function truncateToken(token: string): string {
|
|
|
212
237
|
export function compareVersions(a: string, b: string): number {
|
|
213
238
|
// ...
|
|
214
239
|
}
|
|
215
|
-
|
|
216
|
-
|
|
240
|
+
"""
|
|
241
|
+
] .
|
package/data/turtle.ttl
CHANGED
|
@@ -20,9 +20,10 @@ cs:DefinitionsVsData a cs:CodeStandard ;
|
|
|
20
20
|
- `data/` contains instance files with actual data conforming to the schema
|
|
21
21
|
|
|
22
22
|
This separation allows tools to distinguish between schema and instance data, enables different validation rules, and makes the codebase easier to navigate.""" ;
|
|
23
|
-
cs:
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
cs:do [
|
|
24
|
+
cs:description "Place ontology definitions (classes, properties, datatypes) in the `definitions/` directory." ;
|
|
25
|
+
cs:language "turtle" ;
|
|
26
|
+
cs:code """
|
|
26
27
|
# definitions/ontology.ttl
|
|
27
28
|
@prefix ds: <https://ds.canonical.com/> .
|
|
28
29
|
|
|
@@ -32,32 +33,36 @@ ds:Component a owl:Class ;
|
|
|
32
33
|
ds:name a owl:DatatypeProperty ;
|
|
33
34
|
rdfs:domain ds:UIElement ;
|
|
34
35
|
rdfs:range xsd:string .
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
"""
|
|
37
|
+
] ;
|
|
38
|
+
cs:do [
|
|
39
|
+
cs:description "Place instance data in the `data/` directory." ;
|
|
40
|
+
cs:language "turtle" ;
|
|
41
|
+
cs:code """
|
|
39
42
|
# data/global/component/button.ttl
|
|
40
43
|
@prefix ds: <https://ds.canonical.com/> .
|
|
41
44
|
|
|
42
45
|
ds:global.component.button a ds:Component ;
|
|
43
46
|
ds:name "Button" .
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
cs:
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
"""
|
|
48
|
+
] ;
|
|
49
|
+
cs:dont [
|
|
50
|
+
cs:description "Mix class definitions and instance data in the same file." ;
|
|
51
|
+
cs:language "turtle" ;
|
|
52
|
+
cs:code """
|
|
49
53
|
# Bad: Mixing schema and data
|
|
50
54
|
ds:Component a owl:Class .
|
|
51
55
|
ds:global.component.button a ds:Component .
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
+
"""
|
|
57
|
+
] ;
|
|
58
|
+
cs:dont [
|
|
59
|
+
cs:description "Place instance data in the `definitions/` directory." ;
|
|
60
|
+
cs:code """
|
|
56
61
|
# Bad: Data file in definitions
|
|
57
62
|
definitions/
|
|
58
63
|
└── button.ttl # Contains instance data
|
|
59
|
-
|
|
60
|
-
|
|
64
|
+
"""
|
|
65
|
+
] .
|
|
61
66
|
|
|
62
67
|
# Local Name Casing Convention Standard
|
|
63
68
|
cs:LocalNameCasing a cs:CodeStandard ;
|
|
@@ -70,47 +75,57 @@ cs:LocalNameCasing a cs:CodeStandard ;
|
|
|
70
75
|
- **lowercase** (often with dots or hyphens) for instances (e.g., `ds:global.component.button`)
|
|
71
76
|
|
|
72
77
|
This convention allows a single prefix to serve both definitions and data, with the casing clearly indicating the type of resource.""" ;
|
|
73
|
-
cs:
|
|
74
|
-
|
|
75
|
-
|
|
78
|
+
cs:do [
|
|
79
|
+
cs:description "Use PascalCase for class names." ;
|
|
80
|
+
cs:language "turtle" ;
|
|
81
|
+
cs:code """
|
|
76
82
|
ds:Component a owl:Class .
|
|
77
83
|
ds:UIBlock a owl:Class .
|
|
78
84
|
ds:ModifierFamily a owl:Class .
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
85
|
+
"""
|
|
86
|
+
] ;
|
|
87
|
+
cs:do [
|
|
88
|
+
cs:description "Use camelCase for property names." ;
|
|
89
|
+
cs:language "turtle" ;
|
|
90
|
+
cs:code """
|
|
83
91
|
ds:name a owl:DatatypeProperty .
|
|
84
92
|
ds:hasProperty a owl:ObjectProperty .
|
|
85
93
|
ds:parentComponent a owl:ObjectProperty .
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
94
|
+
"""
|
|
95
|
+
] ;
|
|
96
|
+
cs:do [
|
|
97
|
+
cs:description "Use lowercase (with dots or hyphens as separators) for instance identifiers." ;
|
|
98
|
+
cs:language "turtle" ;
|
|
99
|
+
cs:code """
|
|
90
100
|
ds:global.component.button a ds:Component .
|
|
91
101
|
ds:global.modifier_family.importance a ds:ModifierFamily .
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
cs:
|
|
95
|
-
|
|
96
|
-
|
|
102
|
+
"""
|
|
103
|
+
] ;
|
|
104
|
+
cs:dont [
|
|
105
|
+
cs:description "Use lowercase for class names." ;
|
|
106
|
+
cs:language "turtle" ;
|
|
107
|
+
cs:code """
|
|
97
108
|
# Bad: Class names should be PascalCase
|
|
98
109
|
ds:component a owl:Class .
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
110
|
+
"""
|
|
111
|
+
] ;
|
|
112
|
+
cs:dont [
|
|
113
|
+
cs:description "Use PascalCase for instance identifiers." ;
|
|
114
|
+
cs:language "turtle" ;
|
|
115
|
+
cs:code """
|
|
103
116
|
# Bad: Instance names should be lowercase
|
|
104
117
|
ds:GlobalComponentButton a ds:Component .
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
118
|
+
"""
|
|
119
|
+
] ;
|
|
120
|
+
cs:dont [
|
|
121
|
+
cs:description "Use PascalCase or uppercase for property names." ;
|
|
122
|
+
cs:language "turtle" ;
|
|
123
|
+
cs:code """
|
|
109
124
|
# Bad: Property names should be camelCase
|
|
110
125
|
ds:HasProperty a owl:ObjectProperty .
|
|
111
126
|
ds:NAME a owl:DatatypeProperty .
|
|
112
|
-
|
|
113
|
-
|
|
127
|
+
"""
|
|
128
|
+
] .
|
|
114
129
|
|
|
115
130
|
# Unified Prefix Standard
|
|
116
131
|
cs:UnifiedPrefix a cs:CodeStandard ;
|
|
@@ -119,9 +134,10 @@ cs:UnifiedPrefix a cs:CodeStandard ;
|
|
|
119
134
|
cs:description """When a package uses a single namespace for both ontology and data, use a unified prefix with casing to distinguish between classes, properties, and instances. This simplifies prefix management and makes the relationship between schema and data more apparent.
|
|
120
135
|
|
|
121
136
|
The namespace URI should be a base URI without a fragment or trailing path segment for ontology vs data (e.g., `https://ds.canonical.com/` rather than separate `https://ds.canonical.com/ontology#` and `https://ds.canonical.com/data/`).""" ;
|
|
122
|
-
cs:
|
|
123
|
-
|
|
124
|
-
|
|
137
|
+
cs:do [
|
|
138
|
+
cs:description "Use a single prefix for both definitions and data." ;
|
|
139
|
+
cs:language "turtle" ;
|
|
140
|
+
cs:code """
|
|
125
141
|
# In both definitions/ and data/ files:
|
|
126
142
|
@prefix ds: <https://ds.canonical.com/> .
|
|
127
143
|
|
|
@@ -132,27 +148,29 @@ ds:name a owl:DatatypeProperty .
|
|
|
132
148
|
# Data uses lowercase
|
|
133
149
|
ds:global.component.button a ds:Component ;
|
|
134
150
|
ds:name "Button" .
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
cs:
|
|
138
|
-
|
|
139
|
-
|
|
151
|
+
"""
|
|
152
|
+
] ;
|
|
153
|
+
cs:dont [
|
|
154
|
+
cs:description "Use separate prefixes for ontology and data when a unified prefix is preferred." ;
|
|
155
|
+
cs:language "turtle" ;
|
|
156
|
+
cs:code """
|
|
140
157
|
# Bad: Unnecessarily complex when unified prefix suffices
|
|
141
158
|
@prefix dso: <https://ds.canonical.com/ontology#> .
|
|
142
159
|
@prefix ds: <https://ds.canonical.com/data/> .
|
|
143
160
|
|
|
144
161
|
ds:global.component.button a dso:Component .
|
|
145
|
-
|
|
146
|
-
|
|
162
|
+
"""
|
|
163
|
+
] .
|
|
147
164
|
|
|
148
165
|
# Prefix Declaration Standard
|
|
149
166
|
cs:PrefixDeclaration a cs:CodeStandard ;
|
|
150
167
|
cs:name "turtle/syntax/prefix-declaration" ;
|
|
151
168
|
cs:hasCategory cs:TurtleCategory ;
|
|
152
169
|
cs:description """Every Turtle file must declare all prefixes used within the file at the top of the file. Each prefix should be declared exactly once. Standard prefixes (rdf, rdfs, owl, xsd, skos) should be declared when used but are commonly understood.""" ;
|
|
153
|
-
cs:
|
|
154
|
-
|
|
155
|
-
|
|
170
|
+
cs:do [
|
|
171
|
+
cs:description "Declare all prefixes at the top of the file." ;
|
|
172
|
+
cs:language "turtle" ;
|
|
173
|
+
cs:code """
|
|
156
174
|
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
|
|
157
175
|
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
|
|
158
176
|
@prefix owl: <http://www.w3.org/2002/07/owl#> .
|
|
@@ -161,19 +179,22 @@ cs:PrefixDeclaration a cs:CodeStandard ;
|
|
|
161
179
|
|
|
162
180
|
ds:Component a owl:Class ;
|
|
163
181
|
rdfs:label "Component" .
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
cs:
|
|
167
|
-
|
|
168
|
-
|
|
182
|
+
"""
|
|
183
|
+
] ;
|
|
184
|
+
cs:dont [
|
|
185
|
+
cs:description "Declare the same prefix multiple times." ;
|
|
186
|
+
cs:language "turtle" ;
|
|
187
|
+
cs:code """
|
|
169
188
|
# Bad: Duplicate prefix declaration
|
|
170
189
|
@prefix ds: <https://ds.canonical.com/> .
|
|
171
190
|
@prefix ds: <https://ds.canonical.com/> .
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
191
|
+
"""
|
|
192
|
+
] ;
|
|
193
|
+
cs:dont [
|
|
194
|
+
cs:description "Use prefixes without declaring them." ;
|
|
195
|
+
cs:language "turtle" ;
|
|
196
|
+
cs:code """
|
|
176
197
|
# Bad: Missing prefix declaration for ds:
|
|
177
198
|
ds:Component a owl:Class .
|
|
178
|
-
|
|
179
|
-
|
|
199
|
+
"""
|
|
200
|
+
] .
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
# Ontology Declaration
|
|
9
9
|
cs: a owl:Ontology ;
|
|
10
10
|
rdfs:label "Code Standards Ontology"@en ;
|
|
11
|
-
rdfs:comment "An ontology for describing software development code standards and best practices. This ontology provides a structured way to document coding standards including categories, descriptions, do's and don'ts."@en ;
|
|
12
|
-
owl:versionInfo "
|
|
11
|
+
rdfs:comment "An ontology for describing software development code standards and best practices. This ontology provides a structured way to document coding standards including categories, descriptions, do's and don'ts with structured examples."@en ;
|
|
12
|
+
owl:versionInfo "2.0.0" .
|
|
13
13
|
|
|
14
14
|
# Classes
|
|
15
15
|
cs:CodeStandard a owl:Class ;
|
|
@@ -21,6 +21,10 @@ cs:Category a owl:Class ;
|
|
|
21
21
|
rdfs:comment "A category for grouping related code standards (e.g., testing, components, react, typescript)"@en ;
|
|
22
22
|
rdfs:subClassOf skos:Concept .
|
|
23
23
|
|
|
24
|
+
cs:Example a owl:Class ;
|
|
25
|
+
rdfs:label "Example"@en ;
|
|
26
|
+
rdfs:comment "A single do or don't example with a description, optional language tag, and optional code block"@en .
|
|
27
|
+
|
|
24
28
|
# Datatype properties
|
|
25
29
|
cs:slug a owl:DatatypeProperty ;
|
|
26
30
|
rdfs:label "slug"@en ;
|
|
@@ -48,6 +52,17 @@ cs:extends a owl:ObjectProperty ;
|
|
|
48
52
|
rdfs:domain cs:CodeStandard ;
|
|
49
53
|
rdfs:range cs:CodeStandard .
|
|
50
54
|
|
|
55
|
+
cs:do a owl:ObjectProperty ;
|
|
56
|
+
rdfs:label "do"@en ;
|
|
57
|
+
rdfs:comment "A positive example showing what should be done"@en ;
|
|
58
|
+
rdfs:domain cs:CodeStandard ;
|
|
59
|
+
rdfs:range cs:Example .
|
|
60
|
+
|
|
61
|
+
cs:dont a owl:ObjectProperty ;
|
|
62
|
+
rdfs:label "don't"@en ;
|
|
63
|
+
rdfs:comment "A negative example showing what should not be done"@en ;
|
|
64
|
+
rdfs:domain cs:CodeStandard ;
|
|
65
|
+
rdfs:range cs:Example .
|
|
51
66
|
|
|
52
67
|
cs:name a owl:DatatypeProperty ;
|
|
53
68
|
rdfs:label "name"@en ;
|
|
@@ -57,24 +72,17 @@ cs:name a owl:DatatypeProperty ;
|
|
|
57
72
|
|
|
58
73
|
cs:description a owl:DatatypeProperty ;
|
|
59
74
|
rdfs:label "description"@en ;
|
|
60
|
-
rdfs:comment "A general description of the code standard
|
|
61
|
-
rdfs:domain cs:CodeStandard ;
|
|
75
|
+
rdfs:comment "A general description of the code standard or example"@en ;
|
|
62
76
|
rdfs:range xsd:string .
|
|
63
77
|
|
|
64
|
-
cs:
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
cs:donts a owl:DatatypeProperty ;
|
|
71
|
-
rdfs:label "don'ts"@en ;
|
|
72
|
-
rdfs:comment "Examples of what should not be done, in markdown format"@en ;
|
|
73
|
-
rdfs:domain cs:CodeStandard ;
|
|
74
|
-
rdfs:range xsd:string .
|
|
78
|
+
cs:language a owl:DatatypeProperty ;
|
|
79
|
+
rdfs:label "language"@en ;
|
|
80
|
+
rdfs:comment "The programming language of the example code block (e.g., 'typescript', 'rust', 'css', 'bash', 'svg', 'turtle')"@en ;
|
|
81
|
+
rdfs:domain cs:Example ;
|
|
82
|
+
rdfs:range xsd:string .
|
|
75
83
|
|
|
76
|
-
cs:
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
84
|
+
cs:code a owl:DatatypeProperty ;
|
|
85
|
+
rdfs:label "code"@en ;
|
|
86
|
+
rdfs:comment "The code content of the example"@en ;
|
|
87
|
+
rdfs:domain cs:Example ;
|
|
88
|
+
rdfs:range xsd:string .
|