@starci/eslint-canon-be 3.18.4 → 3.19.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/CHANGELOG.md +4 -0
- package/dist/comments.js +1 -1
- package/dist/explicit-surface.js +1 -1
- package/dist/index.js +1 -1
- package/dist/jwt-alg.js +1 -1
- package/dist/lib/edition.d.ts +1 -1
- package/dist/lib/edition.js +1 -1
- package/dist/lib/hfs.d.ts +0 -6
- package/dist/lib/hfs.js +7 -5
- package/dist/lib/runtime-root.d.ts +6 -1
- package/dist/lib/runtime-root.js +8 -2
- package/dist/lib/subject-values.js +1 -1
- package/dist/module-layering.js +2 -2
- package/dist/project-graph.js +1 -1
- package/dist/third-party-owner.js +1 -1
- package/package.json +3 -1
- package/runtime/bundle.json +1 -190
- package/runtime/scripts/api/git/recorded-lines.mjs +5 -5
- package/runtime/scripts/hfs/project-graph.mjs +6 -6
- package/runtime/scripts/hfs/project-rule.mjs +3 -3
- package/runtime/config.example.yaml +0 -194
- package/runtime/engine/by-code-unit.mjs +0 -12
- package/runtime/engine/config.mjs +0 -461
- package/runtime/engine/invalid-config.mjs +0 -15
- package/runtime/engine/model-config.mjs +0 -112
- package/runtime/engine/orca-config.mjs +0 -34
- package/runtime/engine/plain-object.mjs +0 -5
- package/runtime/engine/release-config.mjs +0 -32
- package/runtime/engine/removed-vocabulary.mjs +0 -27
- package/runtime/engine/resources-config.mjs +0 -59
- package/runtime/engine/runtime-root.mjs +0 -138
- package/runtime/engine/secrets.mjs +0 -202
- package/runtime/engine/sonar-config.mjs +0 -24
- package/runtime/engine/temp-root.mjs +0 -26
- package/runtime/engine/yaml.mjs +0 -161
- package/runtime/knowledge/grammars/index.yaml +0 -114
- package/runtime/knowledge/hfs/canon-pins.yaml +0 -720
- package/runtime/knowledge/hfs/fe-stack.yaml +0 -272
- package/runtime/knowledge/hfs/rules.yaml +0 -6760
- package/runtime/knowledge/hfs/slots.yaml +0 -2783
- package/runtime/knowledge/patterns/fe/folder.yaml +0 -425
- package/runtime/knowledge/sonar-gate.yaml +0 -151
- package/runtime/modules/kernel/removed-vocabulary.yaml +0 -458
- package/runtime/modules/models/registry.yaml +0 -221
- package/runtime/modules/models/runtimes.yaml +0 -556
- package/runtime/modules/models/tiers.yaml +0 -66
- package/runtime/scripts/api/git/cat-file.mjs +0 -4
- package/runtime/scripts/api/git/config-get.mjs +0 -9
- package/runtime/scripts/api/git/diff.mjs +0 -4
- package/runtime/scripts/api/git/lib.mjs +0 -80
- package/runtime/scripts/api/git/ls-files.mjs +0 -5
- package/runtime/scripts/api/git/ls-tree.mjs +0 -4
- package/runtime/scripts/api/git/merge-base.mjs +0 -8
- package/runtime/scripts/api/git/remote.mjs +0 -4
- package/runtime/scripts/api/git/rev-parse-query.mjs +0 -4
- package/runtime/scripts/api/git/show.mjs +0 -5
- package/runtime/scripts/api/git/tag.mjs +0 -4
- package/runtime/scripts/hfs/allows.mjs +0 -77
- package/runtime/scripts/hfs/architecture/ast-walks.mjs +0 -250
- package/runtime/scripts/hfs/architecture/automatic-gates.mjs +0 -103
- package/runtime/scripts/hfs/architecture/backend-app-files.mjs +0 -114
- package/runtime/scripts/hfs/architecture/backend.mjs +0 -462
- package/runtime/scripts/hfs/architecture/background-unowned.mjs +0 -254
- package/runtime/scripts/hfs/architecture/canon-clones.mjs +0 -291
- package/runtime/scripts/hfs/architecture/canon-jsx-clones.mjs +0 -224
- package/runtime/scripts/hfs/architecture/client-reaches-server.mjs +0 -102
- package/runtime/scripts/hfs/architecture/clones.mjs +0 -287
- package/runtime/scripts/hfs/architecture/component-tiers.mjs +0 -161
- package/runtime/scripts/hfs/architecture/config-unread.mjs +0 -16
- package/runtime/scripts/hfs/architecture/config.mjs +0 -407
- package/runtime/scripts/hfs/architecture/connection-map.mjs +0 -350
- package/runtime/scripts/hfs/architecture/constructor-deps.mjs +0 -115
- package/runtime/scripts/hfs/architecture/context-coupling.mjs +0 -117
- package/runtime/scripts/hfs/architecture/context-map.mjs +0 -355
- package/runtime/scripts/hfs/architecture/context-owner.mjs +0 -102
- package/runtime/scripts/hfs/architecture/context-platform-tables.mjs +0 -65
- package/runtime/scripts/hfs/architecture/context-transaction.mjs +0 -75
- package/runtime/scripts/hfs/architecture/contract-bounds.mjs +0 -72
- package/runtime/scripts/hfs/architecture/contract-fixture-guard.mjs +0 -177
- package/runtime/scripts/hfs/architecture/contracts-readonly.mjs +0 -360
- package/runtime/scripts/hfs/architecture/contracts.mjs +0 -489
- package/runtime/scripts/hfs/architecture/cross-app-duplicate.mjs +0 -81
- package/runtime/scripts/hfs/architecture/dead-exports-bindings.mjs +0 -173
- package/runtime/scripts/hfs/architecture/dead-exports.mjs +0 -420
- package/runtime/scripts/hfs/architecture/default-deny.mjs +0 -175
- package/runtime/scripts/hfs/architecture/doc-language.mjs +0 -45
- package/runtime/scripts/hfs/architecture/entity-registry.mjs +0 -51
- package/runtime/scripts/hfs/architecture/entrypoint.mjs +0 -75
- package/runtime/scripts/hfs/architecture/error-codes.mjs +0 -54
- package/runtime/scripts/hfs/architecture/error-masked.mjs +0 -78
- package/runtime/scripts/hfs/architecture/fe-slot-allows.mjs +0 -44
- package/runtime/scripts/hfs/architecture/feature-shape.mjs +0 -60
- package/runtime/scripts/hfs/architecture/framework-pinned.mjs +0 -41
- package/runtime/scripts/hfs/architecture/frontend-block-render.mjs +0 -112
- package/runtime/scripts/hfs/architecture/frontend-grammar.mjs +0 -193
- package/runtime/scripts/hfs/architecture/frontend-routing.mjs +0 -198
- package/runtime/scripts/hfs/architecture/frontend-world-render.mjs +0 -368
- package/runtime/scripts/hfs/architecture/frontend-world.mjs +0 -374
- package/runtime/scripts/hfs/architecture/frontend.mjs +0 -248
- package/runtime/scripts/hfs/architecture/function-spec-providers.mjs +0 -185
- package/runtime/scripts/hfs/architecture/hfs-graph.mjs +0 -77
- package/runtime/scripts/hfs/architecture/hfs.mjs +0 -394
- package/runtime/scripts/hfs/architecture/hooks-are-hooks.mjs +0 -118
- package/runtime/scripts/hfs/architecture/i18n-keys.mjs +0 -213
- package/runtime/scripts/hfs/architecture/identity.mjs +0 -121
- package/runtime/scripts/hfs/architecture/index.mjs +0 -402
- package/runtime/scripts/hfs/architecture/injection-token-exported.mjs +0 -69
- package/runtime/scripts/hfs/architecture/jwt-ast.mjs +0 -231
- package/runtime/scripts/hfs/architecture/machine-ast.mjs +0 -232
- package/runtime/scripts/hfs/architecture/managed-scripts.mjs +0 -32
- package/runtime/scripts/hfs/architecture/module-per-transport.mjs +0 -237
- package/runtime/scripts/hfs/architecture/next-data-contract.mjs +0 -126
- package/runtime/scripts/hfs/architecture/next-data-inference.mjs +0 -192
- package/runtime/scripts/hfs/architecture/next-data-key.mjs +0 -374
- package/runtime/scripts/hfs/architecture/next-data-symbols.mjs +0 -26
- package/runtime/scripts/hfs/architecture/next-data.mjs +0 -425
- package/runtime/scripts/hfs/architecture/operation-contract-roots.mjs +0 -55
- package/runtime/scripts/hfs/architecture/owners.mjs +0 -142
- package/runtime/scripts/hfs/architecture/package-shape.mjs +0 -92
- package/runtime/scripts/hfs/architecture/presentation.mjs +0 -173
- package/runtime/scripts/hfs/architecture/reachability.mjs +0 -330
- package/runtime/scripts/hfs/architecture/register-once.mjs +0 -212
- package/runtime/scripts/hfs/architecture/registration.mjs +0 -372
- package/runtime/scripts/hfs/architecture/render-graph.mjs +0 -449
- package/runtime/scripts/hfs/architecture/render-prop-across-server.mjs +0 -58
- package/runtime/scripts/hfs/architecture/required-files.mjs +0 -237
- package/runtime/scripts/hfs/architecture/root-packages.mjs +0 -78
- package/runtime/scripts/hfs/architecture/route-files-thin.mjs +0 -133
- package/runtime/scripts/hfs/architecture/schema-owner.mjs +0 -288
- package/runtime/scripts/hfs/architecture/server-action.mjs +0 -78
- package/runtime/scripts/hfs/architecture/side-boundary.mjs +0 -13
- package/runtime/scripts/hfs/architecture/source-names-shape.mjs +0 -320
- package/runtime/scripts/hfs/architecture/source-names.mjs +0 -393
- package/runtime/scripts/hfs/architecture/sql-keys.mjs +0 -344
- package/runtime/scripts/hfs/architecture/sql-owner.mjs +0 -291
- package/runtime/scripts/hfs/architecture/sql-returning.mjs +0 -76
- package/runtime/scripts/hfs/architecture/sql-token-forms.mjs +0 -117
- package/runtime/scripts/hfs/architecture/sql-tokens.mjs +0 -587
- package/runtime/scripts/hfs/architecture/staged-consumers.mjs +0 -42
- package/runtime/scripts/hfs/architecture/surface-nesting.mjs +0 -127
- package/runtime/scripts/hfs/architecture/surface.mjs +0 -88
- package/runtime/scripts/hfs/architecture/symbols.mjs +0 -273
- package/runtime/scripts/hfs/architecture/test-world-files.mjs +0 -263
- package/runtime/scripts/hfs/architecture/tiers.mjs +0 -256
- package/runtime/scripts/hfs/architecture/transport-owner.mjs +0 -248
- package/runtime/scripts/hfs/architecture/type-context.mjs +0 -335
- package/runtime/scripts/hfs/architecture/typescript.mjs +0 -477
- package/runtime/scripts/hfs/architecture/unit-spec-providers.mjs +0 -165
- package/runtime/scripts/hfs/declaration-shape.mjs +0 -196
- package/runtime/scripts/hfs/declaration-slots.mjs +0 -89
- package/runtime/scripts/hfs/edition-slots.mjs +0 -80
- package/runtime/scripts/hfs/explicit-surface-rule.mjs +0 -59
- package/runtime/scripts/hfs/linear-text.mjs +0 -30
- package/runtime/scripts/hfs/manifest-shape.mjs +0 -474
- package/runtime/scripts/hfs/param-names.mjs +0 -13
- package/runtime/scripts/hfs/path-findings.mjs +0 -167
- package/runtime/scripts/hfs/repo-identity.mjs +0 -89
- package/runtime/scripts/hfs/rule-catalog.mjs +0 -458
- package/runtime/scripts/hfs/rule-params-shape.mjs +0 -103
- package/runtime/scripts/hfs/rules/database-constants.mjs +0 -25
- package/runtime/scripts/hfs/rules/database-migrations.mjs +0 -684
- package/runtime/scripts/hfs/rules/fe-no-tests.mjs +0 -68
- package/runtime/scripts/hfs/rules/read.mjs +0 -45
- package/runtime/scripts/hfs/rules/secrets.mjs +0 -79
- package/runtime/scripts/hfs/rules/spec-placement.mjs +0 -28
- package/runtime/scripts/hfs/slot-app-view.mjs +0 -97
- package/runtime/scripts/hfs/slot-classify.mjs +0 -69
- package/runtime/scripts/hfs/slot-errors.mjs +0 -12
- package/runtime/scripts/hfs/slot-imports.mjs +0 -98
- package/runtime/scripts/hfs/slot-manifest-shape.mjs +0 -111
- package/runtime/scripts/hfs/slot-match.mjs +0 -164
- package/runtime/scripts/hfs/slot-path.mjs +0 -6
- package/runtime/scripts/hfs/slot-required.mjs +0 -95
- package/runtime/scripts/hfs/slot-semantic-problems.mjs +0 -175
- package/runtime/scripts/hfs/slot-side-problems.mjs +0 -32
- package/runtime/scripts/hfs/slots.mjs +0 -306
- package/runtime/scripts/hfs/test-world-slot.mjs +0 -5
- package/runtime/scripts/hfs/trailing-slashes.mjs +0 -8
- package/runtime/scripts/hfs/typescript-programs.mjs +0 -95
- package/runtime/scripts/hfs/view.mjs +0 -180
- package/runtime/scripts/lib/declaration-surface.mjs +0 -166
- package/runtime/scripts/lib/dockerfile.mjs +0 -164
- package/runtime/scripts/lib/env.mjs +0 -18
- package/runtime/scripts/lib/event-contract.mjs +0 -102
- package/runtime/scripts/lib/git-hooks-dir.mjs +0 -30
- package/runtime/scripts/lib/git.mjs +0 -35
- package/runtime/scripts/lib/glob.mjs +0 -32
- package/runtime/scripts/lib/grammar-lint.mjs +0 -57
- package/runtime/scripts/lib/i18n.mjs +0 -82
- package/runtime/scripts/lib/in-order.mjs +0 -90
- package/runtime/scripts/lib/json-clone.mjs +0 -70
- package/runtime/scripts/lib/json.mjs +0 -44
- package/runtime/scripts/lib/language.mjs +0 -233
- package/runtime/scripts/lib/list.mjs +0 -26
- package/runtime/scripts/lib/mutation-fence.mjs +0 -20
- package/runtime/scripts/lib/package-at.mjs +0 -62
- package/runtime/scripts/lib/path-key.mjs +0 -124
- package/runtime/scripts/lib/read-text.mjs +0 -47
- package/runtime/scripts/lib/regex.mjs +0 -3
- package/runtime/scripts/lib/rule-packs.mjs +0 -243
- package/runtime/scripts/lib/same-text.mjs +0 -4
- package/runtime/scripts/lib/secret-patterns.mjs +0 -230
- package/runtime/scripts/lib/sops-envelope.mjs +0 -212
- package/runtime/scripts/lib/stack-services.mjs +0 -191
- package/runtime/scripts/lib/ts-analysis.mjs +0 -39
- package/runtime/scripts/lib/ts-ast.mjs +0 -63
- package/runtime/scripts/lib/walk.mjs +0 -45
- package/runtime/scripts/lib/yaml-cached.mjs +0 -14
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
import { isPlainObject } from '../../engine/plain-object.mjs';
|
|
2
|
-
import { APP_KIND, connectionShapeProblems, NAME, PACKAGE_NAME, RUNTIME_KIND, SLOT_ID } from './manifest-shape.mjs';
|
|
3
|
-
import { dbFunctionsOk, sqlPassThroughOk } from './rule-params-shape.mjs';
|
|
4
|
-
import { kindShapeProblems, patternShapeProblems } from './declaration-slots.mjs';
|
|
5
|
-
import { byCodeUnit } from '../lib/list.mjs';
|
|
6
|
-
/** Shape problems of the optional hfs.json `db` block of a lite app: the environment variable naming its database, its image, forced RLS and its application role. */
|
|
7
|
-
const isStringList = (value) => Array.isArray(value) && value.every((entry) => typeof entry === 'string' && entry.trim());
|
|
8
|
-
/** One owner ruling on a migration's destructive DDL: the exact file, the exact objects, the reason and the date the owner ruled it. */
|
|
9
|
-
const isDestructiveRuling = (ruling) => isPlainObject(ruling)
|
|
10
|
-
&& typeof ruling.migration === 'string' && /^db\/migrations\/\d{14}_[a-z0-9_-]+\.sql$/.test(ruling.migration)
|
|
11
|
-
&& isStringList(ruling.objects) && ruling.objects.length > 0
|
|
12
|
-
&& typeof ruling.reason === 'string' && ruling.reason.trim() !== ''
|
|
13
|
-
&& typeof ruling.date === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(ruling.date)
|
|
14
|
-
&& Object.keys(ruling).every((key) => ['migration', 'objects', 'reason', 'date'].includes(key));
|
|
15
|
-
function dbBlockProblems(block) {
|
|
16
|
-
if (block === undefined)
|
|
17
|
-
return [];
|
|
18
|
-
if (!isPlainObject(block))
|
|
19
|
-
return ['db must be an object'];
|
|
20
|
-
const bad = [];
|
|
21
|
-
for (const key of Object.keys(block))
|
|
22
|
-
if (!['urlEnv', 'image', 'forceRls', 'forceRlsExemptions', 'appRole', 'destructiveRulings'].includes(key))
|
|
23
|
-
bad.push(`db has unknown key ${key}`);
|
|
24
|
-
if (block.urlEnv !== undefined && (typeof block.urlEnv !== 'string' || !/^[A-Z][A-Z0-9_]*$/.test(block.urlEnv)))
|
|
25
|
-
bad.push('db.urlEnv must name an UPPER_CASE environment variable');
|
|
26
|
-
if (block.image !== undefined && (typeof block.image !== 'string' || !/@sha256:[0-9a-f]{64}$/.test(block.image)))
|
|
27
|
-
bad.push('db.image must be a digest-pinned image reference');
|
|
28
|
-
if (block.forceRls !== undefined && !isStringList(block.forceRls))
|
|
29
|
-
bad.push('db.forceRls must be a list of strings');
|
|
30
|
-
if (block.appRole !== undefined && (typeof block.appRole !== 'string' || !/^[a-z][a-z0-9_]*$/.test(block.appRole)))
|
|
31
|
-
bad.push('db.appRole must name a role');
|
|
32
|
-
if (block.forceRlsExemptions !== undefined && !Array.isArray(block.forceRlsExemptions))
|
|
33
|
-
bad.push('db.forceRlsExemptions must be a list of { table, reason }');
|
|
34
|
-
if (block.destructiveRulings !== undefined && !(Array.isArray(block.destructiveRulings) && block.destructiveRulings.every(isDestructiveRuling)))
|
|
35
|
-
bad.push('db.destructiveRulings must be a list of { migration, objects, reason, date } naming one db/migrations file, the objects it destroys, why and the date the owner ruled it (YYYY-MM-DD)');
|
|
36
|
-
return bad;
|
|
37
|
-
}
|
|
38
|
-
function appShapeProblems(apps, at, side, names) {
|
|
39
|
-
const bad = [];
|
|
40
|
-
if (!Array.isArray(apps) || !apps.length) {
|
|
41
|
-
bad.push(`${at}.apps must list every ${side}/apps/<name> with its kind`);
|
|
42
|
-
return bad;
|
|
43
|
-
}
|
|
44
|
-
apps.forEach((app, index) => {
|
|
45
|
-
if (!isPlainObject(app) || !NAME.test(String(app.name)) || !NAME.test(String(app.kind)) || Object.keys(app).some((key) => key !== 'name' && key !== 'kind'))
|
|
46
|
-
bad.push(`${at}.apps[${index}] must be {name, kind}`);
|
|
47
|
-
else if (names.has(app.name))
|
|
48
|
-
bad.push(`app ${app.name} is declared twice (${names.get(app.name)} and ${side})`);
|
|
49
|
-
else
|
|
50
|
-
names.set(app.name, side);
|
|
51
|
-
});
|
|
52
|
-
return bad;
|
|
53
|
-
}
|
|
54
|
-
function connectionProblems(side, value) {
|
|
55
|
-
const bad = [];
|
|
56
|
-
if (side !== 'be') {
|
|
57
|
-
bad.push('connections belong to the be side');
|
|
58
|
-
return bad;
|
|
59
|
-
}
|
|
60
|
-
const list = Array.isArray(value.connections) ? value.connections : null;
|
|
61
|
-
const shape = connectionShapeProblems(list, value.apps);
|
|
62
|
-
if (shape.length) {
|
|
63
|
-
bad.push(...shape);
|
|
64
|
-
return bad;
|
|
65
|
-
}
|
|
66
|
-
if (new Set(list.map((connection) => connection.name)).size !== list.length)
|
|
67
|
-
bad.push('connections names must be unique');
|
|
68
|
-
for (const a of list)
|
|
69
|
-
for (const b of list)
|
|
70
|
-
if (a !== b && `${b.envPrefix}_`.startsWith(`${a.envPrefix}_`))
|
|
71
|
-
bad.push(`connections ${a.name} and ${b.name} share env keys (${a.envPrefix}_ covers ${b.envPrefix}_)`);
|
|
72
|
-
return bad;
|
|
73
|
-
}
|
|
74
|
-
/** Whether a declared list is present but not a list of distinct entries that all satisfy `valid`. */
|
|
75
|
-
const isBadUniqueList = (list, valid) => list !== undefined && (!Array.isArray(list) || !list.every((entry) => valid(entry)) || new Set(list).size !== list.length);
|
|
76
|
-
function validExtraPackage(entry) {
|
|
77
|
-
return isPlainObject(entry) && Object.keys(entry).every(key => key === 'name' || key === 'reason')
|
|
78
|
-
&& typeof entry.name === 'string' && entry.name.length <= 214 && PACKAGE_NAME.test(entry.name)
|
|
79
|
-
&& typeof entry.reason === 'string' && entry.reason.trim().length > 0;
|
|
80
|
-
}
|
|
81
|
-
function extraPackageProblems(side, entries) {
|
|
82
|
-
if (entries === undefined)
|
|
83
|
-
return [];
|
|
84
|
-
if (side !== 'fe')
|
|
85
|
-
return ['extraPackages belong to the fe side'];
|
|
86
|
-
if (!Array.isArray(entries) || !entries.every(validExtraPackage))
|
|
87
|
-
return ['sides.fe.extraPackages must be a list of {name, reason} with a package name and a nonempty reason'];
|
|
88
|
-
return [];
|
|
89
|
-
}
|
|
90
|
-
function grammarProblems(side, grammar) {
|
|
91
|
-
if (grammar === undefined)
|
|
92
|
-
return [];
|
|
93
|
-
if (side !== 'fe')
|
|
94
|
-
return ['grammar belongs to the fe side'];
|
|
95
|
-
return typeof grammar === 'string' && NAME.test(grammar) ? [] : ['sides.fe.grammar must name a Grammar family'];
|
|
96
|
-
}
|
|
97
|
-
function declarationSideProblems(side, value, names) {
|
|
98
|
-
const bad = [];
|
|
99
|
-
const at = `sides.${side}`;
|
|
100
|
-
if (!isPlainObject(value))
|
|
101
|
-
return [`${at} must be an object`];
|
|
102
|
-
for (const key of Object.keys(value))
|
|
103
|
-
if (!['apps', 'optionalSlots', 'patterns', 'kinds', 'connections', 'reads', 'extraPackages', 'grammar', 'backing', 'dbFunctions', 'sqlPassThrough'].includes(key))
|
|
104
|
-
bad.push(`${at} has unknown key ${key}`);
|
|
105
|
-
if (value.dbFunctions !== undefined && (side !== 'be' || !dbFunctionsOk(value.dbFunctions, { bare: true })))
|
|
106
|
-
bad.push(`${at}.dbFunctions belongs to the be side and lists {name, reason} database functions, each schema-qualified (schema.name, never pg_catalog) or a bare pg built-in of the canon's list, with unique names`);
|
|
107
|
-
if (value.sqlPassThrough !== undefined && (side !== 'be' || !sqlPassThroughOk(value.sqlPassThrough)))
|
|
108
|
-
bad.push(`${at}.sqlPassThrough belongs to the be side and lists {file, reason} files relative to the side folder, forward slashes, unique, each with the reason its SQL text is not the app's own`);
|
|
109
|
-
bad.push(...appShapeProblems(value.apps, at, side, names));
|
|
110
|
-
if (isBadUniqueList(value.optionalSlots, (slot) => SLOT_ID.test(String(slot))))
|
|
111
|
-
bad.push(`${at}.optionalSlots must be a unique list of slot ids`);
|
|
112
|
-
if (value.backing !== undefined && side !== 'be')
|
|
113
|
-
bad.push('backing belongs to the be side');
|
|
114
|
-
else if (isBadUniqueList(value.backing, (name) => NAME.test(String(name))))
|
|
115
|
-
bad.push(`${at}.backing must be a unique list of backing service names`);
|
|
116
|
-
bad.push(...patternShapeProblems(value, at, NAME), ...kindShapeProblems(value, at, NAME));
|
|
117
|
-
if (isBadUniqueList(value.reads, (read) => typeof read === 'string' && read.length > 0))
|
|
118
|
-
bad.push(`${at}.reads must be a unique list of paths`);
|
|
119
|
-
if (value.connections !== undefined)
|
|
120
|
-
bad.push(...connectionProblems(side, value));
|
|
121
|
-
bad.push(...extraPackageProblems(side, value.extraPackages), ...grammarProblems(side, value.grammar));
|
|
122
|
-
return bad;
|
|
123
|
-
}
|
|
124
|
-
/** Product vocabulary is a declaration, never a switch for a rule. */
|
|
125
|
-
function lexiconBlockProblems(lexicon) {
|
|
126
|
-
if (lexicon === undefined)
|
|
127
|
-
return [];
|
|
128
|
-
if (!isPlainObject(lexicon))
|
|
129
|
-
return ['lexicon must be an object'];
|
|
130
|
-
const bad = [];
|
|
131
|
-
for (const key of Object.keys(lexicon))
|
|
132
|
-
if (key !== 'removed')
|
|
133
|
-
bad.push(`lexicon has unknown key ${key}`);
|
|
134
|
-
if (isBadUniqueList(lexicon.removed, (word) => typeof word === 'string' && word.trim().length > 0))
|
|
135
|
-
bad.push('lexicon.removed must be a unique list of nonempty words');
|
|
136
|
-
return bad;
|
|
137
|
-
}
|
|
138
|
-
/** Front-end error reporting remains optional in both editions. */
|
|
139
|
-
function observeBlockProblems(observe) {
|
|
140
|
-
if (observe === undefined)
|
|
141
|
-
return [];
|
|
142
|
-
if (!isPlainObject(observe))
|
|
143
|
-
return ['observe must be an object'];
|
|
144
|
-
const bad = [];
|
|
145
|
-
for (const key of Object.keys(observe))
|
|
146
|
-
if (key !== 'reporter')
|
|
147
|
-
bad.push(`observe has unknown key ${key}`);
|
|
148
|
-
if (observe.reporter !== undefined && (typeof observe.reporter !== 'string' || !observe.reporter.trim()))
|
|
149
|
-
bad.push('observe.reporter must name the optional error reporter');
|
|
150
|
-
return bad;
|
|
151
|
-
}
|
|
152
|
-
const DECLARATION_KEYS = new Set(['hfs', 'kind', 'project', 'edition', 'db', 'sides', 'browser', 'modules', 'lexicon', 'observe', 'rulePacks']);
|
|
153
|
-
/** A rule pack hfs.json names (PROJECT-LINT-3): an npm package name, each once. */
|
|
154
|
-
const RULE_PACK_NAME = /^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/u;
|
|
155
|
-
const RUNTIME_DECLARATION_KEYS = new Set(['hfs', 'kind', 'project']);
|
|
156
|
-
function productDeclarationProblems(declaration, profiles) {
|
|
157
|
-
const bad = [];
|
|
158
|
-
for (const key of Object.keys(declaration))
|
|
159
|
-
if (!DECLARATION_KEYS.has(key))
|
|
160
|
-
bad.push(`unknown key ${key}`);
|
|
161
|
-
bad.push(...dbBlockProblems(declaration.db), ...lexiconBlockProblems(declaration.lexicon), ...observeBlockProblems(declaration.observe));
|
|
162
|
-
if (declaration.browser !== undefined && declaration.browser !== true)
|
|
163
|
-
bad.push('browser is `true` when the app has a browser journey (slot app.browser), and is left out otherwise');
|
|
164
|
-
if (declaration.rulePacks !== undefined && (!Array.isArray(declaration.rulePacks) || declaration.rulePacks.length === 0 || declaration.rulePacks.some((name) => typeof name !== 'string' || !RULE_PACK_NAME.test(name)) || new Set(declaration.rulePacks).size !== declaration.rulePacks.length))
|
|
165
|
-
bad.push('rulePacks is a non-empty list of the installed rule pack packages the app adds its laws with, each once (PROJECT-LINT-3)');
|
|
166
|
-
if (declaration.modules !== undefined && declaration.modules !== 'data')
|
|
167
|
-
bad.push('modules is `"data"` when the app keeps its modules as data (seeds, no rendered registry package), and is left out otherwise');
|
|
168
|
-
if (declaration.kind !== APP_KIND)
|
|
169
|
-
bad.push(`kind must be ${APP_KIND} (a product is one app repository with a be and an fe side) or ${RUNTIME_KIND} (the StarCi runtime repository)`);
|
|
170
|
-
if (!isPlainObject(declaration.sides) || Object.keys(declaration.sides).sort(byCodeUnit).join() !== profiles.join()) {
|
|
171
|
-
bad.push('sides must declare exactly be and fe');
|
|
172
|
-
return bad;
|
|
173
|
-
}
|
|
174
|
-
const names = new Map();
|
|
175
|
-
for (const side of profiles)
|
|
176
|
-
bad.push(...declarationSideProblems(side, declaration.sides[side], names));
|
|
177
|
-
return bad;
|
|
178
|
-
}
|
|
179
|
-
/** Shape problems of a parsed hfs.json, in the words of modules/schemas/hfs-repo.schema.yaml. */
|
|
180
|
-
export function declarationShapeProblems(declaration, profiles) {
|
|
181
|
-
const bad = [];
|
|
182
|
-
if (!isPlainObject(declaration))
|
|
183
|
-
return ['hfs.json is not an object'];
|
|
184
|
-
if (!(Number.isInteger(declaration.hfs) && declaration.hfs >= 1))
|
|
185
|
-
bad.push('hfs must be the pinned manifest major (an integer, 1 or more)');
|
|
186
|
-
if (!NAME.test(String(declaration.project)))
|
|
187
|
-
bad.push('project must be a project name');
|
|
188
|
-
if (declaration.kind === RUNTIME_KIND) {
|
|
189
|
-
for (const key of Object.keys(declaration))
|
|
190
|
-
if (!RUNTIME_DECLARATION_KEYS.has(key))
|
|
191
|
-
bad.push(`unknown key ${key} (a runtime declaration is {hfs, kind, project})`);
|
|
192
|
-
return bad;
|
|
193
|
-
}
|
|
194
|
-
bad.push(...productDeclarationProblems(declaration, profiles));
|
|
195
|
-
return bad;
|
|
196
|
-
}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { judgedInEdition } from './edition-slots.mjs';
|
|
2
|
-
/** The problems of a side's `optionalSlots` and `patterns` against the manifest. */
|
|
3
|
-
export function optionalSlotProblems(manifest, side, s) {
|
|
4
|
-
const bad = [];
|
|
5
|
-
for (const id of s.optionalSlots ?? []) {
|
|
6
|
-
const slot = manifest.slots.find((candidate) => candidate.id === id);
|
|
7
|
-
if (!slot?.profiles.includes(side))
|
|
8
|
-
bad.push(`sides.${side}.optionalSlots names ${id}, which is not a ${side} slot`);
|
|
9
|
-
else if (slot.presence !== 'opt-in')
|
|
10
|
-
bad.push(`sides.${side}.optionalSlots names ${id}, which is ${slot.presence}, not opt-in`);
|
|
11
|
-
else if (slot.appKind !== undefined)
|
|
12
|
-
bad.push(`sides.${side}.optionalSlots names ${id}; an app of kind ${slot.appKind} enables it`);
|
|
13
|
-
}
|
|
14
|
-
for (const name of s.patterns ?? []) {
|
|
15
|
-
const ownsSlot = manifest.slots.some((slot) => slot.profiles.includes(side) && slot.pattern === name);
|
|
16
|
-
const ownsProof = Object.hasOwn(manifest.ruleParams?.[side]?.patternScenarios ?? {}, name);
|
|
17
|
-
if (!ownsSlot && !ownsProof)
|
|
18
|
-
bad.push(`sides.${side}.patterns names ${name}, which neither a ${side} slot nor its proof scenario catalog declares`);
|
|
19
|
-
}
|
|
20
|
-
if (s.kinds !== undefined && side !== 'be')
|
|
21
|
-
bad.push(`sides.${side}.kinds belongs to the be side`);
|
|
22
|
-
for (const kind of s.kinds ?? []) {
|
|
23
|
-
if (!(manifest.triggerKinds ?? []).includes(kind))
|
|
24
|
-
bad.push(`sides.${side}.kinds names ${kind}, which is not one of triggerKinds (${(manifest.triggerKinds ?? []).join(', ')})`);
|
|
25
|
-
}
|
|
26
|
-
return bad;
|
|
27
|
-
}
|
|
28
|
-
/** The problems of a side's `backing` list: every name is admitted by ruleParams.be.backing in this edition. */
|
|
29
|
-
export function backingProblems(manifest, side, s, edition = 'full') {
|
|
30
|
-
const services = Object.entries(manifest.ruleParams?.be?.backing ?? {})
|
|
31
|
-
.filter(([, entry]) => judgedInEdition(entry, edition)).map(([name]) => name);
|
|
32
|
-
return (s.backing ?? []).filter((name) => !services.includes(name))
|
|
33
|
-
.map((name) => `sides.${side}.backing names ${name}, which is not admitted in edition ${edition} by ruleParams.be.backing (${services.join(', ')})`);
|
|
34
|
-
}
|
|
35
|
-
/** The problems of the shape of a side's `patterns` list (a unique list of pattern names). */
|
|
36
|
-
export function patternShapeProblems(s, at, namePattern) {
|
|
37
|
-
const list = s.patterns;
|
|
38
|
-
if (list === undefined)
|
|
39
|
-
return [];
|
|
40
|
-
return Array.isArray(list) && list.every((value) => namePattern.test(String(value))) && new Set(list).size === list.length ? [] : [`${at}.patterns must be a unique list of pattern names`];
|
|
41
|
-
}
|
|
42
|
-
/** The problems of the shape of a side's `kinds` list (a unique list of trigger kind names). */
|
|
43
|
-
export function kindShapeProblems(s, at, namePattern) {
|
|
44
|
-
const list = s.kinds;
|
|
45
|
-
if (list === undefined)
|
|
46
|
-
return [];
|
|
47
|
-
return Array.isArray(list) && list.every((value) => namePattern.test(String(value))) && new Set(list).size === list.length ? [] : [`${at}.kinds must be a unique list of trigger kind names`];
|
|
48
|
-
}
|
|
49
|
-
/** The problems of `ruleParams.be.kindPatterns` (trigger kind -> patterns) and `ruleParams.be.addKinds` (starci app add noun -> {topic, variable, patterns, trigger?, needs?, also?, defaults?, wire?}). */
|
|
50
|
-
export function kindParamProblems(be, triggerKinds) {
|
|
51
|
-
const kebab = /^[a-z][a-z0-9-]*$/;
|
|
52
|
-
const names = (list) => Array.isArray(list) && list.every((value) => kebab.test(String(value))) && new Set(list).size === list.length;
|
|
53
|
-
const bad = [];
|
|
54
|
-
const patterns = be.kindPatterns;
|
|
55
|
-
if (patterns === null || typeof patterns !== 'object' || Array.isArray(patterns) || !Object.entries(patterns).every(([kind, list]) => (triggerKinds ?? []).includes(kind) && names(list)))
|
|
56
|
-
bad.push('ruleParams.be.kindPatterns must map a trigger kind to a unique list of pattern names');
|
|
57
|
-
const nouns = be.addKinds;
|
|
58
|
-
const nounOk = (spec) => spec !== null && typeof spec === 'object' && kebab.test(String(spec.topic)) && kebab.test(String(spec.variable)) && names(spec.patterns) && (spec.trigger === undefined || kebab.test(String(spec.trigger))) && (spec.needs === undefined || names(spec.needs)) && (spec.also === undefined || names(spec.also)) && (spec.defaults === undefined || (typeof spec.defaults === 'object' && !Array.isArray(spec.defaults))) && (spec.wire === undefined || (spec.wire !== null && typeof spec.wire === 'object' && ['file', 'import', 'symbol'].every((key) => typeof spec.wire[key] === 'string' && spec.wire[key] !== '')));
|
|
59
|
-
if (nouns === null || typeof nouns !== 'object' || Array.isArray(nouns) || !Object.entries(nouns).every(([noun, spec]) => kebab.test(noun) && nounOk(spec)))
|
|
60
|
-
bad.push('ruleParams.be.addKinds must map a noun to {topic, variable, patterns, trigger?, needs?, also?, defaults?}');
|
|
61
|
-
return bad;
|
|
62
|
-
}
|
|
63
|
-
/** The problems of `ruleParams.be.patternScenarios`: a pattern name to a non-empty list of unique kebab-case scenario ids. */
|
|
64
|
-
export function scenarioProblem(scenarios) {
|
|
65
|
-
const kebab = /^[a-z][a-z0-9-]*$/;
|
|
66
|
-
const ok = scenarios !== null && typeof scenarios === 'object' && !Array.isArray(scenarios) && Object.entries(scenarios).every(([name, list]) => kebab.test(name) && Array.isArray(list) && list.length > 0 && list.every((id) => kebab.test(String(id))) && new Set(list).size === list.length);
|
|
67
|
-
return ok ? [] : ['ruleParams.be.patternScenarios must map a pattern name to a non-empty list of unique kebab-case scenario ids'];
|
|
68
|
-
}
|
|
69
|
-
/** The problems of the `trigger` of a slot against the manifest's `triggerKinds`: a known kind, on a feature-tier slot only. */
|
|
70
|
-
export function triggerProblems(slot, triggerKinds) {
|
|
71
|
-
if (slot.trigger === undefined)
|
|
72
|
-
return [];
|
|
73
|
-
const bad = [];
|
|
74
|
-
if (!(triggerKinds ?? []).includes(slot.trigger))
|
|
75
|
-
bad.push(`slot ${slot.id}: trigger ${slot.trigger} is not one of triggerKinds`);
|
|
76
|
-
if (slot.tier !== 'feature')
|
|
77
|
-
bad.push(`slot ${slot.id}: a trigger belongs to a feature-tier slot`);
|
|
78
|
-
return bad;
|
|
79
|
-
}
|
|
80
|
-
/** Whether an opt-in slot is enabled for the repository: by its app kind, by a connection's provider, by name in optionalSlots, or by its declared pattern. */
|
|
81
|
-
export function declaredSlotEnabled(slot, repo) {
|
|
82
|
-
if (slot.appKind !== undefined)
|
|
83
|
-
return repo.apps.some((app) => app.kind === slot.appKind);
|
|
84
|
-
// A provider declared on any connection (be owns them all today) enables the provider slots of every profile: repo.providers
|
|
85
|
-
// is the app-wide union the declaration resolver computed; a hand-built repo falls back to its own connections.
|
|
86
|
-
if (slot.provider !== undefined)
|
|
87
|
-
return (repo.providers ?? (repo.connections ?? []).map((connection) => connection.provider)).includes(slot.provider);
|
|
88
|
-
return repo.optionalSlots.includes(slot.id) || (slot.pattern !== undefined && (repo.patterns ?? []).includes(slot.pattern));
|
|
89
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
// edition.mjs - the one edition filter shared by the HFS slot resolver, declaration validation, rule catalog and
|
|
2
|
-
// edition-specific rule parameters. Full is the default; lite changes data views, never the checks that consume them.
|
|
3
|
-
// Lite uses provider adapters and declares Docker Swarm production infrastructure (owner:lite-production-swarm, ruling:R212/case-4).
|
|
4
|
-
// Its overlays exclude the e2e world, and every slot keeps its own `tests`.
|
|
5
|
-
import { isPlainObject } from '../../engine/plain-object.mjs';
|
|
6
|
-
import { EDITIONS } from './manifest-shape.mjs';
|
|
7
|
-
/** The presence of `slot` under edition lite for `profile`: `litePresence`, else the slot's own presence. */
|
|
8
|
-
export function litePresenceOf(slot, profile) {
|
|
9
|
-
const lp = slot.litePresence;
|
|
10
|
-
if (lp === undefined)
|
|
11
|
-
return slot.presence;
|
|
12
|
-
return isPlainObject(lp) ? (lp[profile] ?? slot.presence) : lp;
|
|
13
|
-
}
|
|
14
|
-
/** Whether `slot` exists under `edition` of `manifest` (default: the manifest's own editions). */
|
|
15
|
-
export function slotInEdition(manifest, slot, edition) {
|
|
16
|
-
return (slot.editions ?? manifest.editions ?? EDITIONS).includes(edition);
|
|
17
|
-
}
|
|
18
|
-
/** The slot as `edition` sees it: lite overlays its data, presence and tracking; `tests` stays the slot's own (lite keeps the unit specs). */
|
|
19
|
-
export function effectiveSlot(slot, profile, edition) {
|
|
20
|
-
if (edition !== 'lite')
|
|
21
|
-
return slot;
|
|
22
|
-
const { lite, litePresence, ...base } = slot;
|
|
23
|
-
const presence = litePresenceOf(slot, profile);
|
|
24
|
-
let tracked = slot.tracked;
|
|
25
|
-
if (presence === 'forbidden')
|
|
26
|
-
tracked = 'external';
|
|
27
|
-
else if (tracked === 'external')
|
|
28
|
-
tracked = 'tracked';
|
|
29
|
-
return { ...base, ...lite, presence, tracked };
|
|
30
|
-
}
|
|
31
|
-
/** The template group starci app sync renders `slot` from under `edition`: `liteManagedBy` (else `managedBy`) in lite, `managedBy` otherwise; undefined when unmanaged. */
|
|
32
|
-
export function managedGroupOf(slot, edition) {
|
|
33
|
-
return edition === 'lite' ? (slot.liteManagedBy ?? slot.managedBy) : slot.managedBy;
|
|
34
|
-
}
|
|
35
|
-
/** The declared edition and the vocabulary against which it is validated. */
|
|
36
|
-
export function declarationEdition(manifest, declaration) {
|
|
37
|
-
const edition = declaration.edition === undefined ? 'full' : declaration.edition;
|
|
38
|
-
const known = manifest.editions ?? EDITIONS;
|
|
39
|
-
return { edition, known, valid: known.includes(edition) };
|
|
40
|
-
}
|
|
41
|
-
/** Problems of an optional rule-catalog `editions` list, in the catalog schema's words. */
|
|
42
|
-
export function ruleEditionProblems(rule, label) {
|
|
43
|
-
if (rule.editions === undefined)
|
|
44
|
-
return [];
|
|
45
|
-
const bad = [];
|
|
46
|
-
if (!Array.isArray(rule.editions) || !rule.editions.length)
|
|
47
|
-
return [`${label}.editions must be a non-empty list`];
|
|
48
|
-
for (const value of rule.editions)
|
|
49
|
-
if (!EDITIONS.includes(value))
|
|
50
|
-
bad.push(`${label}.editions has ${JSON.stringify(value)}, not one of ${EDITIONS.join(', ')}`);
|
|
51
|
-
if (new Set(rule.editions).size !== rule.editions.length)
|
|
52
|
-
bad.push(`${label}.editions repeats a value`);
|
|
53
|
-
return bad;
|
|
54
|
-
}
|
|
55
|
-
/** Whether a catalogued rule owner judges its finding under `edition`; uncatalogued codes always remain judged. */
|
|
56
|
-
export function judgedInEdition(owner, edition = 'full') {
|
|
57
|
-
return !owner?.editions || owner.editions.includes(edition);
|
|
58
|
-
}
|
|
59
|
-
/** Whether the enforcer `kind:id` of the catalog `rules` runs under `edition`: every rule listing it is judged there, and the enforcer row's own `editions` (a rule with several enforcers where only one is full-only) agrees. A lint rule no rule lists runs everywhere. */
|
|
60
|
-
export function enforcerJudgedInEdition(rules, kind, id, edition = 'full') {
|
|
61
|
-
const owners = rules.filter((rule) => rule.enforcers.some((enforcer) => enforcer.kind === kind && enforcer.id === id));
|
|
62
|
-
return owners.every((rule) => judgedInEdition(rule, edition) && rule.enforcers.filter((enforcer) => enforcer.kind === kind && enforcer.id === id).every((enforcer) => judgedInEdition(enforcer, edition)));
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* A frozen copy of one profile's parameters, with its lite overrides applied only in the lite edition. A lite key whose base
|
|
66
|
-
* value and override are both maps merges one level deep (lite.infraOwners restates only the specifiers whose owner changes);
|
|
67
|
-
* any other value replaces the base.
|
|
68
|
-
*/
|
|
69
|
-
export function editionRuleParams(params, edition) {
|
|
70
|
-
const { lite, ...base } = params;
|
|
71
|
-
const merged = edition === 'lite' && lite ? { ...base } : base;
|
|
72
|
-
if (edition === 'lite' && lite) {
|
|
73
|
-
for (const [key, value] of Object.entries(lite))
|
|
74
|
-
merged[key] = isPlainObject(value) && isPlainObject(base[key]) ? { ...base[key], ...value } : value;
|
|
75
|
-
}
|
|
76
|
-
const deepFreeze = (value) => { if (value && typeof value === 'object') {
|
|
77
|
-
Object.values(value).forEach(deepFreeze);
|
|
78
|
-
} return Object.freeze(value); };
|
|
79
|
-
return deepFreeze(structuredClone(merged));
|
|
80
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { declarationSurface, isEmittableSource } from '../lib/declaration-surface.mjs';
|
|
2
|
-
/** What to write, by what the classifier says to annotate. */
|
|
3
|
-
const HINTS = {
|
|
4
|
-
'return type': 'Write the return type after the parameter list: `(): Result =>` or `function name(): Result`.',
|
|
5
|
-
'variable type': 'Give the variable a type: `export const name: Result = ...`.',
|
|
6
|
-
'parameter type': 'Give the parameter a type: `(value: Input)`.',
|
|
7
|
-
'property type': 'Give the property a type: `name: Result = ...`.',
|
|
8
|
-
'accessor type': 'Give the accessor a type: `get name(): Result` (a setter takes it from its parameter).',
|
|
9
|
-
'destructured export': 'A destructuring pattern cannot carry a type per name: export each name as its own variable with a type, `export const name: Type = source.name`; a module definition is `export const { ConfigurableModuleClass, OPTIONS_TYPE } = defineCapabilityModule<XOptions>()` (or `defineConfigurableModule`) of @starci/nest-kit, which states the types (`starci app codemod module-definition` writes it).',
|
|
10
|
-
'exported value': 'Declare the type (an interface or a type alias) and annotate the export with it: `export const name: Shape = ...`.',
|
|
11
|
-
};
|
|
12
|
-
/** The `--isolatedDeclarations` flag name TypeScript ends its reasons with says nothing to the reader. */
|
|
13
|
-
const plain = (reason) => reason.replace(/ with --isolatedDeclarations\.?/, '').replace(/\.$/, '');
|
|
14
|
-
/**
|
|
15
|
-
* The rule. `ts` is the canon's own TypeScript (its peer dependency); the side's `module` option comes from the typed program when the file is linted with one.
|
|
16
|
-
*
|
|
17
|
-
* @param input - `ts` is the compiler.
|
|
18
|
-
* @returns An ESLint rule reporting each export of a TypeScript source whose type is inferred.
|
|
19
|
-
*/
|
|
20
|
-
export const explicitSurfaceRule = ({ ts }) => ({
|
|
21
|
-
meta: {
|
|
22
|
-
type: 'problem',
|
|
23
|
-
docs: { description: 'An exported declaration states its type: the return type, variable type or parameter type is written, not inferred from a body or from other files.' },
|
|
24
|
-
schema: [],
|
|
25
|
-
messages: {
|
|
26
|
-
inferred: 'HFS_EXPLICIT_EXPORT_SURFACE: `{{name}}` is exported with an inferred type ({{reason}}), so importers cannot read it from this file and every one of them is linted again whenever the file changes. Annotate the {{annotate}}. {{hint}}',
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
create(context) {
|
|
30
|
-
return {
|
|
31
|
-
Program() {
|
|
32
|
-
const file = context.filename;
|
|
33
|
-
if (!isEmittableSource(file))
|
|
34
|
-
return;
|
|
35
|
-
const { sourceCode } = context;
|
|
36
|
-
const module = sourceCode.parserServices?.program?.getCompilerOptions().module;
|
|
37
|
-
const whole = { start: { line: 1, column: 0 }, end: { line: 1, column: 0 } };
|
|
38
|
-
let surface;
|
|
39
|
-
try {
|
|
40
|
-
surface = declarationSurface(ts, file, sourceCode.text, module);
|
|
41
|
-
}
|
|
42
|
-
catch {
|
|
43
|
-
surface = null;
|
|
44
|
-
}
|
|
45
|
-
if (surface === null) {
|
|
46
|
-
context.report({ loc: whole, messageId: 'inferred', data: { name: 'this file', reason: 'the declaration emit could not read it', annotate: 'exported value', hint: HINTS['exported value'] } });
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
for (const problem of surface.problems) {
|
|
50
|
-
context.report({
|
|
51
|
-
loc: { start: sourceCode.getLocFromIndex(problem.start), end: sourceCode.getLocFromIndex(problem.start + problem.length) },
|
|
52
|
-
messageId: 'inferred',
|
|
53
|
-
data: { name: problem.name, reason: plain(problem.reason), annotate: problem.annotate, hint: HINTS[problem.annotate] },
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
|
-
};
|
|
58
|
-
},
|
|
59
|
-
});
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
// Linear-time text trimming and `<placeholder>` replacement for the HFS path and prose checks.
|
|
2
|
-
/** `text` without its trailing characters that are in `chars`. */
|
|
3
|
-
export function trimTrailingChars(text, chars) {
|
|
4
|
-
let last = text.length - 1;
|
|
5
|
-
while (last >= 0 && chars.includes(text[last]))
|
|
6
|
-
last -= 1;
|
|
7
|
-
return text.slice(0, last + 1);
|
|
8
|
-
}
|
|
9
|
-
/** `text` with every `<name>` placeholder (a `<`, one or more characters other than `>`, a `>`) replaced by `replacement`. */
|
|
10
|
-
export function replacePlaceholders(text, replacement) {
|
|
11
|
-
let out = '';
|
|
12
|
-
let from = 0;
|
|
13
|
-
let open = text.indexOf('<');
|
|
14
|
-
while (open >= 0) {
|
|
15
|
-
const close = text.indexOf('>', open + 1);
|
|
16
|
-
if (close < 0)
|
|
17
|
-
break;
|
|
18
|
-
if (close === open + 1) {
|
|
19
|
-
open = text.indexOf('<', close);
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
out += text.slice(from, open) + replacement;
|
|
23
|
-
from = close + 1;
|
|
24
|
-
open = text.indexOf('<', from);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return out + text.slice(from);
|
|
28
|
-
}
|
|
29
|
-
/** Whether `text` holds a `<name>` placeholder. */
|
|
30
|
-
export const hasPlaceholder = (text) => replacePlaceholders(text, '') !== text;
|