@terrazzo/parser 0.8.1 → 0.9.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@terrazzo/parser",
3
- "version": "0.8.1",
3
+ "version": "0.9.0",
4
4
  "description": "Parser/validator for the Design Tokens Community Group (DTCG) standard.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -42,7 +42,7 @@
42
42
  "picocolors": "^1.1.1",
43
43
  "scule": "^1.3.0",
44
44
  "wildcard-match": "^5.1.4",
45
- "@terrazzo/token-tools": "^0.8.1"
45
+ "@terrazzo/token-tools": "^0.9.0"
46
46
  },
47
47
  "devDependencies": {
48
48
  "yaml-to-momoa": "^0.0.3"
@@ -1,5 +1,5 @@
1
1
  import type { DocumentNode } from '@humanwhocodes/momoa';
2
- import { type TokenNormalized, isTokenMatch } from '@terrazzo/token-tools';
2
+ import type { TokenNormalized } from '@terrazzo/token-tools';
3
3
  import wcmatch from 'wildcard-match';
4
4
  import Logger, { type LogEntry } from '../logger.js';
5
5
  import type { BuildRunnerResult, ConfigInit, TokenTransformed, TransformParams } from '../types.js';
@@ -55,6 +55,10 @@ export default async function build(
55
55
  logger.warn({ group: 'plugin', message: '"format" missing from getTransforms(), no tokens returned.' });
56
56
  return [];
57
57
  }
58
+
59
+ const tokenMatcher = params.id ? wcmatch(Array.isArray(params.id) ? params.id : [params.id]) : null;
60
+ const modeMatcher = params.mode ? wcmatch(params.mode) : null;
61
+
58
62
  return (formats[params.format!] ?? []).filter((token) => {
59
63
  if (params.$type) {
60
64
  if (typeof params.$type === 'string' && token.token.$type !== params.$type) {
@@ -63,14 +67,10 @@ export default async function build(
63
67
  return false;
64
68
  }
65
69
  }
66
- if (
67
- params.id &&
68
- params.id !== '*' &&
69
- !isTokenMatch(token.token.id, Array.isArray(params.id) ? params.id : [params.id])
70
- ) {
70
+ if (params.id && params.id !== '*' && tokenMatcher && !tokenMatcher(token.token.id)) {
71
71
  return false;
72
72
  }
73
- if (params.mode && !wcmatch(params.mode)(token.mode)) {
73
+ if (modeMatcher && !modeMatcher(token.mode)) {
74
74
  return false;
75
75
  }
76
76
  return true;
@@ -1,4 +1,4 @@
1
- import { isTokenMatch } from '@terrazzo/token-tools';
1
+ import wcmatch from 'wildcard-match';
2
2
  import type { LintRule } from '../../../types.js';
3
3
  import { docsLink } from '../lib/docs.js';
4
4
 
@@ -31,8 +31,10 @@ const rule: LintRule<typeof ERROR_TOO_SMALL, RuleA11yMinFontSizeOptions> = {
31
31
  throw new Error('Must specify at least one of minSizePx or minSizeRem');
32
32
  }
33
33
 
34
+ const shouldIgnore = options.ignore ? wcmatch(options.ignore) : null;
35
+
34
36
  for (const t of Object.values(tokens)) {
35
- if (options.ignore && isTokenMatch(t.id, options.ignore)) {
37
+ if (shouldIgnore?.(t.id)) {
36
38
  continue;
37
39
  }
38
40
 
@@ -1,4 +1,5 @@
1
- import { type ColorValueNormalized, isTokenMatch } from '@terrazzo/token-tools';
1
+ import type { ColorValueNormalized } from '@terrazzo/token-tools';
2
+ import wcmatch from 'wildcard-match';
2
3
  import type { LintRule } from '../../../types.js';
3
4
  import { docsLink } from '../lib/docs.js';
4
5
 
@@ -37,9 +38,11 @@ const rule: LintRule<
37
38
  return;
38
39
  }
39
40
 
41
+ const shouldIgnore = options.ignore ? wcmatch(options.ignore) : null;
42
+
40
43
  for (const t of Object.values(tokens)) {
41
44
  // skip ignored tokens
42
- if (options?.ignore && isTokenMatch(t.id, options.ignore)) {
45
+ if (shouldIgnore?.(t.id)) {
43
46
  continue;
44
47
  }
45
48
 
@@ -1,4 +1,4 @@
1
- import { isTokenMatch } from '@terrazzo/token-tools';
1
+ import wcmatch from 'wildcard-match';
2
2
  import type { LintRule } from '../../../types.js';
3
3
  import { docsLink } from '../lib/docs.js';
4
4
 
@@ -23,8 +23,10 @@ const rule: LintRule<typeof ERROR_MISSING_DESCRIPTION, RuleDescriptionsOptions>
23
23
  },
24
24
  defaultOptions: {},
25
25
  create({ tokens, options, report }) {
26
+ const shouldIgnore = options.ignore ? wcmatch(options.ignore) : null;
27
+
26
28
  for (const t of Object.values(tokens)) {
27
- if (options.ignore && isTokenMatch(t.id, options.ignore)) {
29
+ if (shouldIgnore?.(t.id)) {
28
30
  continue;
29
31
  }
30
32
  if (!t.$description) {
@@ -1,4 +1,5 @@
1
- import { isAlias, isTokenMatch } from '@terrazzo/token-tools';
1
+ import { isAlias } from '@terrazzo/token-tools';
2
+ import wcmatch from 'wildcard-match';
2
3
  import type { LintRule } from '../../../types.js';
3
4
  import { docsLink } from '../lib/docs.js';
4
5
 
@@ -25,9 +26,11 @@ const rule: LintRule<typeof ERROR_DUPLICATE_VALUE, RuleDuplicateValueOptions> =
25
26
  create({ report, tokens, options }) {
26
27
  const values: Record<string, Set<any>> = {};
27
28
 
29
+ const shouldIgnore = options.ignore ? wcmatch(options.ignore) : null;
30
+
28
31
  for (const t of Object.values(tokens)) {
29
32
  // skip ignored tokens
30
- if (options.ignore && isTokenMatch(t.id, options.ignore)) {
33
+ if (shouldIgnore?.(t.id)) {
31
34
  continue;
32
35
  }
33
36
 
@@ -1,5 +1,6 @@
1
- import { type ColorValueNormalized, isTokenMatch, tokenToCulori } from '@terrazzo/token-tools';
1
+ import { type ColorValueNormalized, tokenToCulori } from '@terrazzo/token-tools';
2
2
  import { type Color, clampChroma } from 'culori';
3
+ import wcmatch from 'wildcard-match';
3
4
  import type { LintRule } from '../../../types.js';
4
5
  import { docsLink } from '../lib/docs.js';
5
6
 
@@ -73,9 +74,11 @@ const rule: LintRule<
73
74
  throw new Error(`Unknown gamut "${options.gamut}". Options are "srgb", "p3", or "rec2020"`);
74
75
  }
75
76
 
77
+ const shouldIgnore = options.ignore ? wcmatch(options.ignore) : null;
78
+
76
79
  for (const t of Object.values(tokens)) {
77
80
  // skip ignored tokens
78
- if (options.ignore && isTokenMatch(t.id, options.ignore)) {
81
+ if (shouldIgnore?.(t.id)) {
79
82
  continue;
80
83
  }
81
84
 
@@ -1,4 +1,4 @@
1
- import { isTokenMatch } from '@terrazzo/token-tools';
1
+ import wcmatch from 'wildcard-match';
2
2
  import type { LintRule } from '../../../types.js';
3
3
  import { docsLink } from '../lib/docs.js';
4
4
 
@@ -56,11 +56,13 @@ const rule: LintRule<
56
56
  throw new Error(`Match ${matchI}: must declare either \`requiredTokens: […]\` or \`requiredGroups: […]\``);
57
57
  }
58
58
 
59
+ const matcher = wcmatch(match);
60
+
59
61
  const matchGroups: string[] = [];
60
62
  const matchTokens: string[] = [];
61
63
  let tokensMatched = false;
62
64
  for (const t of Object.values(tokens)) {
63
- if (!isTokenMatch(t.id, match)) {
65
+ if (!matcher(t.id)) {
64
66
  continue;
65
67
  }
66
68
  tokensMatched = true;
@@ -1,4 +1,4 @@
1
- import { isTokenMatch } from '@terrazzo/token-tools';
1
+ import wcmatch from 'wildcard-match';
2
2
  import type { LintRule } from '../../../types.js';
3
3
  import { docsLink } from '../lib/docs.js';
4
4
 
@@ -41,9 +41,11 @@ const rule: LintRule<never, RuleRequiredModesOptions> = {
41
41
  throw new Error(`Match ${matchI}: must declare \`modes: […]\``);
42
42
  }
43
43
 
44
+ const matcher = wcmatch(match);
45
+
44
46
  let tokensMatched = false;
45
47
  for (const t of Object.values(tokens)) {
46
- if (!isTokenMatch(t.id, match)) {
48
+ if (!matcher(t.id)) {
47
49
  continue;
48
50
  }
49
51
  tokensMatched = true;
@@ -1,4 +1,4 @@
1
- import { isTokenMatch } from '@terrazzo/token-tools';
1
+ import wcmatch from 'wildcard-match';
2
2
  import type { LintRule } from '../../../types.js';
3
3
  import { docsLink } from '../lib/docs.js';
4
4
 
@@ -28,8 +28,10 @@ const rule: LintRule<never, RuleRequiredTypographyPropertiesOptions> = {
28
28
  throw new Error(`"properties" can’t be empty`);
29
29
  }
30
30
 
31
+ const shouldIgnore = options.ignore ? wcmatch(options.ignore) : null;
32
+
31
33
  for (const t of Object.values(tokens)) {
32
- if (options.ignore && isTokenMatch(t.id, options.ignore)) {
34
+ if (shouldIgnore?.(t.id)) {
33
35
  continue;
34
36
  }
35
37
 
@@ -7,7 +7,8 @@ import {
7
7
  evaluate,
8
8
  print,
9
9
  } from '@humanwhocodes/momoa';
10
- import { type Token, type TokenNormalized, isAlias, isTokenMatch, splitID } from '@terrazzo/token-tools';
10
+ import { type Token, type TokenNormalized, isAlias, splitID } from '@terrazzo/token-tools';
11
+ import wcmatch from 'wildcard-match';
11
12
  import type Logger from '../logger.js';
12
13
  import type { ConfigInit } from '../types.js';
13
14
  import { getObjMembers, injectObjMembers } from './json.js';
@@ -858,7 +859,7 @@ export default function validateTokenNode(
858
859
  // point. However, if we are ignoring this token (or respecting
859
860
  // $deprecated, we can omit it from the output.
860
861
  const $deprecated = members.$deprecated && (evaluate(members.$deprecated) as string | boolean | undefined);
861
- if ((config.ignore.deprecated && $deprecated) || (config.ignore.tokens && isTokenMatch(id, config.ignore.tokens))) {
862
+ if ((config.ignore.deprecated && $deprecated) || (config.ignore.tokens && wcmatch(config.ignore.tokens)(id))) {
862
863
  return;
863
864
  }
864
865