Files
callstack__agent-device/scripts/layering/source-execution-policy.ts
Michał Pierzchała 4454aef139 refactor(layering): remove retired migration scaffolding (#2092)
* refactor(layering): remove retired migration scaffolding

* test: remove retired focus test wording
2026-08-27 19:24:46 +02:00

32 lines
1.2 KiB
TypeScript

import { parseSync } from 'oxc-parser';
import { visitAst } from './layering-ast.ts';
import type { LayeringViolation } from './model.ts';
export const SOURCE_EXECUTION_COMPATIBILITY_RULE = 'R67 source-execution-compatibility';
/** Source-checkout TypeScript must remain executable by the repository's Node type stripper. */
export function sourceExecutionCompatibilityViolations(
sources: ReadonlyMap<string, string>,
): LayeringViolation[] {
const violations: LayeringViolation[] = [];
for (const [file, source] of sources) {
const program = parseSync(file, source).program as Record<string, unknown>;
visitAst(program, (node) => {
if (
node['type'] !== 'VariableDeclaration' ||
(node['kind'] !== 'using' && node['kind'] !== 'await using')
) {
return;
}
const offset = typeof node['start'] === 'number' ? node['start'] : 0;
violations.push({
rule: SOURCE_EXECUTION_COMPATIBILITY_RULE,
file,
line: source.slice(0, offset).split('\n').length,
message: `source-executed TypeScript uses unsupported ${String(node['kind'])} declaration`,
});
});
}
return violations;
}