@starci/eslint-canon-be 3.4.43 → 3.4.45
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/CHANGELOG.md +6 -0
- package/feature-thin.mjs +4 -4
- package/idempotency.mjs +147 -38
- package/package.json +1 -1
- package/runtime/knowledge/grammars/index.yaml +111 -0
- package/runtime/knowledge/hfs/canon-pins.yaml +22 -8
- package/runtime/knowledge/hfs/fe-stack.yaml +12 -4
- package/runtime/knowledge/hfs/rules.yaml +163 -83
- package/runtime/knowledge/hfs/slots.yaml +3 -3
- package/runtime/modules/kernel/removed-vocabulary.yaml +29 -0
- package/runtime/scripts/hfs/architecture/config.mjs +8 -8
- package/runtime/scripts/hfs/declaration-shape.mjs +8 -2
- package/runtime/scripts/hfs/rule-catalog.mjs +2 -2
- package/runtime/scripts/hfs/slots.mjs +1 -0
- package/runtime/scripts/hfs/view.mjs +1 -0
- package/runtime/scripts/lib/grammar-lint.mjs +48 -0
|
@@ -73,11 +73,17 @@ function extraPackageProblems(side, entries) {
|
|
|
73
73
|
return [];
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
function grammarProblems(side, grammar) {
|
|
77
|
+
if (grammar === undefined) return [];
|
|
78
|
+
if (side !== 'fe') return ['grammar belongs to the fe side'];
|
|
79
|
+
return typeof grammar === 'string' && NAME.test(grammar) ? [] : ['sides.fe.grammar must name a Grammar family'];
|
|
80
|
+
}
|
|
81
|
+
|
|
76
82
|
function declarationSideProblems(side, value, names) {
|
|
77
83
|
const bad = [];
|
|
78
84
|
const at = `sides.${side}`;
|
|
79
85
|
if (!isPlainObject(value)) return [`${at} must be an object`];
|
|
80
|
-
for (const key of Object.keys(value)) if (!['apps', 'optionalSlots', 'patterns', 'kinds', 'connections', 'reads', 'extraPackages', 'backing'].includes(key)) bad.push(`${at} has unknown key ${key}`);
|
|
86
|
+
for (const key of Object.keys(value)) if (!['apps', 'optionalSlots', 'patterns', 'kinds', 'connections', 'reads', 'extraPackages', 'grammar', 'backing'].includes(key)) bad.push(`${at} has unknown key ${key}`);
|
|
81
87
|
bad.push(...appShapeProblems(value.apps, at, side, names));
|
|
82
88
|
if (isBadUniqueList(value.optionalSlots, (slot) => SLOT_ID.test(String(slot)))) bad.push(`${at}.optionalSlots must be a unique list of slot ids`);
|
|
83
89
|
if (value.backing !== undefined && side !== 'be') bad.push('backing belongs to the be side');
|
|
@@ -85,7 +91,7 @@ function declarationSideProblems(side, value, names) {
|
|
|
85
91
|
bad.push(...patternShapeProblems(value, at, NAME), ...kindShapeProblems(value, at, NAME));
|
|
86
92
|
if (isBadUniqueList(value.reads, (read) => typeof read === 'string' && read.length > 0)) bad.push(`${at}.reads must be a unique list of paths`);
|
|
87
93
|
if (value.connections !== undefined) bad.push(...connectionProblems(side, value));
|
|
88
|
-
bad.push(...extraPackageProblems(side, value.extraPackages));
|
|
94
|
+
bad.push(...extraPackageProblems(side, value.extraPackages), ...grammarProblems(side, value.grammar));
|
|
89
95
|
return bad;
|
|
90
96
|
}
|
|
91
97
|
|
|
@@ -12,7 +12,7 @@ import { fail } from './slot-errors.mjs';
|
|
|
12
12
|
|
|
13
13
|
const HFS_RULES_FILE = 'knowledge/hfs/rules.yaml';
|
|
14
14
|
const RULE_GATES = Object.freeze(['pre-commit', 'pre-push', 'settle', 'land', 'ci', 'sonar', 'runtime']);
|
|
15
|
-
const ENFORCER_FAMILIES = Object.freeze(['eslint-be', 'eslint-fe', 'stylelint', 'machine', 'hfs', 'work-validate', 'sonar', 'runtime']);
|
|
15
|
+
const ENFORCER_FAMILIES = Object.freeze(['eslint-be', 'eslint-fe', 'eslint-grammar-starci', 'stylelint', 'machine', 'hfs', 'work-validate', 'sonar', 'runtime']);
|
|
16
16
|
const RULE_KINDS = Object.freeze(['codemod', 'lint', 'check', 'design']);
|
|
17
17
|
const FINDING_CODE = /^[A-Z][A-Z0-9]*(_[A-Z0-9]+)+$/;
|
|
18
18
|
const ENFORCER_ID = /^[a-z][a-z0-9]*(-[a-z0-9]+)*$/;
|
|
@@ -346,7 +346,7 @@ export function loadRuleCatalog({ root = skillRoot, file = path.join(root, HFS_R
|
|
|
346
346
|
/** The catalogued why code of a lint finding's rule id (`starci-be/<id>`, `starci-fe/<id>`), or undefined. */
|
|
347
347
|
lintCode: (ruleId) => {
|
|
348
348
|
const [plugin, id] = String(ruleId ?? '').split('/');
|
|
349
|
-
const kind = (plugin === 'starci-be' && 'eslint-be') || (plugin === 'starci-fe' && 'eslint-fe') || null;
|
|
349
|
+
const kind = (plugin === 'starci-be' && 'eslint-be') || (plugin === 'starci-fe' && 'eslint-fe') || (plugin === 'starci-grammar' && 'eslint-grammar-starci') || null;
|
|
350
350
|
return kind ? list.find((rule) => rule.enforcers.some((enforcer) => enforcer.kind === kind && enforcer.id === id))?.code : undefined;
|
|
351
351
|
},
|
|
352
352
|
/** The rules one enforcer judges, e.g. forEnforcer('eslint-be', 'error-home'). */
|
|
@@ -120,6 +120,7 @@ function sideDeclaration(manifest, declaration, name, edition, providers) {
|
|
|
120
120
|
connections: Object.freeze((s.connections ?? []).map(connectionView)),
|
|
121
121
|
providers,
|
|
122
122
|
reads: Object.freeze([...(s.reads ?? [])]),
|
|
123
|
+
...(s.grammar === undefined ? {} : { grammar: s.grammar }),
|
|
123
124
|
...(s.extraPackages === undefined ? {} : { extraPackages: Object.freeze(s.extraPackages.map(entry => Object.freeze({ ...entry }))) }),
|
|
124
125
|
manifestVersion: manifest.version,
|
|
125
126
|
});
|
|
@@ -33,6 +33,7 @@ function hfsView(opened, repoRoot) {
|
|
|
33
33
|
profile: opened.repo.profile,
|
|
34
34
|
side: opened.repo.side ?? null,
|
|
35
35
|
edition: opened.repo.edition ?? 'full',
|
|
36
|
+
...(opened.repo.grammar === undefined ? {} : { grammar: opened.repo.grammar }),
|
|
36
37
|
apps: opened.repo.apps,
|
|
37
38
|
connections: opened.repo.connections,
|
|
38
39
|
patterns: Object.freeze([...(opened.repo.patterns ?? [])]),
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Grammar-family lint selection reads the family catalog; an absent selection never chooses a family.
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import { parseYamlCached } from './yaml-cached.mjs';
|
|
4
|
+
|
|
5
|
+
const CATALOG_FILE = new URL('../../knowledge/grammars/index.yaml', import.meta.url);
|
|
6
|
+
|
|
7
|
+
function selectedFamily(family) {
|
|
8
|
+
if (typeof family !== 'string' || !family.trim()) throw new Error('sides.fe.grammar must explicitly name the selected Grammar family');
|
|
9
|
+
const catalog = parseYamlCached(fs.readFileSync(CATALOG_FILE, 'utf8'));
|
|
10
|
+
const matches = (catalog.families ?? []).filter(entry => entry.id === family);
|
|
11
|
+
if (matches.length !== 1) throw new Error(`Grammar family ${family} has no declared lint contract in knowledge/grammars/index.yaml`);
|
|
12
|
+
return { catalog, selected: matches[0] };
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** The explicitly selected authored family entry; callers share the catalog lookup rather than inferring a family. */
|
|
16
|
+
export function grammarFamilyFor(family) {
|
|
17
|
+
return Object.freeze(selectedFamily(family).selected);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** The declared family's lint contract, including an explicit null package when that family has no rules. */
|
|
21
|
+
export function grammarLintFor(family) {
|
|
22
|
+
const { selected } = selectedFamily(family);
|
|
23
|
+
if (!selected.lint || !Object.hasOwn(selected.lint, 'package')) {
|
|
24
|
+
throw new Error(`Grammar family ${family} has no declared lint contract in knowledge/grammars/index.yaml`);
|
|
25
|
+
}
|
|
26
|
+
const lint = selected.lint;
|
|
27
|
+
if (lint.package === null) return Object.freeze({ family, package: null });
|
|
28
|
+
if (typeof lint.package !== 'string' || !lint.package.startsWith('@starci/eslint-grammar-')
|
|
29
|
+
|| typeof lint.factory !== 'string' || !/^[a-zA-Z][a-zA-Z0-9]*$/.test(lint.factory)
|
|
30
|
+
|| typeof lint.prefix !== 'string' || !/^[a-z][a-z0-9-]*$/.test(lint.prefix)) {
|
|
31
|
+
throw new Error(`Grammar family ${family} has an invalid lint contract in knowledge/grammars/index.yaml`);
|
|
32
|
+
}
|
|
33
|
+
return Object.freeze({ family, package: lint.package, factory: lint.factory, prefix: lint.prefix });
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The selected family's shared component/export contract, resolved through its catalog reference. */
|
|
37
|
+
export function grammarContractFor(family) {
|
|
38
|
+
const { catalog, selected } = selectedFamily(family);
|
|
39
|
+
const owners = (catalog.families ?? []).filter(entry => entry.id === selected.contractRef);
|
|
40
|
+
const contract = owners.length === 1 ? owners[0].componentContract : null;
|
|
41
|
+
if (!contract || typeof contract.package !== 'string' || !contract.package
|
|
42
|
+
|| typeof contract.entry !== 'string' || !contract.entry.startsWith(`${contract.package}/`)
|
|
43
|
+
|| typeof contract.styleEntry !== 'string' || !contract.styleEntry.startsWith(`${contract.package}/`)
|
|
44
|
+
|| !Array.isArray(contract.peers) || !contract.peers.every(peer => typeof peer === 'string' && peer.trim())) {
|
|
45
|
+
throw new Error(`Grammar family ${family} has no valid component contract in knowledge/grammars/index.yaml`);
|
|
46
|
+
}
|
|
47
|
+
return Object.freeze({ ...contract, peers: Object.freeze([...contract.peers]) });
|
|
48
|
+
}
|