@aspruyt/xfg 8.5.6 → 9.0.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.
Files changed (58) hide show
  1. package/dist/cli/settings-factories.d.ts +2 -1
  2. package/dist/cli/settings-factories.js +6 -1
  3. package/dist/cli/settings-report-builder.d.ts +6 -1
  4. package/dist/cli/settings-report-builder.js +12 -0
  5. package/dist/cli/settings-runner.js +7 -0
  6. package/dist/cli/types.d.ts +4 -9
  7. package/dist/config/array-directive.d.ts +21 -0
  8. package/dist/config/array-directive.js +88 -0
  9. package/dist/config/drop-repeated-items.d.ts +2 -0
  10. package/dist/config/drop-repeated-items.js +19 -0
  11. package/dist/config/index.d.ts +2 -2
  12. package/dist/config/index.js +1 -3
  13. package/dist/config/merge.d.ts +6 -1
  14. package/dist/config/merge.js +13 -29
  15. package/dist/config/normalizer.d.ts +0 -8
  16. package/dist/config/normalizer.js +195 -238
  17. package/dist/config/types.d.ts +68 -37
  18. package/dist/config/types.js +6 -0
  19. package/dist/config/validator.d.ts +3 -9
  20. package/dist/config/validator.js +41 -45
  21. package/dist/config/validators/actions-validator.d.ts +7 -0
  22. package/dist/config/validators/actions-validator.js +139 -0
  23. package/dist/config/validators/ai-validator.d.ts +7 -1
  24. package/dist/config/validators/ai-validator.js +41 -14
  25. package/dist/config/validators/file-validator.js +2 -6
  26. package/dist/config/validators/group-validator.js +3 -10
  27. package/dist/config/validators/inherit-flag.d.ts +3 -0
  28. package/dist/config/validators/inherit-flag.js +14 -0
  29. package/dist/config/validators/pr-options-validator.d.ts +3 -0
  30. package/dist/config/validators/pr-options-validator.js +32 -0
  31. package/dist/config/validators/repo-entry-validator.js +2 -9
  32. package/dist/config/validators/ruleset-validator.d.ts +0 -3
  33. package/dist/config/validators/ruleset-validator.js +39 -58
  34. package/dist/config/validators/shared.d.ts +9 -0
  35. package/dist/config/validators/shared.js +98 -28
  36. package/dist/settings/actions/diff.d.ts +11 -0
  37. package/dist/settings/actions/diff.js +32 -0
  38. package/dist/settings/actions/endpoints.d.ts +21 -0
  39. package/dist/settings/actions/endpoints.js +89 -0
  40. package/dist/settings/actions/formatter.d.ts +10 -0
  41. package/dist/settings/actions/formatter.js +11 -0
  42. package/dist/settings/actions/github-actions-strategy.d.ts +16 -0
  43. package/dist/settings/actions/github-actions-strategy.js +23 -0
  44. package/dist/settings/actions/index.d.ts +3 -0
  45. package/dist/settings/actions/index.js +2 -0
  46. package/dist/settings/actions/processor.d.ts +19 -0
  47. package/dist/settings/actions/processor.js +88 -0
  48. package/dist/settings/actions/resolve.d.ts +15 -0
  49. package/dist/settings/actions/resolve.js +42 -0
  50. package/dist/settings/actions/types.d.ts +9 -0
  51. package/dist/settings/actions/types.js +1 -0
  52. package/dist/settings/environments/processor.js +1 -1
  53. package/dist/settings/index.d.ts +1 -0
  54. package/dist/settings/index.js +1 -0
  55. package/dist/settings/labels/diff.js +1 -2
  56. package/dist/shared/credential-env.d.ts +4 -3
  57. package/dist/shared/credential-env.js +12 -7
  58. package/package.json +4 -2
@@ -1,6 +1,7 @@
1
1
  import { isPlainObject } from "../../shared/type-guards.js";
2
2
  import { ValidationError } from "../../shared/errors.js";
