feat(core-eslint): add no-undeclared-analytics-event ESLint rule
Adds the conformance/no-undeclared-analytics-event rule at warn severity,
mirroring no-undeclared-audit and no-undeclared-event-publish. The rule
cross-checks analytics.track("X", ...) literal slugs in *.use-case.ts
files against manifest.useCases[name].analyticsEvents, providing
sub-second editor feedback before boot-time conformance fires.
- Extends _manifest-ast.js to parse analyticsEvents arrays in both
extractUseCaseEntry helpers
- Registers rule in plugin.js and base.js at ["warn", { repoRoot }]
- RuleTester fixtures: declared pass, undeclared warn, non-literal no-op,
non-use-case file no-op, missing manifest entry no-op
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -18,7 +18,12 @@ export function parseManifestUseCases(manifestPath) {
|
||||
}
|
||||
let ast;
|
||||
try {
|
||||
ast = parse(src, { sourceType: "module", ecmaVersion: "latest", loc: false, range: false });
|
||||
ast = parse(src, {
|
||||
sourceType: "module",
|
||||
ecmaVersion: "latest",
|
||||
loc: false,
|
||||
range: false,
|
||||
});
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
@@ -27,13 +32,19 @@ export function parseManifestUseCases(manifestPath) {
|
||||
const arg = unwrapAsConst(defineCall.arguments[0]);
|
||||
if (!arg || arg.type !== "ObjectExpression") return null;
|
||||
const useCasesProp = arg.properties.find(
|
||||
(p) => p.type === "Property" && p.key.type === "Identifier" && p.key.name === "useCases",
|
||||
(p) =>
|
||||
p.type === "Property" &&
|
||||
p.key.type === "Identifier" &&
|
||||
p.key.name === "useCases",
|
||||
);
|
||||
if (!useCasesProp || useCasesProp.value.type !== "ObjectExpression") return {};
|
||||
if (!useCasesProp || useCasesProp.value.type !== "ObjectExpression")
|
||||
return {};
|
||||
const result = {};
|
||||
for (const entry of useCasesProp.value.properties) {
|
||||
if (entry.type !== "Property" || entry.value.type !== "ObjectExpression") continue;
|
||||
const name = entry.key.type === "Identifier" ? entry.key.name : entry.key.value;
|
||||
if (entry.type !== "Property" || entry.value.type !== "ObjectExpression")
|
||||
continue;
|
||||
const name =
|
||||
entry.key.type === "Identifier" ? entry.key.name : entry.key.value;
|
||||
result[name] = extractUseCaseEntry(entry.value);
|
||||
}
|
||||
return result;
|
||||
@@ -46,7 +57,11 @@ function findDefineFeatureCall(ast) {
|
||||
for (const decl of node.declaration.declarations) {
|
||||
const init = decl.init;
|
||||
if (!init) continue;
|
||||
if (init.type === "CallExpression" && init.callee.type === "Identifier" && init.callee.name === "defineFeature") {
|
||||
if (
|
||||
init.type === "CallExpression" &&
|
||||
init.callee.type === "Identifier" &&
|
||||
init.callee.name === "defineFeature"
|
||||
) {
|
||||
return init;
|
||||
}
|
||||
}
|
||||
@@ -60,15 +75,29 @@ function unwrapAsConst(node) {
|
||||
}
|
||||
|
||||
function extractUseCaseEntry(objExpr) {
|
||||
const entry = { mutates: false, audits: [], publishes: [], consumes: [] };
|
||||
const entry = {
|
||||
mutates: false,
|
||||
audits: [],
|
||||
publishes: [],
|
||||
consumes: [],
|
||||
analyticsEvents: [],
|
||||
};
|
||||
for (const prop of objExpr.properties) {
|
||||
if (prop.type !== "Property" || prop.key.type !== "Identifier") continue;
|
||||
const key = prop.key.name;
|
||||
if (key === "mutates" && prop.value.type === "Literal") {
|
||||
entry.mutates = prop.value.value === true;
|
||||
} else if ((key === "audits" || key === "publishes" || key === "consumes") && prop.value.type === "ArrayExpression") {
|
||||
} else if (
|
||||
(key === "audits" ||
|
||||
key === "publishes" ||
|
||||
key === "consumes" ||
|
||||
key === "analyticsEvents") &&
|
||||
prop.value.type === "ArrayExpression"
|
||||
) {
|
||||
entry[key] = prop.value.elements
|
||||
.filter((el) => el && el.type === "Literal" && typeof el.value === "string")
|
||||
.filter(
|
||||
(el) => el && el.type === "Literal" && typeof el.value === "string",
|
||||
)
|
||||
.map((el) => el.value);
|
||||
}
|
||||
}
|
||||
@@ -94,7 +123,12 @@ export function parseManifestFully(manifestPath) {
|
||||
}
|
||||
let ast;
|
||||
try {
|
||||
ast = parse(src, { sourceType: "module", ecmaVersion: "latest", loc: false, range: false });
|
||||
ast = parse(src, {
|
||||
sourceType: "module",
|
||||
ecmaVersion: "latest",
|
||||
loc: false,
|
||||
range: false,
|
||||
});
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
@@ -109,16 +143,33 @@ export function parseManifestFully(manifestPath) {
|
||||
|
||||
for (const prop of arg.properties) {
|
||||
if (prop.type !== "Property" || prop.key.type !== "Identifier") continue;
|
||||
if (prop.key.name === "name" && prop.value.type === "Literal" && typeof prop.value.value === "string") {
|
||||
if (
|
||||
prop.key.name === "name" &&
|
||||
prop.value.type === "Literal" &&
|
||||
typeof prop.value.value === "string"
|
||||
) {
|
||||
name = prop.value.value;
|
||||
} else if (prop.key.name === "requiredCores" && prop.value.type === "ArrayExpression") {
|
||||
} else if (
|
||||
prop.key.name === "requiredCores" &&
|
||||
prop.value.type === "ArrayExpression"
|
||||
) {
|
||||
requiredCores = prop.value.elements
|
||||
.filter((el) => el && el.type === "Literal" && typeof el.value === "string")
|
||||
.filter(
|
||||
(el) => el && el.type === "Literal" && typeof el.value === "string",
|
||||
)
|
||||
.map((el) => el.value);
|
||||
} else if (prop.key.name === "useCases" && prop.value.type === "ObjectExpression") {
|
||||
} else if (
|
||||
prop.key.name === "useCases" &&
|
||||
prop.value.type === "ObjectExpression"
|
||||
) {
|
||||
for (const entry of prop.value.properties) {
|
||||
if (entry.type !== "Property" || entry.value.type !== "ObjectExpression") continue;
|
||||
const ucName = entry.key.type === "Identifier" ? entry.key.name : entry.key.value;
|
||||
if (
|
||||
entry.type !== "Property" ||
|
||||
entry.value.type !== "ObjectExpression"
|
||||
)
|
||||
continue;
|
||||
const ucName =
|
||||
entry.key.type === "Identifier" ? entry.key.name : entry.key.value;
|
||||
useCases[ucName] = extractUseCaseEntryFromObj(entry.value);
|
||||
}
|
||||
}
|
||||
@@ -137,7 +188,11 @@ function findDefineFeatureCallFromBody(ast) {
|
||||
for (const decl of node.declaration.declarations) {
|
||||
const init = decl.init;
|
||||
if (!init) continue;
|
||||
if (init.type === "CallExpression" && init.callee.type === "Identifier" && init.callee.name === "defineFeature") {
|
||||
if (
|
||||
init.type === "CallExpression" &&
|
||||
init.callee.type === "Identifier" &&
|
||||
init.callee.name === "defineFeature"
|
||||
) {
|
||||
return init;
|
||||
}
|
||||
}
|
||||
@@ -151,15 +206,29 @@ function unwrapAsConstNode(node) {
|
||||
}
|
||||
|
||||
function extractUseCaseEntryFromObj(objExpr) {
|
||||
const entry = { mutates: false, audits: [], publishes: [], consumes: [] };
|
||||
const entry = {
|
||||
mutates: false,
|
||||
audits: [],
|
||||
publishes: [],
|
||||
consumes: [],
|
||||
analyticsEvents: [],
|
||||
};
|
||||
for (const prop of objExpr.properties) {
|
||||
if (prop.type !== "Property" || prop.key.type !== "Identifier") continue;
|
||||
const key = prop.key.name;
|
||||
if (key === "mutates" && prop.value.type === "Literal") {
|
||||
entry.mutates = prop.value.value === true;
|
||||
} else if ((key === "audits" || key === "publishes" || key === "consumes") && prop.value.type === "ArrayExpression") {
|
||||
} else if (
|
||||
(key === "audits" ||
|
||||
key === "publishes" ||
|
||||
key === "consumes" ||
|
||||
key === "analyticsEvents") &&
|
||||
prop.value.type === "ArrayExpression"
|
||||
) {
|
||||
entry[key] = prop.value.elements
|
||||
.filter((el) => el && el.type === "Literal" && typeof el.value === "string")
|
||||
.filter(
|
||||
(el) => el && el.type === "Literal" && typeof el.value === "string",
|
||||
)
|
||||
.map((el) => el.value);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user