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

100% Statements 14/14
90.9% Branches 10/11
100% Functions 1/1
100% Lines 13/13

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                11x 11x   11x 1x 1x     10x 2x 2x     8x   6x 6x 1x     6x    
import type { ValidationResult, ValidationError, ValidationWarning } from '../../types.js';
import { err, hasNumericRange } from './helpers.js';
import { SPACING_DESCRIPTORS } from './__generated-allowlists.js';
 
export default function validateSpacing(
  segments: string[],
  aliases: Record<string, string> = {},
): ValidationResult {
  const errors: ValidationError[] = [];
  const warnings: ValidationWarning[] = [];
 
  if (segments.length === 0) {
    errors.push(err('spacing', 'a range or descriptor after spacing', '(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 descriptor = segments.slice(0, -1).join('-');
  if (!SPACING_DESCRIPTORS.includes(descriptor)) {
    errors.push(err('spacing-descriptor', SPACING_DESCRIPTORS, descriptor));
  }
 
  return { errors, warnings };
}