All files / packages/sds-stylelint-config/src/validators/global radius.ts

100% Statements 19/19
100% Branches 13/13
100% Functions 4/4
100% Lines 16/16

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 35        12x           9x 9x   9x 2x 2x     7x 1x 1x     6x 6x 9x   6x 2x 1x     6x    
import type { ValidationResult, ValidationError, ValidationWarning } from '../../types.js';
import { err } from './helpers.js';
import { RADIUS_DESCRIPTORS } from './__generated-allowlists.js';
 
const NAMED_SHAPES = RADIUS_DESCRIPTORS.filter((d) => d !== 'border');
 
export default function validateRadius(
  segments: string[],
  aliases: Record<string, string> = {},
): ValidationResult {
  const errors: ValidationError[] = [];
  const warnings: ValidationWarning[] = [];
 
  if (segments.length === 0 || segments[0] !== 'border') {
    errors.push(err('radius', '"border" as the first segment after radius', segments[0] || '(empty)'));
    return { errors, warnings };
  }
 
  if (segments.length !== 2) {
    errors.push(err('radius', 'radius-border-{range|shape}', `radius-${segments.join('-')}`));
    return { errors, warnings };
  }
 
  const value = segments[1];
  const isNumeric = !Number.isNaN(Number(value));
  const isNamedShape = NAMED_SHAPES.some((d) => d === `border-${value}`);
 
  if (!isNumeric && !isNamedShape) {
    const shapeNames = NAMED_SHAPES.map((d) => d.replace('border-', ''));
    errors.push(err('radius-value', ['numeric range', ...shapeNames], value));
  }
 
  return { errors, warnings };
}