@nowline/core 0.8.5 → 0.9.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/README.md +9 -0
- package/dist/convert/printer.d.ts.map +1 -1
- package/dist/convert/printer.js +20 -9
- package/dist/convert/printer.js.map +1 -1
- package/dist/convert/schema.d.ts +7 -0
- package/dist/convert/schema.d.ts.map +1 -1
- package/dist/convert/schema.js +1 -1
- package/dist/convert/schema.js.map +1 -1
- package/dist/generated/ast.d.ts +251 -141
- package/dist/generated/ast.d.ts.map +1 -1
- package/dist/generated/ast.js +96 -4
- package/dist/generated/ast.js.map +1 -1
- package/dist/generated/grammar.d.ts +1 -1
- package/dist/generated/grammar.d.ts.map +1 -1
- package/dist/generated/grammar.js +435 -149
- package/dist/generated/grammar.js.map +1 -1
- package/dist/generated/module.d.ts +3 -3
- package/dist/generated/module.d.ts.map +1 -1
- package/dist/generated/module.js +1 -1
- package/dist/i18n/codes.d.ts +1 -1
- package/dist/i18n/codes.d.ts.map +1 -1
- package/dist/i18n/codes.js +44 -1
- package/dist/i18n/codes.js.map +1 -1
- package/dist/i18n/index.d.ts +1 -0
- package/dist/i18n/index.d.ts.map +1 -1
- package/dist/i18n/index.js.map +1 -1
- package/dist/i18n/messages.en.d.ts +107 -0
- package/dist/i18n/messages.en.d.ts.map +1 -1
- package/dist/i18n/messages.en.js +220 -1
- package/dist/i18n/messages.en.js.map +1 -1
- package/dist/i18n/messages.fr.d.ts.map +1 -1
- package/dist/i18n/messages.fr.js +250 -1
- package/dist/i18n/messages.fr.js.map +1 -1
- package/dist/i18n/wave-message-types.d.ts +238 -0
- package/dist/i18n/wave-message-types.d.ts.map +1 -0
- package/dist/i18n/wave-message-types.js +11 -0
- package/dist/i18n/wave-message-types.js.map +1 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +6 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +9 -0
- package/dist/internal.js.map +1 -0
- package/dist/language/ast-walk.d.ts +31 -0
- package/dist/language/ast-walk.d.ts.map +1 -0
- package/dist/language/ast-walk.js +109 -0
- package/dist/language/ast-walk.js.map +1 -0
- package/dist/language/calendar-declarations.d.ts +31 -0
- package/dist/language/calendar-declarations.d.ts.map +1 -0
- package/dist/language/calendar-declarations.js +99 -0
- package/dist/language/calendar-declarations.js.map +1 -0
- package/dist/language/include-references.d.ts +11 -0
- package/dist/language/include-references.d.ts.map +1 -0
- package/dist/language/include-references.js +45 -0
- package/dist/language/include-references.js.map +1 -0
- package/dist/language/include-resolver.d.ts +78 -1
- package/dist/language/include-resolver.d.ts.map +1 -1
- package/dist/language/include-resolver.js +190 -12
- package/dist/language/include-resolver.js.map +1 -1
- package/dist/language/include-waves.d.ts +73 -0
- package/dist/language/include-waves.d.ts.map +1 -0
- package/dist/language/include-waves.js +319 -0
- package/dist/language/include-waves.js.map +1 -0
- package/dist/language/nowline-module.js.map +1 -1
- package/dist/language/nowline-validator.d.ts +6 -1
- package/dist/language/nowline-validator.d.ts.map +1 -1
- package/dist/language/nowline-validator.js +95 -1589
- package/dist/language/nowline-validator.js.map +1 -1
- package/dist/language/references.d.ts +14 -0
- package/dist/language/references.d.ts.map +1 -0
- package/dist/language/references.js +36 -0
- package/dist/language/references.js.map +1 -0
- package/dist/language/style-chain.d.ts +37 -0
- package/dist/language/style-chain.d.ts.map +1 -0
- package/dist/language/style-chain.js +55 -0
- package/dist/language/style-chain.js.map +1 -0
- package/dist/language/validator/calendar.d.ts +9 -0
- package/dist/language/validator/calendar.d.ts.map +1 -0
- package/dist/language/validator/calendar.js +250 -0
- package/dist/language/validator/calendar.js.map +1 -0
- package/dist/language/validator/entities.d.ts +23 -0
- package/dist/language/validator/entities.d.ts.map +1 -0
- package/dist/language/validator/entities.js +261 -0
- package/dist/language/validator/entities.js.map +1 -0
- package/dist/language/validator/properties.d.ts +18 -0
- package/dist/language/validator/properties.d.ts.map +1 -0
- package/dist/language/validator/properties.js +356 -0
- package/dist/language/validator/properties.js.map +1 -0
- package/dist/language/validator/references.d.ts +7 -0
- package/dist/language/validator/references.d.ts.map +1 -0
- package/dist/language/validator/references.js +261 -0
- package/dist/language/validator/references.js.map +1 -0
- package/dist/language/validator/structure.d.ts +16 -0
- package/dist/language/validator/structure.d.ts.map +1 -0
- package/dist/language/validator/structure.js +166 -0
- package/dist/language/validator/structure.js.map +1 -0
- package/dist/language/validator/style.d.ts +5 -0
- package/dist/language/validator/style.d.ts.map +1 -0
- package/dist/language/validator/style.js +126 -0
- package/dist/language/validator/style.js.map +1 -0
- package/dist/language/validator/support.d.ts +35 -0
- package/dist/language/validator/support.d.ts.map +1 -0
- package/dist/language/validator/support.js +49 -0
- package/dist/language/validator/support.js.map +1 -0
- package/dist/language/validator/symbols.d.ts +6 -0
- package/dist/language/validator/symbols.d.ts.map +1 -0
- package/dist/language/validator/symbols.js +131 -0
- package/dist/language/validator/symbols.js.map +1 -0
- package/dist/language/validator/tables.d.ts +34 -0
- package/dist/language/validator/tables.d.ts.map +1 -0
- package/dist/language/validator/tables.js +120 -0
- package/dist/language/validator/tables.js.map +1 -0
- package/dist/language/validator-utils.d.ts +32 -0
- package/dist/language/validator-utils.d.ts.map +1 -0
- package/dist/language/validator-utils.js +118 -0
- package/dist/language/validator-utils.js.map +1 -0
- package/dist/language/value-tables.d.ts +107 -0
- package/dist/language/value-tables.d.ts.map +1 -0
- package/dist/language/value-tables.js +240 -0
- package/dist/language/value-tables.js.map +1 -0
- package/dist/language/waves-order.d.ts +51 -0
- package/dist/language/waves-order.d.ts.map +1 -0
- package/dist/language/waves-order.js +787 -0
- package/dist/language/waves-order.js.map +1 -0
- package/dist/language/waves-plan.d.ts +45 -0
- package/dist/language/waves-plan.d.ts.map +1 -0
- package/dist/language/waves-plan.js +64 -0
- package/dist/language/waves-plan.js.map +1 -0
- package/dist/language/waves.d.ts +96 -0
- package/dist/language/waves.d.ts.map +1 -0
- package/dist/language/waves.js +575 -0
- package/dist/language/waves.js.map +1 -0
- package/dist/util/props.d.ts +27 -0
- package/dist/util/props.d.ts.map +1 -0
- package/dist/util/props.js +49 -0
- package/dist/util/props.js.map +1 -0
- package/dist/util/single-line.d.ts +14 -0
- package/dist/util/single-line.d.ts.map +1 -0
- package/dist/util/single-line.js +16 -0
- package/dist/util/single-line.js.map +1 -0
- package/package.json +10 -6
- package/src/convert/printer.ts +20 -10
- package/src/convert/schema.ts +8 -1
- package/src/generated/ast.ts +160 -28
- package/src/generated/grammar.ts +435 -149
- package/src/generated/module.ts +1 -1
- package/src/i18n/codes.ts +95 -2
- package/src/i18n/index.ts +1 -0
- package/src/i18n/messages.en.ts +300 -1
- package/src/i18n/messages.fr.ts +335 -1
- package/src/i18n/wave-message-types.ts +206 -0
- package/src/index.ts +33 -0
- package/src/internal.ts +9 -0
- package/src/language/ast-walk.ts +158 -0
- package/src/language/calendar-declarations.ts +141 -0
- package/src/language/include-references.ts +49 -0
- package/src/language/include-resolver.ts +284 -10
- package/src/language/include-waves.ts +419 -0
- package/src/language/nowline-validator.ts +98 -1835
- package/src/language/nowline.langium +56 -22
- package/src/language/references.ts +40 -0
- package/src/language/style-chain.ts +95 -0
- package/src/language/validator/calendar.ts +319 -0
- package/src/language/validator/entities.ts +366 -0
- package/src/language/validator/properties.ts +425 -0
- package/src/language/validator/references.ts +295 -0
- package/src/language/validator/structure.ts +206 -0
- package/src/language/validator/style.ts +149 -0
- package/src/language/validator/support.ts +84 -0
- package/src/language/validator/symbols.ts +141 -0
- package/src/language/validator/tables.ts +171 -0
- package/src/language/validator-utils.ts +123 -0
- package/src/language/value-tables.ts +260 -0
- package/src/language/waves-order.ts +879 -0
- package/src/language/waves-plan.ts +101 -0
- package/src/language/waves.ts +731 -0
- package/src/util/props.ts +59 -0
- package/src/util/single-line.ts +15 -0
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
// Forward reference, reference resolution, inline date pin and cycle checks
|
|
2
|
+
// (specs/core-ast-utilities.md §3.6). Moved out of nowline-validator.ts as-is; the class
|
|
3
|
+
// forwards one method per check.
|
|
4
|
+
|
|
5
|
+
import type { AstNode, ValidationAcceptor } from 'langium';
|
|
6
|
+
import type { EntityProperty, NowlineFile } from '../../generated/ast.js';
|
|
7
|
+
import {
|
|
8
|
+
isGroupBlock,
|
|
9
|
+
isItemDeclaration,
|
|
10
|
+
isParallelBlock,
|
|
11
|
+
isSizeDeclaration,
|
|
12
|
+
isStatusDeclaration,
|
|
13
|
+
isTeamDeclaration,
|
|
14
|
+
isWaveDeclaration,
|
|
15
|
+
} from '../../generated/ast.js';
|
|
16
|
+
import { ISO_DATE_RE, isRealIsoDate, parseIsoDate, propKey } from '../../util/props.js';
|
|
17
|
+
import { declarations, visitProperties } from '../ast-walk.js';
|
|
18
|
+
import { unresolvedReferences } from '../references.js';
|
|
19
|
+
import { entityTypeLabel } from '../validator-utils.js';
|
|
20
|
+
import { isWaveBannedProperty } from '../waves.js';
|
|
21
|
+
import { acceptTr, resolveLocalStart } from './support.js';
|
|
22
|
+
import { BUILTIN_STATUS_SET } from './tables.js';
|
|
23
|
+
|
|
24
|
+
// --- Rule 15: size:/status: references resolve to earlier declarations ---
|
|
25
|
+
export function checkForwardReferences(file: NowlineFile, accept: ValidationAcceptor): void {
|
|
26
|
+
// Declarations in source order across the file.
|
|
27
|
+
const sizeOrder = new Map<string, number>();
|
|
28
|
+
const statusOrder = new Map<string, number>();
|
|
29
|
+
|
|
30
|
+
for (let i = 0; i < file.roadmapEntries.length; i++) {
|
|
31
|
+
const entry = file.roadmapEntries[i];
|
|
32
|
+
if (isSizeDeclaration(entry) && entry.name) {
|
|
33
|
+
if (!sizeOrder.has(entry.name)) sizeOrder.set(entry.name, i);
|
|
34
|
+
} else if (isStatusDeclaration(entry) && entry.name) {
|
|
35
|
+
if (!statusOrder.has(entry.name)) statusOrder.set(entry.name, i);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
for (let i = 0; i < file.roadmapEntries.length; i++) {
|
|
40
|
+
const entry = file.roadmapEntries[i];
|
|
41
|
+
visitProperties(entry, (prop) => {
|
|
42
|
+
if (isWaveBannedProperty(prop)) return;
|
|
43
|
+
const key = propKey(prop);
|
|
44
|
+
if (key === 'size' && prop.value) {
|
|
45
|
+
const val = prop.value;
|
|
46
|
+
const declIdx = sizeOrder.get(val);
|
|
47
|
+
if (declIdx === undefined) {
|
|
48
|
+
accept(
|
|
49
|
+
'error',
|
|
50
|
+
`Size "${val}" is not declared. Add "size ${val} effort:<literal>" earlier in the roadmap section.`,
|
|
51
|
+
{ node: prop, property: 'value' },
|
|
52
|
+
);
|
|
53
|
+
} else if (declIdx >= i) {
|
|
54
|
+
accept(
|
|
55
|
+
'error',
|
|
56
|
+
`Size "${val}" is referenced before its declaration. Move "size ${val}" above this entity.`,
|
|
57
|
+
{ node: prop, property: 'value' },
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
} else if (key === 'status' && prop.value) {
|
|
61
|
+
const val = prop.value;
|
|
62
|
+
if (BUILTIN_STATUS_SET.has(val)) return;
|
|
63
|
+
const declIdx = statusOrder.get(val);
|
|
64
|
+
if (declIdx === undefined) {
|
|
65
|
+
accept(
|
|
66
|
+
'error',
|
|
67
|
+
`Status "${val}" is not a built-in and has no declaration. Add "status ${val}" earlier in the roadmap section.`,
|
|
68
|
+
{ node: prop, property: 'value' },
|
|
69
|
+
);
|
|
70
|
+
} else if (declIdx >= i) {
|
|
71
|
+
accept(
|
|
72
|
+
'error',
|
|
73
|
+
`Status "${val}" is referenced before its declaration. Move "status ${val}" above this entity.`,
|
|
74
|
+
{ node: prop, property: 'value' },
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// --- Rules 24/1 (reference): after/before/on must resolve to declared ids ---
|
|
83
|
+
// `owner:` is intentionally NOT checked here. Per specs/dsl.md ("Declarations
|
|
84
|
+
// are optional"), `owner:sam` is valid even if no `person sam` declaration
|
|
85
|
+
// exists — it renders as the bare id. Sequencing properties (`after`,
|
|
86
|
+
// `before`, `on`) stay strict because a phantom dependency silently breaks
|
|
87
|
+
// the timeline / footnote target.
|
|
88
|
+
//
|
|
89
|
+
// Inline date literals in `after:` / `before:` (e.g. `after:2026-03-15`)
|
|
90
|
+
// are intentionally NOT id references — they pin the entity directly to a
|
|
91
|
+
// calendar date without a named anchor. `unresolvedReferences` (../references.ts,
|
|
92
|
+
// shared with the include resolver) skips them; their own validation
|
|
93
|
+
// (entity-type allowlist, multi-date-per-direction, roadmap-start:
|
|
94
|
+
// requirements) lives in `checkInlineDatePins` below.
|
|
95
|
+
export function checkReferenceResolution(file: NowlineFile, accept: ValidationAcceptor): void {
|
|
96
|
+
for (const { prop, key, value } of unresolvedReferences(file)) {
|
|
97
|
+
acceptTr(accept, 'error', { node: prop }, 'NL.E0302', { key, value });
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// --- Rules 24a/24b/27/28 (inline-date pins on after:/before:) ---
|
|
102
|
+
// An inline ISO date literal in `after:` or `before:` pins the entity
|
|
103
|
+
// directly to a calendar position without a named `anchor` declaration
|
|
104
|
+
// (see specs/dsl.md "Inline date pins"). This check enforces:
|
|
105
|
+
// - 24a: inline date allowed only on item / parallel / group, and on a
|
|
106
|
+
// wave's after: (its start floor). A wave's before: is skipped
|
|
107
|
+
// entirely: NL.E1105 is its only diagnostic.
|
|
108
|
+
// - 24b: at most one inline date per direction (per `after:` / `before:`)
|
|
109
|
+
// - 27: file with any inline date requires roadmap `start:`
|
|
110
|
+
// - 28: every inline date must be on or after roadmap `start:`
|
|
111
|
+
// - 1: every inline date names a real calendar day (NL.E0405)
|
|
112
|
+
//
|
|
113
|
+
// Cycle detection (`checkCircularDependencies`) skips dates entirely —
|
|
114
|
+
// they are not graph nodes — so this is the only validator that touches
|
|
115
|
+
// their date semantics. The grammar's DATE_LITERAL terminal already
|
|
116
|
+
// enforces the YYYY-MM-DD shape; an impossible day such as `2026-02-30`
|
|
117
|
+
// is NL.E0405 and skips rules 27 and 28, since layout reads it as no date
|
|
118
|
+
// and `Date` would roll it over to March 2.
|
|
119
|
+
export function checkInlineDatePins(file: NowlineFile, accept: ValidationAcceptor): void {
|
|
120
|
+
const start = resolveLocalStart(file);
|
|
121
|
+
|
|
122
|
+
const visit = (entry: AstNode): void => {
|
|
123
|
+
const props = (entry as { properties?: EntityProperty[] }).properties ?? [];
|
|
124
|
+
const wave = isWaveDeclaration(entry);
|
|
125
|
+
const allowed =
|
|
126
|
+
isItemDeclaration(entry) || isParallelBlock(entry) || isGroupBlock(entry) || wave;
|
|
127
|
+
|
|
128
|
+
for (const prop of props) {
|
|
129
|
+
const key = propKey(prop);
|
|
130
|
+
if (key !== 'after' && key !== 'before') continue;
|
|
131
|
+
if (wave && key === 'before') continue;
|
|
132
|
+
const vals = prop.value ? [prop.value] : prop.values;
|
|
133
|
+
const dateVals = vals.filter((v): v is string => !!v && ISO_DATE_RE.test(v));
|
|
134
|
+
if (dateVals.length === 0) continue;
|
|
135
|
+
|
|
136
|
+
if (!allowed) {
|
|
137
|
+
acceptTr(accept, 'error', { node: prop }, 'NL.E0411', {
|
|
138
|
+
key,
|
|
139
|
+
type: entityTypeLabel(entry),
|
|
140
|
+
});
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (dateVals.length > 1) {
|
|
145
|
+
acceptTr(accept, 'error', { node: prop }, 'NL.E0410', { key });
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
for (const dateVal of dateVals) {
|
|
149
|
+
if (!isRealIsoDate(dateVal)) {
|
|
150
|
+
acceptTr(
|
|
151
|
+
accept,
|
|
152
|
+
'error',
|
|
153
|
+
prop.value !== undefined
|
|
154
|
+
? { node: prop, property: 'value' }
|
|
155
|
+
: {
|
|
156
|
+
node: prop,
|
|
157
|
+
property: 'values',
|
|
158
|
+
index: prop.values.indexOf(dateVal),
|
|
159
|
+
},
|
|
160
|
+
'NL.E0405',
|
|
161
|
+
{ key, value: dateVal },
|
|
162
|
+
);
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
switch (start.kind) {
|
|
166
|
+
case 'invalid':
|
|
167
|
+
// Roadmap start: itself is malformed; the user
|
|
168
|
+
// already sees that error. Suppress this one to
|
|
169
|
+
// avoid noise (mirrors anchor / milestone behavior).
|
|
170
|
+
continue;
|
|
171
|
+
case 'missing':
|
|
172
|
+
acceptTr(accept, 'error', { node: prop }, 'NL.E0412', {
|
|
173
|
+
key,
|
|
174
|
+
date: dateVal,
|
|
175
|
+
});
|
|
176
|
+
continue;
|
|
177
|
+
case 'valid': {
|
|
178
|
+
const d = parseIsoDate(dateVal);
|
|
179
|
+
if (d && d < start.date) {
|
|
180
|
+
acceptTr(accept, 'error', { node: prop }, 'NL.E0413', {
|
|
181
|
+
key,
|
|
182
|
+
date: dateVal,
|
|
183
|
+
start: start.iso,
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
for (const node of declarations(file)) {
|
|
193
|
+
if (!isNestedTeam(node)) visit(node);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// --- Rule 25: circular dependencies in after/before graph ---
|
|
198
|
+
export function checkCircularDependencies(file: NowlineFile, accept: ValidationAcceptor): void {
|
|
199
|
+
// Build forward-edge graph: id -> set of ids that must finish before id can start.
|
|
200
|
+
// `after:x` on entity y means y depends on x (edge y -> x).
|
|
201
|
+
// `before:y` on entity x means x must finish before y starts, so y depends on x (edge y -> x).
|
|
202
|
+
const deps = new Map<string, Set<string>>();
|
|
203
|
+
const addDep = (node: string, dep: string) => {
|
|
204
|
+
if (!deps.has(node)) deps.set(node, new Set());
|
|
205
|
+
deps.get(node)!.add(dep);
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
const indexDependents = (
|
|
209
|
+
idName: string | undefined,
|
|
210
|
+
props: EntityProperty[],
|
|
211
|
+
file: NowlineFile,
|
|
212
|
+
) => {
|
|
213
|
+
if (!idName) return;
|
|
214
|
+
for (const prop of props) {
|
|
215
|
+
const key = propKey(prop);
|
|
216
|
+
if (key === 'after') {
|
|
217
|
+
const refs = prop.value ? [prop.value] : prop.values;
|
|
218
|
+
for (const r of refs) {
|
|
219
|
+
if (!r) continue;
|
|
220
|
+
// Inline date literals are not graph nodes — they pin
|
|
221
|
+
// to a calendar position, not to another entity. Skip
|
|
222
|
+
// them so they never participate in a cycle (per
|
|
223
|
+
// specs/dsl.md rule 25).
|
|
224
|
+
if (ISO_DATE_RE.test(r)) continue;
|
|
225
|
+
addDep(idName, r);
|
|
226
|
+
}
|
|
227
|
+
} else if (key === 'before') {
|
|
228
|
+
const refs = prop.value ? [prop.value] : prop.values;
|
|
229
|
+
for (const r of refs) {
|
|
230
|
+
if (!r) continue;
|
|
231
|
+
if (ISO_DATE_RE.test(r)) continue;
|
|
232
|
+
addDep(r, idName);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
void file;
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
const visitEntry = (entry: AstNode): void => {
|
|
240
|
+
// A wave's after: names constants (anchors, dated milestones, a
|
|
241
|
+
// date) and its before: is NL.E1105, so neither is a schedule
|
|
242
|
+
// edge. Skipping them keeps the wave-deadline idiom
|
|
243
|
+
// (`wave w2 after:gate` + `milestone gate date:... after:w2`)
|
|
244
|
+
// from reading as a cycle.
|
|
245
|
+
if (isWaveDeclaration(entry)) return;
|
|
246
|
+
const id = (entry as { name?: string }).name;
|
|
247
|
+
const props = (entry as { properties?: EntityProperty[] }).properties ?? [];
|
|
248
|
+
indexDependents(id, props, file);
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
for (const node of declarations(file)) {
|
|
252
|
+
if (!isNestedTeam(node)) visitEntry(node);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// DFS for cycles.
|
|
256
|
+
const WHITE = 0,
|
|
257
|
+
GRAY = 1,
|
|
258
|
+
BLACK = 2;
|
|
259
|
+
const color = new Map<string, number>();
|
|
260
|
+
for (const id of deps.keys()) color.set(id, WHITE);
|
|
261
|
+
|
|
262
|
+
const reported = new Set<string>();
|
|
263
|
+
const dfs = (node: string, path: string[]): void => {
|
|
264
|
+
color.set(node, GRAY);
|
|
265
|
+
path.push(node);
|
|
266
|
+
for (const dep of deps.get(node) ?? []) {
|
|
267
|
+
const c = color.get(dep) ?? WHITE;
|
|
268
|
+
if (c === GRAY) {
|
|
269
|
+
const cycleStart = path.indexOf(dep);
|
|
270
|
+
const cycle = path.slice(cycleStart).concat(dep);
|
|
271
|
+
const key = [...cycle].sort().join('→');
|
|
272
|
+
if (!reported.has(key)) {
|
|
273
|
+
reported.add(key);
|
|
274
|
+
accept('error', `Circular dependency detected: ${cycle.join(' → ')}.`, {
|
|
275
|
+
node: file.roadmapDecl ?? file,
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
} else if (c === WHITE) {
|
|
279
|
+
dfs(dep, path);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
path.pop();
|
|
283
|
+
color.set(node, BLACK);
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
for (const node of deps.keys()) {
|
|
287
|
+
if ((color.get(node) ?? WHITE) === WHITE) dfs(node, []);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// The rule 24 and rule 25 walks never looked inside a team, so a team nested
|
|
292
|
+
// in a team is skipped to keep their diagnostics (specs/core-ast-utilities.md §6).
|
|
293
|
+
function isNestedTeam(node: AstNode): boolean {
|
|
294
|
+
return isTeamDeclaration(node) && isTeamDeclaration(node.$container);
|
|
295
|
+
}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
// File structure, directive, id and title, unique id, indentation, swimlane and include-option
|
|
2
|
+
// checks (specs/core-ast-utilities.md §3.6). Moved out of nowline-validator.ts as-is; the class
|
|
3
|
+
// forwards one method per check.
|
|
4
|
+
|
|
5
|
+
import type { AstNode, ValidationAcceptor } from 'langium';
|
|
6
|
+
import { GrammarUtils } from 'langium';
|
|
7
|
+
import type {
|
|
8
|
+
IncludeDeclaration,
|
|
9
|
+
IncludeOption,
|
|
10
|
+
NowlineDirective,
|
|
11
|
+
NowlineFile,
|
|
12
|
+
} from '../../generated/ast.js';
|
|
13
|
+
import { isStyleDeclaration, isSwimlaneDeclaration } from '../../generated/ast.js';
|
|
14
|
+
import { propKey } from '../../util/props.js';
|
|
15
|
+
import { forEachDeclaredId } from '../ast-walk.js';
|
|
16
|
+
import { acceptTr, locationOf } from './support.js';
|
|
17
|
+
import {
|
|
18
|
+
BCP47_RE,
|
|
19
|
+
DIRECTIVE_FIELDS,
|
|
20
|
+
INCLUDE_MODES,
|
|
21
|
+
SUPPORTED_VERSION,
|
|
22
|
+
VERSION_RE,
|
|
23
|
+
} from './tables.js';
|
|
24
|
+
|
|
25
|
+
// --- Structural Rule 4: Section order ---
|
|
26
|
+
export function checkFileStructure(file: NowlineFile, accept: ValidationAcceptor): void {
|
|
27
|
+
// Use CST-aware lookup so the `config:` / `roadmap:` substrings inside
|
|
28
|
+
// INCLUDE_OPTION_KEY tokens (e.g. `config:isolate`) aren't mistaken for
|
|
29
|
+
// the top-level `config` section marker. See issue #1.
|
|
30
|
+
const configOffset = file.hasConfig
|
|
31
|
+
? GrammarUtils.findNodeForKeyword(file.$cstNode, 'config')?.offset
|
|
32
|
+
: undefined;
|
|
33
|
+
const roadmapOffset = file.roadmapDecl?.$cstNode?.offset;
|
|
34
|
+
|
|
35
|
+
if (configOffset !== undefined && roadmapOffset !== undefined && configOffset > roadmapOffset) {
|
|
36
|
+
acceptTr(accept, 'error', { node: file, property: 'hasConfig' }, 'NL.E0001');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
for (const inc of file.includes) {
|
|
40
|
+
const incOffset = inc.$cstNode?.offset ?? 0;
|
|
41
|
+
if (configOffset !== undefined && incOffset > configOffset) {
|
|
42
|
+
acceptTr(accept, 'error', { node: inc }, 'NL.E0002');
|
|
43
|
+
}
|
|
44
|
+
if (roadmapOffset !== undefined && incOffset > roadmapOffset) {
|
|
45
|
+
acceptTr(accept, 'error', { node: inc }, 'NL.E0003');
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// --- Structural Rules 8/9/10: label/duration/status must live in roadmap section ---
|
|
51
|
+
// Parser enforces this by construction (these keywords are only valid as RoadmapEntry),
|
|
52
|
+
// so we mainly need to forbid custom statuses referenced before their declaration (rule 15).
|
|
53
|
+
export function checkRoadmapOnlyKeywordsPosition(
|
|
54
|
+
_file: NowlineFile,
|
|
55
|
+
_accept: ValidationAcceptor,
|
|
56
|
+
): void {
|
|
57
|
+
// No-op: the grammar places label/duration/status under RoadmapEntry.
|
|
58
|
+
// Any attempt to declare them before `roadmap` surfaces as a parse error.
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// --- Rule 5: Directive version ---
|
|
62
|
+
export function checkDirectiveVersion(
|
|
63
|
+
directive: NowlineDirective,
|
|
64
|
+
accept: ValidationAcceptor,
|
|
65
|
+
): void {
|
|
66
|
+
if (!VERSION_RE.test(directive.version)) {
|
|
67
|
+
acceptTr(accept, 'error', { node: directive, property: 'version' }, 'NL.E0100', {
|
|
68
|
+
version: directive.version,
|
|
69
|
+
});
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const num = parseInt(directive.version.slice(1), 10);
|
|
73
|
+
const supportedNum = parseInt(SUPPORTED_VERSION.slice(1), 10);
|
|
74
|
+
if (num > supportedNum) {
|
|
75
|
+
acceptTr(accept, 'error', { node: directive, property: 'version' }, 'NL.E0101', {
|
|
76
|
+
version: directive.version,
|
|
77
|
+
supported: SUPPORTED_VERSION,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// --- Directive properties (locale) ---
|
|
83
|
+
// Validates the optional key:value pairs on the `nowline` directive line. Today the
|
|
84
|
+
// only allowed key is `locale:` (BCP-47 tag); unknown keys are rejected so typos
|
|
85
|
+
// surface immediately. Duplicate keys are also rejected.
|
|
86
|
+
export function checkDirectiveProperties(
|
|
87
|
+
directive: NowlineDirective,
|
|
88
|
+
accept: ValidationAcceptor,
|
|
89
|
+
): void {
|
|
90
|
+
const seen = new Set<string>();
|
|
91
|
+
for (const prop of directive.properties) {
|
|
92
|
+
const key = propKey(prop);
|
|
93
|
+
if (!DIRECTIVE_FIELDS.has(key)) {
|
|
94
|
+
acceptTr(accept, 'error', { node: prop, property: 'key' }, 'NL.E0102', {
|
|
95
|
+
key,
|
|
96
|
+
allowed: [...DIRECTIVE_FIELDS].join(', '),
|
|
97
|
+
});
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
if (seen.has(key)) {
|
|
101
|
+
acceptTr(accept, 'error', { node: prop, property: 'key' }, 'NL.E0103', { key });
|
|
102
|
+
}
|
|
103
|
+
seen.add(key);
|
|
104
|
+
|
|
105
|
+
if (key === 'locale') {
|
|
106
|
+
const raw = prop.value;
|
|
107
|
+
if (!BCP47_RE.test(raw)) {
|
|
108
|
+
acceptTr(accept, 'error', { node: prop, property: 'value' }, 'NL.E0104', {
|
|
109
|
+
value: raw,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// --- Rule 3: Id or title required ---
|
|
117
|
+
export function checkEntityIdOrTitle(
|
|
118
|
+
node: AstNode & { name?: string; title?: string },
|
|
119
|
+
accept: ValidationAcceptor,
|
|
120
|
+
): void {
|
|
121
|
+
if (!node.name && !node.title) {
|
|
122
|
+
acceptTr(accept, 'error', { node }, 'NL.E0301', { type: node.$type });
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// --- Rule 2: Unique identifiers ---
|
|
127
|
+
export function checkUniqueIdentifiers(file: NowlineFile, accept: ValidationAcceptor): void {
|
|
128
|
+
const seen = new Map<string, AstNode>();
|
|
129
|
+
|
|
130
|
+
const register = (name: string | undefined, node: AstNode) => {
|
|
131
|
+
if (!name) return;
|
|
132
|
+
const existing = seen.get(name);
|
|
133
|
+
if (existing) {
|
|
134
|
+
acceptTr(accept, 'error', { node }, 'NL.E0300', {
|
|
135
|
+
name,
|
|
136
|
+
location: locationOf(existing),
|
|
137
|
+
});
|
|
138
|
+
} else {
|
|
139
|
+
seen.set(name, node);
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
if (file.roadmapDecl?.name) {
|
|
144
|
+
register(file.roadmapDecl.name, file.roadmapDecl);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
for (const entry of file.roadmapEntries) {
|
|
148
|
+
forEachDeclaredId(entry, register);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
for (const entry of file.configEntries) {
|
|
152
|
+
if (isStyleDeclaration(entry) && entry.name) {
|
|
153
|
+
register(entry.name, entry);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// --- Rule 7: Mixed tabs and spaces in indentation ---
|
|
159
|
+
export function checkIndentationConsistency(file: NowlineFile, accept: ValidationAcceptor): void {
|
|
160
|
+
const text = file.$document?.textDocument.getText() ?? file.$cstNode?.text;
|
|
161
|
+
if (!text) return;
|
|
162
|
+
const lines = text.split(/\r?\n/);
|
|
163
|
+
for (let i = 0; i < lines.length; i++) {
|
|
164
|
+
const line = lines[i];
|
|
165
|
+
if (line.length === 0) continue;
|
|
166
|
+
const match = line.match(/^([\t ]+)/);
|
|
167
|
+
if (!match) continue;
|
|
168
|
+
const indent = match[1];
|
|
169
|
+
if (indent.includes('\t') && indent.includes(' ')) {
|
|
170
|
+
acceptTr(accept, 'error', { node: file }, 'NL.E0005', { line: i + 1 });
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// --- Rule 6: At least one swimlane ---
|
|
177
|
+
export function checkSwimlaneRequired(file: NowlineFile, accept: ValidationAcceptor): void {
|
|
178
|
+
const hasSwimlane = file.roadmapEntries.some(isSwimlaneDeclaration);
|
|
179
|
+
if (file.roadmapDecl && !hasSwimlane) {
|
|
180
|
+
acceptTr(accept, 'error', { node: file.roadmapDecl }, 'NL.E0004');
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// --- Include rules 5/6: mode values ---
|
|
185
|
+
export function checkIncludeMode(option: IncludeOption, accept: ValidationAcceptor): void {
|
|
186
|
+
if (!INCLUDE_MODES.has(option.value)) {
|
|
187
|
+
acceptTr(accept, 'error', { node: option, property: 'value' }, 'NL.E0200', {
|
|
188
|
+
value: option.value,
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// --- Include rule 4 (partial): Duplicate include options ---
|
|
194
|
+
export function checkIncludeDuplicateOptions(
|
|
195
|
+
inc: IncludeDeclaration,
|
|
196
|
+
accept: ValidationAcceptor,
|
|
197
|
+
): void {
|
|
198
|
+
const keys = new Set<string>();
|
|
199
|
+
for (const opt of inc.options) {
|
|
200
|
+
const normalized = propKey(opt);
|
|
201
|
+
if (keys.has(normalized)) {
|
|
202
|
+
acceptTr(accept, 'error', { node: opt }, 'NL.E0201', { key: normalized });
|
|
203
|
+
}
|
|
204
|
+
keys.add(normalized);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
// `default` line checks and the hidden timeline strip warning NL.W0704
|
|
2
|
+
// (specs/core-ast-utilities.md §3.6). Moved out of nowline-validator.ts as-is; the class
|
|
3
|
+
// forwards one method per check.
|
|
4
|
+
|
|
5
|
+
import type { ValidationAcceptor } from 'langium';
|
|
6
|
+
import type {
|
|
7
|
+
DefaultDeclaration,
|
|
8
|
+
EntityProperty,
|
|
9
|
+
LabelDeclaration,
|
|
10
|
+
NowlineFile,
|
|
11
|
+
StyleDeclaration,
|
|
12
|
+
StyleProperty,
|
|
13
|
+
} from '../../generated/ast.js';
|
|
14
|
+
import {
|
|
15
|
+
isDefaultDeclaration,
|
|
16
|
+
isLabelDeclaration,
|
|
17
|
+
isStyleDeclaration,
|
|
18
|
+
} from '../../generated/ast.js';
|
|
19
|
+
import { propKey } from '../../util/props.js';
|
|
20
|
+
import { styleLayers } from '../style-chain.js';
|
|
21
|
+
import { defaultBannedMessage } from '../validator-utils.js';
|
|
22
|
+
import { acceptTr } from './support.js';
|
|
23
|
+
import { DEFAULT_BANNED, DEFAULT_ENTITY_TYPES, ROADMAP_ONLY_STYLE_KEYS } from './tables.js';
|
|
24
|
+
|
|
25
|
+
// --- Defaults rules 21-23: entity-type whitelist, duplicate-per-entity, banned props ---
|
|
26
|
+
// Plus rule 20's roadmap-only keys on another entity's default (NL.W0703).
|
|
27
|
+
export function checkDefaultDeclaration(
|
|
28
|
+
decl: DefaultDeclaration,
|
|
29
|
+
accept: ValidationAcceptor,
|
|
30
|
+
): void {
|
|
31
|
+
if (!DEFAULT_ENTITY_TYPES.has(decl.entityType)) {
|
|
32
|
+
accept(
|
|
33
|
+
'error',
|
|
34
|
+
`"${decl.entityType}" is not a supported entity type for default. Allowed: ${[...DEFAULT_ENTITY_TYPES].join(', ')}.`,
|
|
35
|
+
{ node: decl, property: 'entityType' },
|
|
36
|
+
);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Duplicate default <entity> within the same file.
|
|
41
|
+
const file = decl.$container;
|
|
42
|
+
let firstIdx = -1;
|
|
43
|
+
for (let i = 0; i < file.configEntries.length; i++) {
|
|
44
|
+
const other = file.configEntries[i];
|
|
45
|
+
if (isDefaultDeclaration(other) && other.entityType === decl.entityType) {
|
|
46
|
+
if (firstIdx < 0) {
|
|
47
|
+
firstIdx = i;
|
|
48
|
+
} else if (other === decl) {
|
|
49
|
+
accept(
|
|
50
|
+
'error',
|
|
51
|
+
`Duplicate "default ${decl.entityType}" declaration. Only one is allowed per entity type per file.`,
|
|
52
|
+
{ node: decl },
|
|
53
|
+
);
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const banned = DEFAULT_BANNED[decl.entityType];
|
|
60
|
+
if (banned) {
|
|
61
|
+
for (const prop of decl.properties) {
|
|
62
|
+
const key = propKey(prop);
|
|
63
|
+
if (banned.has(key)) {
|
|
64
|
+
accept('error', defaultBannedMessage(key, decl.entityType), { node: prop });
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (decl.entityType !== 'roadmap') {
|
|
70
|
+
for (const prop of decl.properties) {
|
|
71
|
+
const key = propKey(prop);
|
|
72
|
+
if (ROADMAP_ONLY_STYLE_KEYS.has(key)) {
|
|
73
|
+
acceptTr(accept, 'warning', { node: prop, property: 'key' }, 'NL.W0703', {
|
|
74
|
+
key,
|
|
75
|
+
entityType: decl.entityType,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// --- Rule 20: header-height:none hides the timeline-position strips (NL.W0704) ---
|
|
83
|
+
// `none` drops every date strip, so `timeline-position:bottom|both` draws
|
|
84
|
+
// nothing. Walks the roadmap's style chain (core's `styleLayers`, the one
|
|
85
|
+
// @nowline/layout's resolveStyle applies): `default roadmap` (its `style:`
|
|
86
|
+
// block, then its own keys), then the style of each label on the roadmap
|
|
87
|
+
// line from last to first (so the first label wins), then the roadmap's
|
|
88
|
+
// own `style:`, a later key winning. A style or label this file does not
|
|
89
|
+
// declare (one from an include) could reset either key, so the check
|
|
90
|
+
// stays silent then.
|
|
91
|
+
export function checkHiddenTimelineStrip(file: NowlineFile, accept: ValidationAcceptor): void {
|
|
92
|
+
const roadmap = file.roadmapDecl;
|
|
93
|
+
if (!roadmap) return;
|
|
94
|
+
|
|
95
|
+
// File-local sources, first declaration of each id wins.
|
|
96
|
+
const styles = new Map<string, StyleDeclaration>();
|
|
97
|
+
const defaults = new Map<string, DefaultDeclaration>();
|
|
98
|
+
for (const entry of file.configEntries) {
|
|
99
|
+
if (isStyleDeclaration(entry) && entry.name && !styles.has(entry.name)) {
|
|
100
|
+
styles.set(entry.name, entry);
|
|
101
|
+
} else if (isDefaultDeclaration(entry) && entry.entityType === 'roadmap') {
|
|
102
|
+
if (!defaults.has('roadmap')) defaults.set('roadmap', entry);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const labels = new Map<string, LabelDeclaration>();
|
|
106
|
+
for (const entry of file.roadmapEntries) {
|
|
107
|
+
if (isLabelDeclaration(entry) && entry.name && !labels.has(entry.name)) {
|
|
108
|
+
labels.set(entry.name, entry);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
let headerHeight: EntityProperty | StyleProperty | undefined;
|
|
113
|
+
let position: EntityProperty | StyleProperty | undefined;
|
|
114
|
+
const apply = (props: ReadonlyArray<EntityProperty | StyleProperty>): void => {
|
|
115
|
+
for (const prop of props) {
|
|
116
|
+
const key = propKey(prop);
|
|
117
|
+
if (key === 'header-height') headerHeight = prop;
|
|
118
|
+
else if (key === 'timeline-position') position = prop;
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
for (const layer of styleLayers('roadmap', roadmap.properties, {
|
|
122
|
+
styles,
|
|
123
|
+
defaults,
|
|
124
|
+
labels,
|
|
125
|
+
})) {
|
|
126
|
+
switch (layer.level) {
|
|
127
|
+
// The roadmap line's own keys are raw style keys, an error of their
|
|
128
|
+
// own; this check never read them.
|
|
129
|
+
case 'inline':
|
|
130
|
+
break;
|
|
131
|
+
case 'default':
|
|
132
|
+
apply(layer.props);
|
|
133
|
+
break;
|
|
134
|
+
// A label or style this file does not declare (an include may):
|
|
135
|
+
// the outcome is unknown, so stay silent.
|
|
136
|
+
case 'label':
|
|
137
|
+
return;
|
|
138
|
+
default:
|
|
139
|
+
if (!layer.decl) return;
|
|
140
|
+
apply(layer.decl.properties);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (headerHeight?.value !== 'none') return;
|
|
145
|
+
if (position?.value !== 'bottom' && position?.value !== 'both') return;
|
|
146
|
+
acceptTr(accept, 'warning', { node: position, property: 'value' }, 'NL.W0704', {
|
|
147
|
+
position: position.value,
|
|
148
|
+
});
|
|
149
|
+
}
|