@terrazzo/parser 0.1.3 → 0.2.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/.turbo/turbo-build.log +4 -0
- package/CHANGELOG.md +17 -0
- package/CONTRIBUTING.md +0 -12
- package/dist/build/index.d.ts +19 -0
- package/dist/build/index.js +165 -0
- package/dist/build/index.js.map +1 -0
- package/dist/config.d.ts +7 -0
- package/dist/config.js +269 -0
- package/dist/config.js.map +1 -0
- package/{index.d.ts → dist/index.d.ts} +1 -5
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/code-frame.d.ts +30 -0
- package/dist/lib/code-frame.js +108 -0
- package/dist/lib/code-frame.js.map +1 -0
- package/dist/lint/index.d.ts +11 -0
- package/dist/lint/index.js +102 -0
- package/dist/lint/index.js.map +1 -0
- package/dist/lint/plugin-core/index.d.ts +12 -0
- package/dist/lint/plugin-core/index.js +40 -0
- package/dist/lint/plugin-core/index.js.map +1 -0
- package/dist/lint/plugin-core/lib/docs.d.ts +1 -0
- package/dist/lint/plugin-core/lib/docs.js +4 -0
- package/dist/lint/plugin-core/lib/docs.js.map +1 -0
- package/dist/lint/plugin-core/rules/a11y-min-contrast.d.ts +39 -0
- package/dist/lint/plugin-core/rules/a11y-min-contrast.js +58 -0
- package/dist/lint/plugin-core/rules/a11y-min-contrast.js.map +1 -0
- package/dist/lint/plugin-core/rules/a11y-min-font-size.d.ts +13 -0
- package/dist/lint/plugin-core/rules/a11y-min-font-size.js +45 -0
- package/dist/lint/plugin-core/rules/a11y-min-font-size.js.map +1 -0
- package/dist/lint/plugin-core/rules/colorspace.d.ts +14 -0
- package/dist/lint/plugin-core/rules/colorspace.js +85 -0
- package/dist/lint/plugin-core/rules/colorspace.js.map +1 -0
- package/dist/lint/plugin-core/rules/consistent-naming.d.ts +11 -0
- package/dist/lint/plugin-core/rules/consistent-naming.js +49 -0
- package/dist/lint/plugin-core/rules/consistent-naming.js.map +1 -0
- package/dist/lint/plugin-core/rules/descriptions.d.ts +9 -0
- package/dist/lint/plugin-core/rules/descriptions.js +32 -0
- package/dist/lint/plugin-core/rules/descriptions.js.map +1 -0
- package/dist/lint/plugin-core/rules/duplicate-values.d.ts +9 -0
- package/dist/lint/plugin-core/rules/duplicate-values.js +65 -0
- package/dist/lint/plugin-core/rules/duplicate-values.js.map +1 -0
- package/dist/lint/plugin-core/rules/max-gamut.d.ts +14 -0
- package/dist/lint/plugin-core/rules/max-gamut.js +101 -0
- package/dist/lint/plugin-core/rules/max-gamut.js.map +1 -0
- package/dist/lint/plugin-core/rules/required-children.d.ts +18 -0
- package/dist/lint/plugin-core/rules/required-children.js +78 -0
- package/dist/lint/plugin-core/rules/required-children.js.map +1 -0
- package/dist/lint/plugin-core/rules/required-modes.d.ts +13 -0
- package/dist/lint/plugin-core/rules/required-modes.js +52 -0
- package/dist/lint/plugin-core/rules/required-modes.js.map +1 -0
- package/dist/lint/plugin-core/rules/required-typography-properties.d.ts +10 -0
- package/dist/lint/plugin-core/rules/required-typography-properties.js +38 -0
- package/dist/lint/plugin-core/rules/required-typography-properties.js.map +1 -0
- package/dist/logger.d.ts +76 -0
- package/dist/logger.js +123 -0
- package/dist/logger.js.map +1 -0
- package/dist/parse/alias.d.ts +51 -0
- package/dist/parse/alias.js +188 -0
- package/dist/parse/alias.js.map +1 -0
- package/dist/parse/index.d.ts +27 -0
- package/dist/parse/index.js +379 -0
- package/dist/parse/index.js.map +1 -0
- package/dist/parse/json.d.ts +36 -0
- package/dist/parse/json.js +88 -0
- package/dist/parse/json.js.map +1 -0
- package/dist/parse/normalize.d.ts +23 -0
- package/dist/parse/normalize.js +163 -0
- package/dist/parse/normalize.js.map +1 -0
- package/dist/parse/validate.d.ts +45 -0
- package/dist/parse/validate.js +601 -0
- package/dist/parse/validate.js.map +1 -0
- package/dist/types.d.ts +264 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +7 -7
- package/{build/index.js → src/build/index.ts} +47 -63
- package/src/config.ts +280 -0
- package/src/index.ts +18 -0
- package/{lib/code-frame.js → src/lib/code-frame.ts} +41 -8
- package/src/lint/index.ts +135 -0
- package/src/lint/plugin-core/index.ts +47 -0
- package/src/lint/plugin-core/lib/docs.ts +3 -0
- package/src/lint/plugin-core/rules/a11y-min-contrast.ts +91 -0
- package/src/lint/plugin-core/rules/a11y-min-font-size.ts +64 -0
- package/src/lint/plugin-core/rules/colorspace.ts +101 -0
- package/src/lint/plugin-core/rules/consistent-naming.ts +65 -0
- package/src/lint/plugin-core/rules/descriptions.ts +41 -0
- package/src/lint/plugin-core/rules/duplicate-values.ts +80 -0
- package/src/lint/plugin-core/rules/max-gamut.ts +121 -0
- package/src/lint/plugin-core/rules/required-children.ts +104 -0
- package/src/lint/plugin-core/rules/required-modes.ts +71 -0
- package/src/lint/plugin-core/rules/required-typography-properties.ts +53 -0
- package/{logger.js → src/logger.ts} +55 -16
- package/src/parse/alias.ts +224 -0
- package/src/parse/index.ts +457 -0
- package/src/parse/json.ts +106 -0
- package/{parse/normalize.js → src/parse/normalize.ts} +70 -24
- package/{parse/validate.js → src/parse/validate.ts} +154 -236
- package/src/types.ts +310 -0
- package/build/index.d.ts +0 -113
- package/config.d.ts +0 -64
- package/config.js +0 -206
- package/index.js +0 -35
- package/lib/code-frame.d.ts +0 -56
- package/lint/index.d.ts +0 -44
- package/lint/index.js +0 -59
- package/lint/plugin-core/index.d.ts +0 -3
- package/lint/plugin-core/index.js +0 -12
- package/lint/plugin-core/rules/duplicate-values.d.ts +0 -10
- package/lint/plugin-core/rules/duplicate-values.js +0 -68
- package/logger.d.ts +0 -71
- package/parse/index.d.ts +0 -45
- package/parse/index.js +0 -592
- package/parse/json.d.ts +0 -30
- package/parse/json.js +0 -94
- package/parse/normalize.d.ts +0 -3
- package/parse/validate.d.ts +0 -43
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// This is copied from @babel/code-frame package but without the heavyweight color highlighting
|
|
2
|
+
// (note: Babel loads both chalk AND picocolors, and doesn’t treeshake well)
|
|
3
|
+
// Babel is MIT-licensed and unaffiliated with this project.
|
|
4
|
+
/**
|
|
5
|
+
* Extract what lines should be marked and highlighted.
|
|
6
|
+
*/
|
|
7
|
+
function getMarkerLines(loc, source, opts = {}) {
|
|
8
|
+
const startLoc = {
|
|
9
|
+
// @ts-ignore this is fine
|
|
10
|
+
column: 0,
|
|
11
|
+
// @ts-ignore this is fine
|
|
12
|
+
line: -1,
|
|
13
|
+
...loc.start,
|
|
14
|
+
};
|
|
15
|
+
const endLoc = {
|
|
16
|
+
...startLoc,
|
|
17
|
+
...loc.end,
|
|
18
|
+
};
|
|
19
|
+
const { linesAbove = 2, linesBelow = 3 } = opts || {};
|
|
20
|
+
const startLine = startLoc.line;
|
|
21
|
+
const startColumn = startLoc.column;
|
|
22
|
+
const endLine = endLoc.line;
|
|
23
|
+
const endColumn = endLoc.column;
|
|
24
|
+
let start = Math.max(startLine - (linesAbove + 1), 0);
|
|
25
|
+
let end = Math.min(source.length, endLine + linesBelow);
|
|
26
|
+
if (startLine === -1) {
|
|
27
|
+
start = 0;
|
|
28
|
+
}
|
|
29
|
+
if (endLine === -1) {
|
|
30
|
+
end = source.length;
|
|
31
|
+
}
|
|
32
|
+
const lineDiff = endLine - startLine;
|
|
33
|
+
const markerLines = {};
|
|
34
|
+
if (lineDiff) {
|
|
35
|
+
for (let i = 0; i <= lineDiff; i++) {
|
|
36
|
+
const lineNumber = i + startLine;
|
|
37
|
+
if (!startColumn) {
|
|
38
|
+
markerLines[lineNumber] = true;
|
|
39
|
+
}
|
|
40
|
+
else if (i === 0) {
|
|
41
|
+
const sourceLength = source[lineNumber - 1].length;
|
|
42
|
+
markerLines[lineNumber] = [startColumn, sourceLength - startColumn + 1];
|
|
43
|
+
}
|
|
44
|
+
else if (i === lineDiff) {
|
|
45
|
+
markerLines[lineNumber] = [0, endColumn];
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
const sourceLength = source[lineNumber - i].length;
|
|
49
|
+
markerLines[lineNumber] = [0, sourceLength];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
if (startColumn === endColumn) {
|
|
55
|
+
if (startColumn) {
|
|
56
|
+
markerLines[startLine] = [startColumn, 0];
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
markerLines[startLine] = true;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
markerLines[startLine] = [startColumn, endColumn - startColumn];
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return { start, end, markerLines };
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* RegExp to test for newlines in terminal.
|
|
70
|
+
*/
|
|
71
|
+
const NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
|
|
72
|
+
export function codeFrameColumns(rawLines, loc, opts = {}) {
|
|
73
|
+
const lines = rawLines.split(NEWLINE);
|
|
74
|
+
const { start, end, markerLines } = getMarkerLines(loc, lines, opts);
|
|
75
|
+
const hasColumns = loc.start && typeof loc.start.column === 'number';
|
|
76
|
+
const numberMaxWidth = String(end).length;
|
|
77
|
+
let frame = rawLines
|
|
78
|
+
.split(NEWLINE, end)
|
|
79
|
+
.slice(start, end)
|
|
80
|
+
.map((line, index) => {
|
|
81
|
+
const number = start + 1 + index;
|
|
82
|
+
const paddedNumber = ` ${number}`.slice(-numberMaxWidth);
|
|
83
|
+
const gutter = ` ${paddedNumber} |`;
|
|
84
|
+
const hasMarker = markerLines[number];
|
|
85
|
+
const lastMarkerLine = !markerLines[number + 1];
|
|
86
|
+
if (hasMarker) {
|
|
87
|
+
let markerLine = '';
|
|
88
|
+
if (Array.isArray(hasMarker)) {
|
|
89
|
+
const markerSpacing = line.slice(0, Math.max(hasMarker[0] - 1, 0)).replace(/[^\t]/g, ' ');
|
|
90
|
+
const numberOfMarkers = hasMarker[1] || 1;
|
|
91
|
+
markerLine = ['\n ', gutter.replace(/\d/g, ' '), ' ', markerSpacing, '^'.repeat(numberOfMarkers)].join('');
|
|
92
|
+
if (lastMarkerLine && opts.message) {
|
|
93
|
+
markerLine += ` ${opts.message}`;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return ['>', gutter, line.length > 0 ? ` ${line}` : '', markerLine].join('');
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
return ` ${gutter}${line.length > 0 ? ` ${line}` : ''}`;
|
|
100
|
+
}
|
|
101
|
+
})
|
|
102
|
+
.join('\n');
|
|
103
|
+
if (opts.message && !hasColumns) {
|
|
104
|
+
frame = `${' '.repeat(numberMaxWidth + 1)}${opts.message}\n${frame}`;
|
|
105
|
+
}
|
|
106
|
+
return frame;
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=code-frame.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-frame.js","sourceRoot":"","sources":["../../src/lib/code-frame.ts"],"names":[],"mappings":"AAAA,+FAA+F;AAC/F,4EAA4E;AAC5E,4DAA4D;AAyD5D;;GAEG;AACH,SAAS,cAAc,CAAC,GAAiB,EAAE,MAAgB,EAAE,OAAgB,EAAa;IACxF,MAAM,QAAQ,GAAG;QACf,0BAA0B;QAC1B,MAAM,EAAE,CAAC;QACT,0BAA0B;QAC1B,IAAI,EAAE,CAAC,CAAC;QACR,GAAG,GAAG,CAAC,KAAK;KACD,CAAC;IACd,MAAM,MAAM,GAAa;QACvB,GAAG,QAAQ;QACX,GAAG,GAAG,CAAC,GAAG;KACX,CAAC;IACF,MAAM,EAAE,UAAU,GAAG,CAAC,EAAE,UAAU,GAAG,CAAC,EAAE,GAAG,IAAI,IAAI,EAAE,CAAC;IACtD,MAAM,SAAS,GAAG,QAAQ,CAAC,IAAI,CAAC;IAChC,MAAM,WAAW,GAAG,QAAQ,CAAC,MAAM,CAAC;IACpC,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC;IAC5B,MAAM,SAAS,GA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AC;YACN,OAAO,IAAI,MAAM,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;QAC1D,CAAC;IACH,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAC;IAEd,IAAI,IAAI,CAAC,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC;QAChC,KAAK,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,cAAc,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,OAAO,KAAK,KAAK,EAAE,CAAC;IACvE,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type TokenNormalized } from '@terrazzo/token-tools';
|
|
2
|
+
import type { default as Logger } from '../logger.js';
|
|
3
|
+
import type { ConfigInit } from '../types.js';
|
|
4
|
+
export interface LintRunnerOptions {
|
|
5
|
+
tokens: Record<string, TokenNormalized>;
|
|
6
|
+
filename?: URL;
|
|
7
|
+
config: ConfigInit;
|
|
8
|
+
src: string;
|
|
9
|
+
logger: Logger;
|
|
10
|
+
}
|
|
11
|
+
export default function lintRunner({ tokens, filename, config, src, logger, }: LintRunnerOptions): Promise<void>;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { pluralize } from '@terrazzo/token-tools';
|
|
2
|
+
import { merge } from 'merge-anything';
|
|
3
|
+
const listFormat = new Intl.ListFormat('en-us');
|
|
4
|
+
export default async function lintRunner({ tokens, filename, config = {}, src, logger, }) {
|
|
5
|
+
const { plugins = [], lint } = config;
|
|
6
|
+
const unusedLintRules = Object.keys(lint?.rules ?? {});
|
|
7
|
+
for (const plugin of plugins) {
|
|
8
|
+
if (typeof plugin.lint === 'function') {
|
|
9
|
+
const s = performance.now();
|
|
10
|
+
logger.debug({ group: 'plugin', label: plugin.name, message: 'Start linting' });
|
|
11
|
+
const linter = plugin.lint();
|
|
12
|
+
const errors = [];
|
|
13
|
+
const warnings = [];
|
|
14
|
+
await Promise.all(Object.entries(linter).map(async ([id, rule]) => {
|
|
15
|
+
if (!(id in lint.rules) || lint.rules[id] === null) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const [severity, options] = lint.rules[id];
|
|
19
|
+
if (severity === 'off') {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
// note: this usually isn’t a Promise, but it _might_ be!
|
|
23
|
+
await rule.create({
|
|
24
|
+
id,
|
|
25
|
+
report(descriptor) {
|
|
26
|
+
let message = '';
|
|
27
|
+
if (!descriptor.message && !descriptor.messageId) {
|
|
28
|
+
logger.error({
|
|
29
|
+
label: `[plugin] ${plugin.name} › lint › ${id}`,
|
|
30
|
+
message: 'Unable to report error: missing message or messageId',
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
// handle message or messageId
|
|
34
|
+
if (descriptor.message) {
|
|
35
|
+
message = descriptor.message;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
if (!(descriptor.messageId in (rule.meta?.messages ?? {}))) {
|
|
39
|
+
logger.error({
|
|
40
|
+
label: `[plugin] ${plugin.name} › lint › ${id}`,
|
|
41
|
+
message: `messageId "${descriptor.messageId}" does not exist`,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
message = rule.meta?.messages?.[descriptor.messageId] ?? '';
|
|
45
|
+
}
|
|
46
|
+
// replace with descriptor.data (if any)
|
|
47
|
+
if (descriptor.data && typeof descriptor.data === 'object') {
|
|
48
|
+
for (const [k, v] of Object.entries(descriptor.data)) {
|
|
49
|
+
// lazy formatting
|
|
50
|
+
const formatted = ['string', 'number', 'boolean'].includes(typeof v) ? String(v) : JSON.stringify(v);
|
|
51
|
+
message = message.replace(/{{[^}]+}}/g, (inner) => {
|
|
52
|
+
const key = inner.substring(2, inner.length - 2).trim();
|
|
53
|
+
return key === k ? formatted : inner;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
(severity === 'error' ? errors : warnings).push({
|
|
58
|
+
label: id,
|
|
59
|
+
message,
|
|
60
|
+
filename,
|
|
61
|
+
node: descriptor.node,
|
|
62
|
+
src: descriptor.source?.src,
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
tokens,
|
|
66
|
+
filename,
|
|
67
|
+
src,
|
|
68
|
+
options: merge(rule.meta?.defaultOptions ?? [], rule.defaultOptions ?? [], // Note: is this the correct order to merge in?
|
|
69
|
+
options),
|
|
70
|
+
});
|
|
71
|
+
// tick off used rule
|
|
72
|
+
const unusedLintRuleI = unusedLintRules.indexOf(id);
|
|
73
|
+
if (unusedLintRuleI !== -1) {
|
|
74
|
+
unusedLintRules.splice(unusedLintRuleI, 1);
|
|
75
|
+
}
|
|
76
|
+
}));
|
|
77
|
+
for (const error of errors) {
|
|
78
|
+
logger.error({ ...error, continueOnError: true }); // print out all errors before exiting here
|
|
79
|
+
}
|
|
80
|
+
for (const warning of warnings) {
|
|
81
|
+
logger.warn(warning);
|
|
82
|
+
}
|
|
83
|
+
logger.debug({ group: 'plugin', label: plugin.name, message: 'Finish linting', timing: performance.now() - s });
|
|
84
|
+
if (errors.length) {
|
|
85
|
+
const counts = [pluralize(errors.length, 'error', 'errors')];
|
|
86
|
+
if (warnings.length) {
|
|
87
|
+
counts.push(pluralize(warnings.length, 'warning', 'warnings'));
|
|
88
|
+
}
|
|
89
|
+
logger.error({
|
|
90
|
+
message: `Lint failed with ${listFormat.format(counts)}`,
|
|
91
|
+
label: plugin.name,
|
|
92
|
+
continueOnError: false,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
// warn user if they have unused lint rules (they might have meant to configure something!)
|
|
98
|
+
for (const unusedRule of unusedLintRules) {
|
|
99
|
+
logger.warn({ group: 'parser', label: 'lint', message: `Unknown lint rule "${unusedRule}"` });
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=index.js.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,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,sBAAsB,UAAU,GAAG,EAAE,CAAC,CAAC;IAChG,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Plugin } from '../../types.js';
|
|
2
|
+
export * from './rules/a11y-min-contrast.js';
|
|
3
|
+
export * from './rules/a11y-min-font-size.js';
|
|
4
|
+
export * from './rules/colorspace.js';
|
|
5
|
+
export * from './rules/consistent-naming.js';
|
|
6
|
+
export * from './rules/descriptions.js';
|
|
7
|
+
export * from './rules/duplicate-values.js';
|
|
8
|
+
export * from './rules/max-gamut.js';
|
|
9
|
+
export * from './rules/required-children.js';
|
|
10
|
+
export * from './rules/required-modes.js';
|
|
11
|
+
export * from './rules/required-typography-properties.js';
|
|
12
|
+
export default function coreLintPlugin(): Plugin;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export * from './rules/a11y-min-contrast.js';
|
|
2
|
+
export * from './rules/a11y-min-font-size.js';
|
|
3
|
+
export * from './rules/colorspace.js';
|
|
4
|
+
export * from './rules/consistent-naming.js';
|
|
5
|
+
export * from './rules/descriptions.js';
|
|
6
|
+
export * from './rules/duplicate-values.js';
|
|
7
|
+
export * from './rules/max-gamut.js';
|
|
8
|
+
export * from './rules/required-children.js';
|
|
9
|
+
export * from './rules/required-modes.js';
|
|
10
|
+
export * from './rules/required-typography-properties.js';
|
|
11
|
+
import a11yMinContrast, { A11Y_MIN_CONTRAST } from './rules/a11y-min-contrast.js';
|
|
12
|
+
import a11yMinFontSize, { A11Y_MIN_FONT_SIZE } from './rules/a11y-min-font-size.js';
|
|
13
|
+
import colorspace, { COLORSPACE } from './rules/colorspace.js';
|
|
14
|
+
import consistentNaming, { CONSISTENT_NAMING } from './rules/consistent-naming.js';
|
|
15
|
+
import descriptions, { DESCRIPTIONS } from './rules/descriptions.js';
|
|
16
|
+
import duplicateValues, { DUPLICATE_VALUES } from './rules/duplicate-values.js';
|
|
17
|
+
import maxGamut, { MAX_GAMUT } from './rules/max-gamut.js';
|
|
18
|
+
import requiredChidlren, { REQUIRED_CHILDREN } from './rules/required-children.js';
|
|
19
|
+
import requiredModes, { REQUIRED_MODES } from './rules/required-modes.js';
|
|
20
|
+
import requiredTypographyProperties, { REQUIRED_TYPOGRAPHY_PROPERTIES, } from './rules/required-typography-properties.js';
|
|
21
|
+
export default function coreLintPlugin() {
|
|
22
|
+
return {
|
|
23
|
+
name: '@terrazzo/plugin-lint-core',
|
|
24
|
+
lint() {
|
|
25
|
+
return {
|
|
26
|
+
[COLORSPACE]: colorspace,
|
|
27
|
+
[CONSISTENT_NAMING]: consistentNaming,
|
|
28
|
+
[DESCRIPTIONS]: descriptions,
|
|
29
|
+
[DUPLICATE_VALUES]: duplicateValues,
|
|
30
|
+
[MAX_GAMUT]: maxGamut,
|
|
31
|
+
[REQUIRED_CHILDREN]: requiredChidlren,
|
|
32
|
+
[REQUIRED_MODES]: requiredModes,
|
|
33
|
+
[REQUIRED_TYPOGRAPHY_PROPERTIES]: requiredTypographyProperties,
|
|
34
|
+
[A11Y_MIN_CONTRAST]: a11yMinContrast,
|
|
35
|
+
[A11Y_MIN_FONT_SIZE]: a11yMinFontSize,
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lint/plugin-core/index.ts"],"names":[],"mappings":"AAIA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,uBAAuB,CAAC;AACtC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,yBAAyB,CAAC;AACxC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,sBAAsB,CAAC;AACrC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2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@
|
|
|
1
|
+
export declare function docsLink(ruleName: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"docs.js","sourceRoot":"","sources":["../../../../src/lint/plugin-core/lib/docs.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,QAAQ,CAAC,QAAgB;IACvC,OAAO,sCAAsC,QAAQ,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;AAC/E,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { LintRule } from '../../../types.js';
|
|
2
|
+
export declare const A11Y_MIN_CONTRAST = "a11y/min-contrast";
|
|
3
|
+
export interface RuleA11yMinContrastOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Whether to adhere to AA (minimum) or AAA (enhanced) contrast levels.
|
|
6
|
+
* @default "AA"
|
|
7
|
+
*/
|
|
8
|
+
level?: 'AA' | 'AAA';
|
|
9
|
+
/** Pairs of color tokens (and optionally typography) to test */
|
|
10
|
+
pairs: ContrastPair[];
|
|
11
|
+
}
|
|
12
|
+
export interface ContrastPair {
|
|
13
|
+
/** The foreground color token ID */
|
|
14
|
+
foreground: string;
|
|
15
|
+
/** The background color token ID */
|
|
16
|
+
background: string;
|
|
17
|
+
/**
|
|
18
|
+
* Is this pair for large text? Large text allows a smaller contrast ratio.
|
|
19
|
+
*
|
|
20
|
+
* Note: while WCAG has _suggested_ sizes and weights, those are merely
|
|
21
|
+
* suggestions. It’s always more reliable to determine what constitutes “large
|
|
22
|
+
* text” for your designs yourself, based on your typographic stack.
|
|
23
|
+
* @see https://www.w3.org/WAI/WCAG22/quickref/#contrast-minimum
|
|
24
|
+
*/
|
|
25
|
+
largeText?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export declare const WCAG2_MIN_CONTRAST: {
|
|
28
|
+
AA: {
|
|
29
|
+
default: number;
|
|
30
|
+
large: number;
|
|
31
|
+
};
|
|
32
|
+
AAA: {
|
|
33
|
+
default: number;
|
|
34
|
+
large: number;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
export declare const ERROR_INSUFFICIENT_CONTRAST = "INSUFFICIENT_CONTRAST";
|
|
38
|
+
declare const rule: LintRule<typeof ERROR_INSUFFICIENT_CONTRAST, RuleA11yMinContrastOptions>;
|
|
39
|
+
export default rule;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { tokenToCulori } from '@terrazzo/token-tools';
|
|
2
|
+
import { wcagContrast } from 'culori';
|
|
3
|
+
import { docsLink } from '../lib/docs.js';
|
|
4
|
+
export const A11Y_MIN_CONTRAST = 'a11y/min-contrast';
|
|
5
|
+
export const WCAG2_MIN_CONTRAST = {
|
|
6
|
+
AA: { default: 4.5, large: 3 },
|
|
7
|
+
AAA: { default: 7, large: 4.5 },
|
|
8
|
+
};
|
|
9
|
+
export const ERROR_INSUFFICIENT_CONTRAST = 'INSUFFICIENT_CONTRAST';
|
|
10
|
+
const rule = {
|
|
11
|
+
meta: {
|
|
12
|
+
messages: {
|
|
13
|
+
[ERROR_INSUFFICIENT_CONTRAST]: 'Pair {{ index }} failed; expected {{ expected }}, got {{ actual }} ({{ level }})',
|
|
14
|
+
},
|
|
15
|
+
docs: {
|
|
16
|
+
description: 'Enforce colors meet minimum contrast checks for WCAG 2.',
|
|
17
|
+
url: docsLink(A11Y_MIN_CONTRAST),
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
defaultOptions: { level: 'AA', pairs: [] },
|
|
21
|
+
create({ tokens, options, report }) {
|
|
22
|
+
for (let i = 0; i < options.pairs.length; i++) {
|
|
23
|
+
const { foreground, background, largeText } = options.pairs[i];
|
|
24
|
+
if (!tokens[foreground]) {
|
|
25
|
+
throw new Error(`Token ${foreground} does not exist`);
|
|
26
|
+
}
|
|
27
|
+
if (tokens[foreground].$type !== 'color') {
|
|
28
|
+
throw new Error(`Token ${foreground} isn’t a color`);
|
|
29
|
+
}
|
|
30
|
+
if (!tokens[background]) {
|
|
31
|
+
throw new Error(`Token ${background} does not exist`);
|
|
32
|
+
}
|
|
33
|
+
if (tokens[background].$type !== 'color') {
|
|
34
|
+
throw new Error(`Token ${background} isn’t a color`);
|
|
35
|
+
}
|
|
36
|
+
// Note: if these culors were unparseable, they would have already thrown an error before the linter
|
|
37
|
+
const a = tokenToCulori(tokens[foreground].$value);
|
|
38
|
+
const b = tokenToCulori(tokens[background].$value);
|
|
39
|
+
// Note: for the purposes of WCAG 2, foreground and background don’t
|
|
40
|
+
// matter. But in other contrast algorithms, they do.
|
|
41
|
+
const contrast = wcagContrast(a, b);
|
|
42
|
+
const min = WCAG2_MIN_CONTRAST[options.level ?? 'AA'][largeText ? 'large' : 'default'];
|
|
43
|
+
if (contrast < min) {
|
|
44
|
+
report({
|
|
45
|
+
messageId: ERROR_INSUFFICIENT_CONTRAST,
|
|
46
|
+
data: {
|
|
47
|
+
index: i + 1,
|
|
48
|
+
expected: min,
|
|
49
|
+
actual: Math.round(contrast * 100) / 100,
|
|
50
|
+
level: options.level,
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
export default rule;
|
|
58
|
+
//# sourceMappingURL=a11y-min-contrast.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"a11y-min-contrast.js","sourceRoot":"","sources":["../../../../src/lint/plugin-core/rules/a11y-min-contrast.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,MAAM,CAAC,MAAM,iBAAiB,GAAG,mBAAmB,CAAC;AA4BrD,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,EAAE,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE;IAC9B,GAAG,EAAE,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AED,oGAAoG;YACpG,MAAM,CAAC,GAAG,aAAa,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,MAAM,CAAE,CAAC;YACpD,MAAM,CAAC,GAAG,aAAa,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,MAAM,CAAE,CAAC;YAEpD,oEAAoE;YACpE,qDAAqD;YACrD,MAAM,QAAQ,GAAG,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YACpC,MAAM,GAAG,GAAG,kBAAkB,CAAC,OAAO,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;YACvF,IAAI,QAAQ,GAAG,GAAG,EAAE,CAAC;gBACnB,MAAM,CAAC;oBACL,SAAS,EAAE,2BAA2B;oBACtC,IAAI,EAAE;wBACJ,KAAK,EAAE,CAAC,GAAG,CAAC;wBACZ,QAAQ,EAAE,GAAG;wBACb,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,GAAG,CAAC,GAAG,GAAG;wBACxC,KAAK,EAAE,OAAO,CAAC,KAAK;qBACrB;iBACF,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;CACF,CAAC;AAEF,eAAe,IAAI,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { LintRule } from '../../../types.js';
|
|
2
|
+
export declare const A11Y_MIN_FONT_SIZE = "a11y/min-font-size";
|
|
3
|
+
export interface RuleA11yMinFontSizeOptions {
|
|
4
|
+
/** Minimum font size (pixels) */
|
|
5
|
+
minSizePx?: number;
|
|
6
|
+
/** Minimum font size (rems) */
|
|
7
|
+
minSizeRem?: number;
|
|
8
|
+
/** Token IDs to ignore. Accepts globs. */
|
|
9
|
+
ignore?: string[];
|
|
10
|
+
}
|
|
11
|
+
export declare const ERROR_TOO_SMALL = "TOO_SMALL";
|
|
12
|
+
declare const rule: LintRule<typeof ERROR_TOO_SMALL, RuleA11yMinFontSizeOptions>;
|
|
13
|
+
export default rule;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { isTokenMatch } from '@terrazzo/token-tools';
|
|
2
|
+
import { docsLink } from '../lib/docs.js';
|
|
3
|
+
export const A11Y_MIN_FONT_SIZE = 'a11y/min-font-size';
|
|
4
|
+
export const ERROR_TOO_SMALL = 'TOO_SMALL';
|
|
5
|
+
const rule = {
|
|
6
|
+
meta: {
|
|
7
|
+
messages: {
|
|
8
|
+
[ERROR_TOO_SMALL]: '{{ id }} font size too small. Expected minimum of {{ min }}',
|
|
9
|
+
},
|
|
10
|
+
docs: {
|
|
11
|
+
description: 'Enforce font sizes are no smaller than the given value.',
|
|
12
|
+
url: docsLink(A11Y_MIN_FONT_SIZE),
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
defaultOptions: {},
|
|
16
|
+
create({ tokens, options, report }) {
|
|
17
|
+
if (!options.minSizePx && !options.minSizeRem) {
|
|
18
|
+
throw new Error('Must specify at least one of minSizePx or minSizeRem');
|
|
19
|
+
}
|
|
20
|
+
for (const t of Object.values(tokens)) {
|
|
21
|
+
if (options.ignore && isTokenMatch(t.id, options.ignore)) {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
// skip aliases
|
|
25
|
+
if (t.aliasOf) {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (t.$type === 'typography' && 'fontSize' in t.$value) {
|
|
29
|
+
const fontSize = t.$value.fontSize;
|
|
30
|
+
if ((fontSize.unit === 'px' && options.minSizePx && fontSize.value < options.minSizePx) ||
|
|
31
|
+
(fontSize.unit === 'rem' && options.minSizeRem && fontSize.value < options.minSizeRem)) {
|
|
32
|
+
report({
|
|
33
|
+
messageId: ERROR_TOO_SMALL,
|
|
34
|
+
data: {
|
|
35
|
+
id: t.id,
|
|
36
|
+
min: options.minSizePx ? `${options.minSizePx}px` : `${options.minSizeRem}rem`,
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
export default rule;
|
|
45
|
+
//# sourceMappingURL=a11y-min-font-size.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"a11y-min-font-size.js","sourceRoot":"","sources":["../../../../src/lint/plugin-core/rules/a11y-min-font-size.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,MAAM,CAAC,MAAM,kBAAkB,GAAG,oBAAoB,CAAC;AAWvD,MAAM,CAAC,MAAM,eAAe,GAAG,WAAW,CAAC;AAE3C,MAAM,IAAI,GAAiE;IACzE,IAAI,EAAE;QACJ,QAAQ,EAAE;YACR,CAAC,eAAe,CAAC,EAAE,6DAA6D;SACjF;QACD,IAAI,EAAE;YACJ,WAAW,EAAE,yDAAyD;YACtE,GAAG,EAAE,QAAQ,CAAC,kBAAkB,CAAC;SAClC;KACF;IACD,cAAc,EAAE,EAAE;IAClB,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE;QAChC,IAAI,CAAC,OAAO,CAAC,SAAS,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC;YAC9C,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;QAC1E,CAAC;QAED,KAAK,MAAM,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;YACtC,IAAI,OAAO,CAAC,MAAM,IAAI,YAAY,CAAC,CAAC,CAAC,EAAE,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;gBACzD,SAAS;YACX,CAAC;YAED,eAAe;YACf,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC;gBACd,SAAS;YACX,CAAC;YAED,IAAI,CAAC,CAAC,KAAK,KAAK,YAAY,IAAI,UAAU,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;gBACvD,MAAM,QAAQ,GAAG,CAAC,CAAC,MAAM,CAAC,QAAS,CAAC;gBAEpC,IACE,CAAC,QAAQ,CAAC,IAAI,KAAK,IAAI,IAAI,OAAO,CAAC,SAAS,IAAI,QAAQ,CAAC,KAAK,GAAG,OAAO,CAAC,SAAS,CAAC;oBACnF,CAAC,QAAQ,CAAC,IAAI,KAAK,KAAK,IAAI,OAAO,CAAC,UAAU,IAAI,QAAQ,CAAC,KAAK,GAAG,OAAO,CAAC,UAAU,CAAC,EACtF,CAAC;oBACD,MAAM,CAAC;wBACL,SAAS,EAAE,eAAe;wBAC1B,IAAI,EAAE;4BACJ,EAAE,EAAE,CAAC,CAAC,EAAE;4BACR,GAAG,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,SAAS,IAAI,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,UAAU,KAAK;yBAC/E;qBACF,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;CACF,CAAC;AAEF,eAAe,IAAI,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type ColorValueNormalized } from '@terrazzo/token-tools';
|
|
2
|
+
import type { LintRule } from '../../../types.js';
|
|
3
|
+
export declare const COLORSPACE = "core/colorspace";
|
|
4
|
+
export interface RuleColorspaceOptions {
|
|
5
|
+
colorSpace: ColorValueNormalized['colorSpace'];
|
|
6
|
+
/** (optional) Token IDs to ignore. Supports globs (`*`). */
|
|
7
|
+
ignore?: string[];
|
|
8
|
+
}
|
|
9
|
+
declare const ERROR_COLOR = "COLOR";
|
|
10
|
+
declare const ERROR_BORDER = "BORDER";
|
|
11
|
+
declare const ERROR_GRADIENT = "GRADIENT";
|
|
12
|
+
declare const ERROR_SHADOW = "SHADOW";
|
|
13
|
+
declare const rule: LintRule<typeof ERROR_COLOR | typeof ERROR_BORDER | typeof ERROR_GRADIENT | typeof ERROR_SHADOW, RuleColorspaceOptions>;
|
|
14
|
+
export default rule;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { isTokenMatch } from '@terrazzo/token-tools';
|
|
2
|
+
import { docsLink } from '../lib/docs.js';
|
|
3
|
+
export const COLORSPACE = 'core/colorspace';
|
|
4
|
+
const ERROR_COLOR = 'COLOR';
|
|
5
|
+
const ERROR_BORDER = 'BORDER';
|
|
6
|
+
const ERROR_GRADIENT = 'GRADIENT';
|
|
7
|
+
const ERROR_SHADOW = 'SHADOW';
|
|
8
|
+
const rule = {
|
|
9
|
+
meta: {
|
|
10
|
+
messages: {
|
|
11
|
+
[ERROR_COLOR]: 'Color {{ id }} not in colorspace {{ colorSpace }}',
|
|
12
|
+
[ERROR_BORDER]: 'Border {{ id }} not in colorspace {{ colorSpace }}',
|
|
13
|
+
[ERROR_GRADIENT]: 'Gradient {{ id }} not in colorspace {{ colorSpace }}',
|
|
14
|
+
[ERROR_SHADOW]: 'Shadow {{ id }} not in colorspace {{ colorSpace }}',
|
|
15
|
+
},
|
|
16
|
+
docs: {
|
|
17
|
+
description: 'Enforce that all colors are in a specific colorspace.',
|
|
18
|
+
url: docsLink(COLORSPACE),
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
defaultOptions: { colorSpace: 'srgb' },
|
|
22
|
+
create({ tokens, options, report }) {
|
|
23
|
+
if (!options.colorSpace) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
for (const t of Object.values(tokens)) {
|
|
27
|
+
// skip ignored tokens
|
|
28
|
+
if (options?.ignore && isTokenMatch(t.id, options.ignore)) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
// skip aliases
|
|
32
|
+
if (t.aliasOf) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
switch (t.$type) {
|
|
36
|
+
case 'color': {
|
|
37
|
+
if (t.$value.colorSpace !== options.colorSpace) {
|
|
38
|
+
report({
|
|
39
|
+
messageId: ERROR_COLOR,
|
|
40
|
+
data: { id: t.id, colorSpace: options.colorSpace },
|
|
41
|
+
node: t.source.node,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
case 'border': {
|
|
47
|
+
if (!t.partialAliasOf?.color && t.$value.color.colorSpace !== options.colorSpace) {
|
|
48
|
+
report({
|
|
49
|
+
messageId: ERROR_BORDER,
|
|
50
|
+
data: { id: t.id, colorSpace: options.colorSpace },
|
|
51
|
+
node: t.source.node,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
case 'gradient': {
|
|
57
|
+
for (let stopI = 0; stopI < t.$value.length; stopI++) {
|
|
58
|
+
if (!t.partialAliasOf?.[stopI]?.color && t.$value[stopI].color.colorSpace !== options.colorSpace) {
|
|
59
|
+
report({
|
|
60
|
+
messageId: ERROR_GRADIENT,
|
|
61
|
+
data: { id: t.id, colorSpace: options.colorSpace },
|
|
62
|
+
node: t.source.node,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
case 'shadow': {
|
|
69
|
+
for (let shadowI = 0; shadowI < t.$value.length; shadowI++) {
|
|
70
|
+
if (!t.partialAliasOf?.[shadowI]?.color && t.$value[shadowI].color.colorSpace !== options.colorSpace) {
|
|
71
|
+
report({
|
|
72
|
+
messageId: ERROR_SHADOW,
|
|
73
|
+
data: { id: t.id, colorSpace: options.colorSpace },
|
|
74
|
+
node: t.source.node,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
export default rule;
|
|
85
|
+
//# sourceMappingURL=colorspace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"colorspace.js","sourceRoot":"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AAC,CAAC,MAAM,CAAC,IAAI;6BACpB,CAAC,CAAC;wBACL,CAAC;oBACH,CAAC;oBACD,MAAM;gBACR,CAAC;gBACD,KAAK,QAAQ,CAAC,CAAC,CAAC;oBACd,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,CAAC;wBAC3D,IAAI,CAAC,CAAC,CAAC,cAAc,EAAE,CAAC,OAAO,CAAC,EAAE,KAAK,IAAI,CAAC,CAAC,MAAM,CAAC,OAAO,CAAE,CAAC,KAAK,CAAC,UAAU,KAAK,OAAO,CAAC,UAAU,EAAE,CAAC;4BACtG,MAAM,CAAC;gCACL,SAAS,EAAE,YAAY;gCACvB,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE;gCAClD,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI;6BACpB,CAAC,CAAC;wBACL,CAAC;oBACH,CAAC;oBACD,MAAM;gBACR,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;CACF,CAAC;AAEF,eAAe,IAAI,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { LintRule } from '../../../types.js';
|
|
2
|
+
export declare const CONSISTENT_NAMING = "core/consistent-naming";
|
|
3
|
+
export declare const ERROR_WRONG_FORMAT = "ERROR_WRONG_FORMAT";
|
|
4
|
+
export interface RuleConsistentNamingOptions {
|
|
5
|
+
/** Specify format, or custom naming validator */
|
|
6
|
+
format: 'kebab-case' | 'camelCase' | 'PascalCase' | 'snake_case' | 'SCREAMING_SNAKE_CASE' | ((tokenID: string) => boolean);
|
|
7
|
+
/** Token IDs to ignore. Supports globs (`*`). */
|
|
8
|
+
ignore?: string[];
|
|
9
|
+
}
|
|
10
|
+
declare const rule: LintRule<typeof ERROR_WRONG_FORMAT, RuleConsistentNamingOptions>;
|
|
11
|
+
export default rule;
|