stylelint-plugin-rhythmguard 3.17.0 → 3.19.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.
@@ -490,7 +490,7 @@ function customPropertyDeclarations(source, { lineComments = true } = {}) {
490
490
  /**
491
491
  * Sass variables and maps as token sources. Handles `$spacer: 1rem`, maps such
492
492
  * as `$spacers: (1: $spacer * .25, ...)` including nested maps, variable
493
- * references, `* / + -` arithmetic and `math.div()`. Anything it cannot
493
+ * references, `* / + -` arithmetic, `math.div()` and `px-to-rem()`. Anything it cannot
494
494
  * evaluate (function calls, strings, keywords, interpolated keys, cycles) is
495
495
  * skipped rather than guessed. Token names are `$name` or `$name.key.path`.
496
496
  */
@@ -530,6 +530,8 @@ function collectScssTokens(source, matchesKind, { lineComments = true } = {}) {
530
530
  // Namespaced maps such as GOV.UK's $govuk-spacing-points are only accepted
531
531
  // for the spacing kind, and only when they hold a real ladder (issue #86).
532
532
  const spacingKind = matchesKind('$spacing-probe');
533
+ // Scalars such as GitLab's $gl-spacing-scale-1..88 count the same way, per namespace (issue #167).
534
+ const namespacedScales = spacingKind ? collectNamespacedSpacingScales(declarations, resolveVariable) : new Set();
533
535
 
534
536
  for (const [name, raw] of declarations) {
535
537
  const tokenName = `$${name}`;
@@ -555,12 +557,32 @@ function collectScssTokens(source, matchesKind, { lineComments = true } = {}) {
555
557
  });
556
558
  continue;
557
559
  }
558
- push(tokenName, resolveVariable(name, new Set()));
560
+ push(tokenName, resolveVariable(name, new Set()), namespacedScales.has(name));
559
561
  }
560
562
 
561
563
  return tokens;
562
564
  }
563
565
 
566
+ /** The `<namespace>-spacing-scale-*` scalars whose namespace holds a real ladder. */
567
+ function collectNamespacedSpacingScales(declarations, resolveVariable) {
568
+ const byNamespace = new Map();
569
+ for (const [name, raw] of declarations) {
570
+ const match = isScssMap(raw) ? null : name.match(NAMESPACED_SPACING_SCALE);
571
+ const value = match ? resolveVariable(name, new Set()) : null;
572
+ if (!value) continue;
573
+ if (!byNamespace.has(match[1])) byNamespace.set(match[1], { lengths: new Set(), names: [] });
574
+ const entry = byNamespace.get(match[1]);
575
+ entry.names.push(name);
576
+ const formatted = formatScssValue(value);
577
+ if (/^-?\d*\.?\d+(?:px|rem|em)$/.test(formatted) && parseFloat(formatted) !== 0) entry.lengths.add(formatted);
578
+ }
579
+ const accepted = new Set();
580
+ for (const { lengths, names } of byNamespace.values()) {
581
+ if (lengths.size >= MIN_NAMESPACED_MAP_LENGTHS) names.forEach((name) => accepted.add(name));
582
+ }
583
+ return accepted;
584
+ }
585
+
564
586
  /**
565
587
  * A variable resolver over a Sass source text, for evaluating declaration
566
588
  * values: same-file declarations first, then `fallback(name)` for a length
@@ -594,6 +616,8 @@ function createScssVariableResolver(source, fallback = () => null) {
594
616
  /** `$<namespace>-spacing-points`, `$<ns>-space-scale`: one namespace segment before the anchor. */
595
617
  const NAMESPACED_SPACING_MAP = /^\$[a-z0-9]+-(?:space|spacing|spacer)s?(?:-|$)/i;
596
618
  const MIN_NAMESPACED_MAP_LENGTHS = 4;
619
+ /** `$gl-spacing-scale-1`, `$gl-spacing-scale-11-5`: one namespace segment, then a numbered step. Names here carry no `$`. */
620
+ const NAMESPACED_SPACING_SCALE = /^([a-z0-9]+)-spacing-scale-\d/i;
597
621
 
598
622
  /**
599
623
  * The value of a Sass variable declaration starting at `start`: the text up to
@@ -915,6 +939,8 @@ function createScssParser(tokens, resolveVariable, stack) {
915
939
  const closing = next();
916
940
  if (!closing || closing.type !== 'op' || closing.value !== ')') return null;
917
941
  if (token.name === 'math.div' && args.length === 2) return combine(args[0], '/', args[1]);
942
+ // GitLab's $grid-size: px-to-rem(8px). One px length renders as that length; a second argument changes the base.
943
+ if (token.name === 'px-to-rem' && args.length === 1 && args[0]?.unit === 'px') return args[0];
918
944
  return null;
919
945
  }
920
946
  return null;
package/types/audit.d.ts CHANGED
@@ -114,6 +114,8 @@ export interface AuditScanned {
114
114
  scssSkipped?: number;
115
115
  /** Stylesheets Stylelint skipped because the project's own .stylelintignore excludes them. */
116
116
  stylelintIgnored?: number;
117
+ /** Stylesheets found but not audited because Stylelint is not installed. */
118
+ stylelintMissing?: number;
117
119
  /** Stylesheets not audited because they look vendored, generated, test-only, minified or built. 0 with `includeNonAuthored`. */
118
120
  nonAuthoredSkipped?: number;
119
121
  /** The stylesheets counted in `nonAuthoredSkipped`, with why each was skipped. */