Files
agentic-dev/packages/core-eslint/rules/no-undeclared-consent-check.js
Danijel Martinek 1cab88916a 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>
2026-05-19 11:51:30 +00:00

69 lines
2.3 KiB
JavaScript

import { parseManifestFully } from "./_manifest-ast.js";
import { manifestPathForFeature } from "./_manifest-source.js";
import { repoRootSchema } from "./_rule-schema.js";
import { resolveRuleContext } from "./_rule-context.js";
/** @type {import("eslint").Rule.RuleModule} */
export default {
meta: {
type: "suggestion",
docs: {
description:
'consent.isGranted("X") inside a use-case file must match a category declared in manifest.requiresConsent.',
},
schema: repoRootSchema,
messages: {
undeclared:
'{{useCase}} calls consent.isGranted("{{category}}") but "{{category}}" is not declared in manifest.requiresConsent. Add it to the manifest or remove the call.',
unusedDeclaration:
"{{useCase}} manifest declares requiresConsent but no consent.isGranted() call found in this file. Add consent checks or clear the manifest declaration.",
},
},
create(context) {
const rc = resolveRuleContext(context);
if (!rc) return {};
const { useCaseName, featureRoot } = rc;
const manifest = parseManifestFully(manifestPathForFeature(featureRoot));
if (!manifest) return {};
const requiresConsent = manifest.requiresConsent ?? [];
if (requiresConsent.length === 0) return {};
const declared = new Set(requiresConsent);
let hasConsentCall = false;
return {
CallExpression(node) {
if (
node.callee.type === "MemberExpression" &&
node.callee.object.type === "Identifier" &&
node.callee.object.name === "consent" &&
node.callee.property.type === "Identifier" &&
node.callee.property.name === "isGranted" &&
node.arguments.length > 0 &&
node.arguments[0].type === "Literal" &&
typeof node.arguments[0].value === "string"
) {
hasConsentCall = true;
const category = node.arguments[0].value;
if (!declared.has(category)) {
context.report({
node,
messageId: "undeclared",
data: { category, useCase: useCaseName },
});
}
}
},
"Program:exit"(node) {
if (!hasConsentCall) {
context.report({
node,
messageId: "unusedDeclaration",
data: { useCase: useCaseName },
});
}
},
};
},
};