@starci/eslint-canon-be 3.4.42 → 3.4.44

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.
@@ -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
+ }