Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | 14x 14x 14x 1x 1x 13x 2x 2x 11x 9x 9x 9x 9x 1x 9x | import type { ValidationResult, ValidationError, ValidationWarning } from '../../types.js';
import { err, hasNumericRange, resolveDescriptor } from './helpers.js';
import { SHADOW_DESCRIPTORS } from './__generated-allowlists.js';
export default function validateShadow(
segments: string[],
aliases: Record<string, string> = {},
): ValidationResult {
const errors: ValidationError[] = [];
const warnings: ValidationWarning[] = [];
if (segments.length === 0) {
errors.push(err('shadow', 'a range or descriptor after shadow', '(empty)'));
return { errors, warnings };
}
if (!hasNumericRange(segments)) {
errors.push(err('range', 'numeric range as final segment', segments.at(-1) ?? '(missing)'));
return { errors, warnings };
}
if (segments.length === 1) return { errors, warnings };
const descriptorSegments = segments.slice(0, -1);
const { descriptor, warnings: aliasWarnings } = resolveDescriptor(descriptorSegments, aliases);
warnings.push(...aliasWarnings);
if (!SHADOW_DESCRIPTORS.includes(descriptor)) {
errors.push(err('shadow-descriptor', SHADOW_DESCRIPTORS, descriptor));
}
return { errors, warnings };
}
|