feat(core-eslint): add no-undeclared-consent-check rule (conformance gate 12)
Extends the conformance ESLint layer with the consent-check rule:
- `no-undeclared-consent-check` (warn): `consent.isGranted("X")` in a
use-case file must match a category declared in `manifest.requiresConsent`;
also warns when requiresConsent is declared but no isGranted call is found.
- `_manifest-ast.js`: adds `parseManifestFully` which extracts top-level
`name`, `requiredCores`, `requiresConsent`, and per-use-case maps from the
manifest AST; `requiresConsent` extraction tested in `_manifest-ast.test.js`.
- `_rule-context.js` / `_rule-schema.js`: shared helpers extracted from the
existing per-rule files so the new rule can resolve use-case name + feature
root without duplication.
- Existing rules (`no-undeclared-audit`, `no-undeclared-event-publish`,
`no-undeclared-analytics-event`) updated to use the shared helpers.
- `plugin.js` + `base.js` register the rule at warn severity.
- CLAUDE.md + conformance-quickref.md: rule count advanced from 11 → 12.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
import fs from "node:fs";
|
||||
import { parse } from "@typescript-eslint/parser";
|
||||
|
||||
function extractStringLiterals(arrayExpr) {
|
||||
return arrayExpr.elements
|
||||
.filter((el) => el && el.type === "Literal" && typeof el.value === "string")
|
||||
.map((el) => el.value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a feature.manifest.ts file and extract per-use-case attributes.
|
||||
* Walks the AST to find the `defineFeature({...} as const)` call expression
|
||||
@@ -94,11 +100,7 @@ function extractUseCaseEntry(objExpr) {
|
||||
key === "analyticsEvents") &&
|
||||
prop.value.type === "ArrayExpression"
|
||||
) {
|
||||
entry[key] = prop.value.elements
|
||||
.filter(
|
||||
(el) => el && el.type === "Literal" && typeof el.value === "string",
|
||||
)
|
||||
.map((el) => el.value);
|
||||
entry[key] = extractStringLiterals(prop.value);
|
||||
}
|
||||
}
|
||||
return entry;
|
||||
@@ -139,6 +141,7 @@ export function parseManifestFully(manifestPath) {
|
||||
|
||||
let name = null;
|
||||
let requiredCores = [];
|
||||
let requiresConsent = [];
|
||||
let useCases = {};
|
||||
|
||||
for (const prop of arg.properties) {
|
||||
@@ -153,30 +156,34 @@ export function parseManifestFully(manifestPath) {
|
||||
prop.key.name === "requiredCores" &&
|
||||
prop.value.type === "ArrayExpression"
|
||||
) {
|
||||
requiredCores = prop.value.elements
|
||||
.filter(
|
||||
(el) => el && el.type === "Literal" && typeof el.value === "string",
|
||||
)
|
||||
.map((el) => el.value);
|
||||
requiredCores = extractStringLiterals(prop.value);
|
||||
} else if (
|
||||
prop.key.name === "requiresConsent" &&
|
||||
prop.value.type === "ArrayExpression"
|
||||
) {
|
||||
requiresConsent = extractStringLiterals(prop.value);
|
||||
} 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;
|
||||
useCases[ucName] = extractUseCaseEntryFromObj(entry.value);
|
||||
}
|
||||
useCases = extractUseCasesMap(prop.value);
|
||||
}
|
||||
}
|
||||
|
||||
if (name === null) return null;
|
||||
return { name, requiredCores, useCases };
|
||||
return { name, requiredCores, requiresConsent, useCases };
|
||||
}
|
||||
|
||||
function extractUseCasesMap(useCasesObjExpr) {
|
||||
const result = {};
|
||||
for (const entry of useCasesObjExpr.properties) {
|
||||
if (entry.type !== "Property" || entry.value.type !== "ObjectExpression")
|
||||
continue;
|
||||
const ucName =
|
||||
entry.key.type === "Identifier" ? entry.key.name : entry.key.value;
|
||||
result[ucName] = extractUseCaseEntryFromObj(entry.value);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Helper aliases for the existing private functions — exposed under
|
||||
@@ -225,11 +232,7 @@ function extractUseCaseEntryFromObj(objExpr) {
|
||||
key === "analyticsEvents") &&
|
||||
prop.value.type === "ArrayExpression"
|
||||
) {
|
||||
entry[key] = prop.value.elements
|
||||
.filter(
|
||||
(el) => el && el.type === "Literal" && typeof el.value === "string",
|
||||
)
|
||||
.map((el) => el.value);
|
||||
entry[key] = extractStringLiterals(prop.value);
|
||||
}
|
||||
}
|
||||
return entry;
|
||||
|
||||
Reference in New Issue
Block a user