describeAccepted method

String describeAccepted(
  1. JxClassToken token,
  2. JxThemeContract theme
)

Valeurs acceptées par la règle, pour les messages d'erreur : suggestion la plus proche puis aperçu des valeurs possibles.

Implementation

String describeAccepted(JxClassToken token, JxThemeContract theme) {
  final category = themeCategory;
  final candidates = <String>[
    if (category != null && theme is JxTheme)
      ...theme.data.getCategory(category).keys,
    ...keywords.keys,
  ].where((v) => !disallowed.contains(v)).toList();
  final hints = <String>[];
  final raw = token.isArbitrary ? null : token.value;
  final closest = raw == null ? null : closestMatch(raw, candidates);
  if (closest != null) {
    hints.add('did you mean "${token.identifier}:$closest"?');
  }
  if (candidates.isNotEmpty) {
    final preview = candidates.take(12).join(', ');
    hints.add(
      'accepted values: $preview${candidates.length > 12 ? '…' : ''}',
    );
  }
  if (allowArbitrary) hints.add('or an arbitrary value in brackets');
  if (hints.isEmpty) return '';
  final text = hints.join('; ');
  return ' ${text[0].toUpperCase()}${text.substring(1)}.';
}