3
- import { assertAiBaseUrlEnvAllowed, assertAiHeadersEnvAllowed, assertAiKeyEnvAllowed, } from "../../shared/credential-env.js";
3
+ import { assertAiBaseUrlEnvAllowed, assertAiBaseUrlEnvName, assertAiHeadersEnvAllowed, assertAiKeyEnvAllowed, } from "../../shared/credential-env.js";
4
+ import { assertNoRootInherit } from "./inherit-flag.js";
4
5
  const VALID_PROVIDERS = ["anthropic", "openai"];
5
6
  const STRING_FIELDS = ["model", "baseUrl", "apiKeyEnv", "prompt"];
6
7
  const PROVIDER_KEYS = [
@@ -10,23 +11,43 @@ const PROVIDER_KEYS = [
10
11
  "baseUrlEnv",
11
12
  ...STRING_FIELDS,
12
13
  ];
13
- const PRIMARY_KEYS = new Set([...PROVIDER_KEYS, "fallback"]);
14
+ const PRIMARY_KEYS = new Set([...PROVIDER_KEYS, "fallback", "inherit"]);
14
15
  const FALLBACK_KEYS = new Set(PROVIDER_KEYS);
15
- export function validateAiOption(ai) {
16
+ /**
17
+ * Checks one layer's field shapes; rules that relate fields wait for `validateMergedAi`.
18
+ * `context` names the layer, empty for the root; `inherit` is only valid in a layer.
19
+ */
20
+ export function validateAiLayer(ai, context = "") {
16
21
  if (ai === undefined || typeof ai === "boolean")
17
22
  return;
23
+ const path = context ? `${context}: prOptions.ai` : "prOptions.ai";
18
24
  if (!isPlainObject(ai)) {
19
- throw new ValidationError("prOptions.ai must be a boolean or an object");
25
+ throw new ValidationError(`${path} must be a boolean or an object`);
20
26
  }
21
- validateProvider(ai, "prOptions.ai", PRIMARY_KEYS);
27
+ if (!context)
28
+ assertNoRootInherit(ai, "prOptions.ai");
29
+ if (ai.inherit !== undefined && typeof ai.inherit !== "boolean") {
30
+ throw new ValidationError(`${path}.inherit must be a boolean`);
31
+ }
32
+ validateProviderShape(ai, path, PRIMARY_KEYS);
22
33
  if (ai.fallback !== undefined) {
23
34
  if (!isPlainObject(ai.fallback)) {
24
- throw new ValidationError("prOptions.ai.fallback must be an object");
35
+ throw new ValidationError(`${path}.fallback must be an object`);
25
36
  }
26
- validateProvider(ai.fallback, "prOptions.ai.fallback", FALLBACK_KEYS);
37
+ validateProviderShape(ai.fallback, `${path}.fallback`, FALLBACK_KEYS);
38
+ }
39
+ }
40
+ /** Checks the `ai` of one repo after every layer merged; `context` names the repo. */
41
+ export function validateMergedAi(ai, context) {
42
+ if (!isPlainObject(ai))
43
+ return;
44
+ const path = `${context}: prOptions.ai`;
45
+ validateMergedProvider(ai, path);
46
+ if (isPlainObject(ai.fallback)) {
47
+ validateMergedProvider(ai.fallback, `${path}.fallback`);
27
48
  }
28
49
  }
29
- function validateProvider(ai, path, knownKeys) {
50
+ function validateProviderShape(ai, path, knownKeys) {
30
51
  const unknown = Object.keys(ai).find((key) => !knownKeys.has(key));
31
52
  if (unknown !== undefined) {
32
53
  throw new ValidationError(`${path} has unknown key '${unknown}'`);
@@ -42,17 +63,23 @@ function validateProvider(ai, path, knownKeys) {
42
63
  throw new ValidationError(`${path}.${field} must be a non-empty string`);
43
64
  }
44
65
  }
66
+ assertAiBaseUrlEnvName(ai.baseUrlEnv, path);
67
+ assertAiHeadersEnvAllowed(ai.headersEnv, path);
68
+ const max = ai.maxDiffChars;
69
+ if (max !== undefined &&
70
+ (typeof max !== "number" || !Number.isInteger(max) || max <= 0)) {
71
+ throw new ValidationError(`${path}.maxDiffChars must be a positive integer`);
72
+ }
73
+ }
74
+ function validateMergedProvider(ai, path) {
75
+ const provider = ai.provider ?? "anthropic";
45
76
  assertAiBaseUrlEnvAllowed(ai.baseUrlEnv, ai.baseUrl, path);
46
- assertAiKeyEnvAllowed(provider ?? "anthropic", ai.apiKeyEnv, ai.baseUrl, path,
77
+ assertAiKeyEnvAllowed(provider, ai.apiKeyEnv, ai.baseUrl, path,
47
78
  // A URL read from the env is unknown here, so it never counts as the provider's own API.
48
79
  ai.baseUrlEnv !== undefined);
80
+ // Layers can each be valid and still name one header twice in different case.
49
81
  assertAiHeadersEnvAllowed(ai.headersEnv, path);
50
82
  if (provider === "openai" && ai.model === undefined) {
51
83
  throw new ValidationError(`${path}.model is required when provider is 'openai'`);
52
84
  }
53
- const max = ai.maxDiffChars;
54
- if (max !== undefined &&
55
- (typeof max !== "number" || !Number.isInteger(max) || max <= 0)) {
56
- throw new ValidationError(`${path}.maxDiffChars must be a positive integer`);
57
- }
58
85
  }
@@ -1,5 +1,6 @@
1
1
  import { extname, isAbsolute } from "node:path";
2
2
  import { isTextContent } from "../merge.js";
3
+ import { ARRAY_MERGE_STRATEGIES } from "../array-directive.js";
3
4
  import { ValidationError } from "../../shared/errors.js";
4
5
  import { isPlainObject } from "../../shared/type-guards.js";
5
6
  import { hasGitDirSegment } from "../../shared/path-safety.js";
@@ -8,12 +9,7 @@ export { isPlainObject as isObjectContent };
8
9
  export function validValues(values) {
9
10
  return values;
10
11
  }
11
- const VALID_STRATEGIES = validValues([
12
- "replace",
13
- "append",
14
- "prepend",
15
- "merge",
16
- ]);
12
+ const VALID_STRATEGIES = ARRAY_MERGE_STRATEGIES;
17
13
  /**
18
14
  * Check if file extension is for structured output (JSON/YAML).
19
15
  */
@@ -1,8 +1,7 @@
1
1
  import { resolveExtendsChain } from "../extends-resolver.js";
2
2
  import { isPlainObject } from "../../shared/type-guards.js";
3
3
  import { ValidationError } from "../../shared/errors.js";
4
- import { validateBranchName } from "../../shared/branch-validation.js";
5
- import { validateAiOption } from "./ai-validator.js";
4
+ import { validatePrOptions } from "./pr-options-validator.js";
6
5
  import { validateFileName } from "./file-validator.js";
7
6
  import { validateFileConfigFields, validateSettings, buildRootSettingsContext, } from "./shared.js";
8
7
  function validateGroupExtends(groupName, extends_, groupNames) {
@@ -106,10 +105,7 @@ export function validateGroups(config) {
106
105
  if (group.settings !== undefined) {
107
106
  validateSettings(group.settings, `groups.${groupName}`, rootCtx);
108
107
  }
109
- if (group.prOptions?.branch !== undefined) {
110
- validateBranchName(group.prOptions.branch);
111
- }
112
- validateAiOption(group.prOptions?.ai);
108
+ validatePrOptions(group.prOptions, `groups.${groupName}`);
113
109
  }
114
110
  validateNoCircularExtends(config.groups);
115
111
  }
@@ -172,9 +168,6 @@ export function validateConditionalGroups(config) {
172
168
  if (entry.settings !== undefined) {
173
169
  validateSettings(entry.settings, ctx, rootCtx);
174
170
  }
175
- if (entry.prOptions?.branch !== undefined) {
176
- validateBranchName(entry.prOptions.branch);
177
- }
178
- validateAiOption(entry.prOptions?.ai);
171
+ validatePrOptions(entry.prOptions, ctx);
179
172
  }
180
173
  }
@@ -0,0 +1,3 @@
1
+ export declare function validateInheritFlag(block: Record<string, unknown>, context: string): void;
2
+ /** Root blocks have nothing to inherit from, so `inherit` there is a mistake. */
3
+ export declare function assertNoRootInherit(block: unknown, name: string, context?: string): void;
@@ -0,0 +1,14 @@
1
+ import { ValidationError } from "../../shared/errors.js";
2
+ import { isPlainObject } from "../../shared/type-guards.js";
3
+ export function validateInheritFlag(block, context) {
4
+ if (block.inherit !== undefined && typeof block.inherit !== "boolean") {
5
+ throw new ValidationError(`${context}: inherit must be a boolean`);
6
+ }
7
+ }
8
+ /** Root blocks have nothing to inherit from, so `inherit` there is a mistake. */
9
+ export function assertNoRootInherit(block, name, context = "") {
10
+ if (!isPlainObject(block) || !("inherit" in block))
11
+ return;
12
+ const prefix = context ? `${context}: ` : "";
13
+ throw new ValidationError(`${prefix}'inherit' is not allowed in root-level ${name} (nothing to inherit from)`);
14
+ }
@@ -0,0 +1,3 @@
1
+ import type { RawPRMergeOptions } from "../types.js";
2
+ /** Validates prOptions of one layer; `context` names the layer, empty for the root. */
3
+ export declare function validatePrOptions(prOptions: RawPRMergeOptions | undefined, context?: string): void;
@@ -0,0 +1,32 @@
1
+ import { ValidationError } from "../../shared/errors.js";
2
+ import { validateBranchName } from "../../shared/branch-validation.js";
3
+ import { arrayValues, explainNotArray } from "../array-directive.js";
4
+ import { validateAiLayer } from "./ai-validator.js";
5
+ import { assertNoRootInherit } from "./inherit-flag.js";
6
+ /** Validates prOptions of one layer; `context` names the layer, empty for the root. */
7
+ export function validatePrOptions(prOptions, context = "") {
8
+ if (prOptions === undefined)
9
+ return;
10
+ const prefix = context ? `${context}: ` : "";
11
+ if (!context)
12
+ assertNoRootInherit(prOptions, "prOptions");
13
+ if (prOptions.inherit !== undefined &&
14
+ typeof prOptions.inherit !== "boolean") {
15
+ throw new ValidationError(`${prefix}prOptions.inherit must be a boolean`);
16
+ }
17
+ if (prOptions.branch !== undefined) {
18
+ validateBranchName(prOptions.branch);
19
+ }
20
+ validateAiLayer(prOptions.ai, context);
21
+ if (prOptions.labels === undefined)
22
+ return;
23
+ const labels = arrayValues(prOptions.labels);
24
+ if (labels === null) {
25
+ throw new ValidationError(explainNotArray(`${prefix}prOptions.labels must be an array of strings or $arrayMerge directive`, prOptions.labels));
26
+ }
27
+ for (const label of labels) {
28
+ if (typeof label !== "string" || label.length === 0) {
29
+ throw new ValidationError(`${prefix}prOptions.labels entries must be non-empty strings`);
30
+ }
31
+ }
32
+ }
@@ -3,8 +3,7 @@ import { validateFileName } from "./file-validator.js";
3
3
  import { isPlainObject } from "../../shared/type-guards.js";
4
4
  import { escapeRegExp } from "../../shared/regex-utils.js";
5
5
  import { ValidationError } from "../../shared/errors.js";
6
- import { validateBranchName } from "../../shared/branch-validation.js";
7
- import { validateAiOption } from "./ai-validator.js";
6
+ import { validatePrOptions } from "./pr-options-validator.js";
8
7
  import { validateFileConfigFields, validateSettings, buildRootSettingsContext, enrichSettingsContext, } from "./shared.js";
9
8
  function isValidGitUrl(url) {
10
9
  return /^git@[^:]+:.+$/.test(url) || /^https?:\/\/[^/]+\/.+$/.test(url);
@@ -158,17 +157,11 @@ function validateRepoSettingsEntry(config, repo, repoLabel) {
158
157
  }
159
158
  validateSettings(repo.settings, `Repo ${repoLabel}`, rootCtx);
160
159
  }
161
- function validateRepoPrOptions(repo) {
162
- if (repo.prOptions?.branch !== undefined) {
163
- validateBranchName(repo.prOptions.branch);
164
- }
165
- validateAiOption(repo.prOptions?.ai);
166
- }
167
160
  export function validateRepoEntry(config, repo, index) {
168
161
  const repoLabel = validateRepoGitField(repo, index);
169
162
  validateRepoOrigins(config, repo, repoLabel);
170
163
  validateRepoGroups(config, repo, index);
171
164
  validateRepoFiles(config, repo, index, repoLabel);
172
165
  validateRepoSettingsEntry(config, repo, repoLabel);
173
- validateRepoPrOptions(repo);
166
+ validatePrOptions(repo.prOptions, `Repo ${repoLabel}`);
174
167
  }
@@ -1,4 +1 @@
1
- /**
2
- * Validates a single ruleset.
3
- */
4
1
  export declare function validateRuleset(ruleset: unknown, name: string, context: string): void;
@@ -1,5 +1,6 @@
1
1
  import { ValidationError } from "../../shared/errors.js";
2
2
  import { isPlainObject } from "../../shared/type-guards.js";
3
+ import { arrayValues, explainNotArray } from "../array-directive.js";
3
4
  import { validValues } from "./file-validator.js";
4
5
  const VALID_RULESET_TARGETS = validValues(["branch", "tag"]);
5
6
  const VALID_ENFORCEMENT_LEVELS = validValues([
@@ -64,35 +65,22 @@ const VALID_RULE_TYPES = validValues([
64
65
  "max_file_path_length",
65
66
  "max_file_size",
66
67
  ]);
67
- // Intentionally duplicated from merge.ts — validator should not depend on merge internals
68
- const VALID_MERGE_STRATEGIES = ["replace", "append", "prepend", "merge"];
69
- const DIRECTIVE_KEYS = new Set(["$arrayMerge", "$values", "$matchBy"]);
70
- /**
71
- * Checks if a value is an $arrayMerge directive:
72
- * { $arrayMerge: strategy, $values: [...], $matchBy?: key }
73
- */
74
- function isArrayMergeDirective(value) {
75
- if (!isPlainObject(value))
76
- return false;
77
- return (Object.keys(value).every((k) => DIRECTIVE_KEYS.has(k)) &&
78
- VALID_MERGE_STRATEGIES.includes(value.$arrayMerge) &&
79
- Array.isArray(value.$values) &&
80
- (value.$matchBy === undefined || typeof value.$matchBy === "string"));
81
- }
82
- /**
83
- * Extracts the $values array from a directive, or returns the value as-is if it's already an array.
84
- * Returns null if value is neither an array nor a valid directive.
85
- */
86
- function extractArrayOrDirectiveValues(value) {
87
- if (Array.isArray(value))
88
- return value;
89
- if (isArrayMergeDirective(value))
90
- return value.$values;
91
- return null;
68
+ function arrayParam(params, key, context) {
69
+ if (params[key] === undefined)
70
+ return undefined;
71
+ const values = arrayValues(params[key]);
72
+ if (values === null) {
73
+ throw new ValidationError(explainNotArray(`${context}: ${key} must be an array or $arrayMerge directive`, params[key]));
74
+ }
75
+ return values;
92
76
  }
93
- /**
94
- * Validates a single ruleset rule.
95
- */
77
+ const ARRAY_PARAMS_BY_RULE_TYPE = {
78
+ required_status_checks: ["requiredStatusChecks"],
79
+ required_deployments: ["requiredDeploymentEnvironments"],
80
+ workflows: ["workflows"],
81
+ file_path_restriction: ["restrictedFilePaths"],
82
+ file_extension_restriction: ["restrictedFileExtensions"],
83
+ };
96
84
  function validateRule(rule, context) {
97
85
  if (typeof rule !== "object" || rule === null || Array.isArray(rule)) {
98
86
  throw new ValidationError(`${context}: rule must be an object`);
@@ -104,7 +92,6 @@ function validateRule(rule, context) {
104
92
  if (!VALID_RULE_TYPES.includes(r.type)) {
105
93
  throw new ValidationError(`${context}: invalid rule type '${r.type}'. Must be one of: ${VALID_RULE_TYPES.join(", ")}`);
106
94
  }
107
- // Validate parameters based on rule type
108
95
  if (r.parameters !== undefined) {
109
96
  if (typeof r.parameters !== "object" ||
110
97
  r.parameters === null ||
@@ -112,7 +99,6 @@ function validateRule(rule, context) {
112
99
  throw new ValidationError(`${context}: rule parameters must be an object`);
113
100
  }
114
101
  const params = r.parameters;
115
- // Validate pattern rule parameters
116
102
  if (r.type.toString().endsWith("_pattern")) {
117
103
  if (params.operator !== undefined &&
118
104
  !VALID_PATTERN_OPERATORS.includes(params.operator)) {
@@ -122,7 +108,6 @@ function validateRule(rule, context) {
122
108
  throw new ValidationError(`${context}: pattern rule pattern must be a string`);
123
109
  }
124
110
  }
125
- // Validate pull_request parameters
126
111
  if (r.type === "pull_request") {
127
112
  if (params.requiredApprovingReviewCount !== undefined) {
128
113
  const count = params.requiredApprovingReviewCount;
@@ -133,23 +118,22 @@ function validateRule(rule, context) {
133
118
  throw new ValidationError(`${context}: requiredApprovingReviewCount must be an integer between 0 and 10`);
134
119
  }
135
120
  }
136
- if (params.allowedMergeMethods !== undefined) {
137
- if (!Array.isArray(params.allowedMergeMethods)) {
138
- throw new ValidationError(`${context}: allowedMergeMethods must be an array`);
121
+ const methods = arrayParam(params, "allowedMergeMethods", context);
122
+ for (const method of methods ?? []) {
123
+ if (!VALID_MERGE_METHODS.includes(method)) {
124
+ throw new ValidationError(`${context}: allowedMergeMethods values must be one of: ${VALID_MERGE_METHODS.join(", ")}`);
139
125
  }
140
- for (const method of params.allowedMergeMethods) {
141
- if (!VALID_MERGE_METHODS.includes(method)) {
142
- throw new ValidationError(`${context}: allowedMergeMethods values must be one of: ${VALID_MERGE_METHODS.join(", ")}`);
143
- }
126
+ }
127
+ const reviewers = arrayParam(params, "requiredReviewers", context);
128
+ for (const reviewer of reviewers ?? []) {
129
+ if (isPlainObject(reviewer)) {
130
+ arrayParam(reviewer, "filePatterns", `${context}: requiredReviewers`);
144
131
  }
145
132
  }
146
133
  }
147
- // Validate code_scanning parameters
148
- if (r.type === "code_scanning" && params.codeScanningTools !== undefined) {
149
- if (!Array.isArray(params.codeScanningTools)) {
150
- throw new ValidationError(`${context}: codeScanningTools must be an array`);
151
- }
152
- for (const tool of params.codeScanningTools) {
134
+ if (r.type === "code_scanning") {
135
+ const tools = arrayParam(params, "codeScanningTools", context);
136
+ for (const tool of tools ?? []) {
153
137
  if (typeof tool !== "object" || tool === null) {
154
138
  throw new ValidationError(`${context}: each codeScanningTool must be an object`);
155
139
  }
@@ -164,11 +148,11 @@ function validateRule(rule, context) {
164
148
  }
165
149
  }
166
150
  }
151
+ for (const key of ARRAY_PARAMS_BY_RULE_TYPE[r.type] ?? []) {
152
+ arrayParam(params, key, context);
153
+ }
167
154
  }
168
155
  }
169
- /**
170
- * Validates a single ruleset.
171
- */
172
156
  export function validateRuleset(ruleset, name, context) {
173
157
  if (typeof ruleset !== "object" ||
174
158
  ruleset === null ||
@@ -184,11 +168,10 @@ export function validateRuleset(ruleset, name, context) {
184
168
  !VALID_ENFORCEMENT_LEVELS.includes(rs.enforcement)) {
185
169
  throw new ValidationError(`${context}: ruleset '${name}' enforcement must be one of: ${VALID_ENFORCEMENT_LEVELS.join(", ")}`);
186
170
  }
187
- // Validate bypassActors
188
171
  if (rs.bypassActors !== undefined) {
189
- const actors = extractArrayOrDirectiveValues(rs.bypassActors);
172
+ const actors = arrayValues(rs.bypassActors);
190
173
  if (actors === null) {
191
- throw new ValidationError(`${context}: ruleset '${name}' bypassActors must be an array or $arrayMerge directive`);
174
+ throw new ValidationError(explainNotArray(`${context}: ruleset '${name}' bypassActors must be an array or $arrayMerge directive`, rs.bypassActors));
192
175
  }
193
176
  for (let i = 0; i < actors.length; i++) {
194
177
  const actor = actors[i];
@@ -207,7 +190,6 @@ export function validateRuleset(ruleset, name, context) {
207
190
  }
208
191
  }
209
192
  }
210
- // Validate conditions
211
193
  if (rs.conditions !== undefined) {
212
194
  if (typeof rs.conditions !== "object" ||
213
195
  rs.conditions === null ||
@@ -223,24 +205,23 @@ export function validateRuleset(ruleset, name, context) {
223
205
  throw new ValidationError(`${context}: ruleset '${name}' conditions.refName must be an object`);
224
206
  }
225
207
  if (refName.include !== undefined) {
226
- const include = extractArrayOrDirectiveValues(refName.include);
208
+ const include = arrayValues(refName.include);
227
209
  if (include === null || !include.every((s) => typeof s === "string")) {
228
- throw new ValidationError(`${context}: ruleset '${name}' conditions.refName.include must be an array of strings or $arrayMerge directive with string $values`);
210
+ throw new ValidationError(explainNotArray(`${context}: ruleset '${name}' conditions.refName.include must be an array of strings or $arrayMerge directive with string $values`, refName.include));
229
211
  }
230
212
  }
231
213
  if (refName.exclude !== undefined) {
232
- const exclude = extractArrayOrDirectiveValues(refName.exclude);
214
+ const exclude = arrayValues(refName.exclude);
233
215
  if (exclude === null || !exclude.every((s) => typeof s === "string")) {
234
- throw new ValidationError(`${context}: ruleset '${name}' conditions.refName.exclude must be an array of strings or $arrayMerge directive with string $values`);
216
+ throw new ValidationError(explainNotArray(`${context}: ruleset '${name}' conditions.refName.exclude must be an array of strings or $arrayMerge directive with string $values`, refName.exclude));
235
217
  }
236
218
  }
237
219
  }
238
220
  }
239
- // Validate rules array
240
221
  if (rs.rules !== undefined) {
241
- const rules = extractArrayOrDirectiveValues(rs.rules);
222
+ const rules = arrayValues(rs.rules);
242
223
  if (rules === null) {
243
- throw new ValidationError(`${context}: ruleset '${name}' rules must be an array or $arrayMerge directive`);
224
+ throw new ValidationError(explainNotArray(`${context}: ruleset '${name}' rules must be an array or $arrayMerge directive`, rs.rules));
244
225
  }
245
226
  for (let i = 0; i < rules.length; i++) {
246
227
  validateRule(rules[i], `${context}: ruleset '${name}' rules[${i}]`);
@@ -1,11 +1,20 @@
1
1
  import type { RawConfig, RawRootSettings, RawRepoSettings } from "../types.js";
2
+ import type { RawCodeScanningSettings, DeploymentBranchPolicy } from "../types.js";
2
3
  export interface RootSettingsContext {
3
4
  rulesetNames: string[];
4
5
  hasRepoSettings: boolean;
5
6
  hasCodeScanningSettings: boolean;
7
+ hasActionsSettings: boolean;
6
8
  labelNames: string[];
7
9
  }
8
10
  export declare function buildRootSettingsContext(config: RawConfig): RootSettingsContext;
9
11
  export declare function validateFileConfigFields(fileConfig: Record<string, unknown>, fileName: string, context: string): void;
12
+ /** A layer may omit `state` and inherit it, so only the merged block can be checked. */
13
+ export declare function validateMergedCodeScanningSettings(codeScanning: RawCodeScanningSettings | undefined, context: string): void;
14
+ /**
15
+ * A layer sets only some fields, so the options that must go together are
16
+ * checked on the merged policy.
17
+ */
18
+ export declare function validateDeploymentBranchPolicy(policy: DeploymentBranchPolicy, context: string): void;
10
19
  export declare function validateSettings(settings: unknown, context: string, rootCtx?: RootSettingsContext): void;
11
20
  export declare function enrichSettingsContext(rootCtx: RootSettingsContext, settings: RawRepoSettings | RawRootSettings | undefined): void;