@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
package/parse/json.js
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @typedef {import("@humanwhocodes/momoa").AnyNode} AnyNode
|
|
3
|
-
* @typedef {import("@humanwhocodes/momoa").ObjectNode} ObjectNode
|
|
4
|
-
* @typedef {import("@humanwhocodes/momoa").ValueNode} ValueNode
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
export const CHILD_KEYS = {
|
|
8
|
-
Document: ['body'],
|
|
9
|
-
Object: ['members'],
|
|
10
|
-
Member: ['name', 'value'],
|
|
11
|
-
Element: ['value'],
|
|
12
|
-
Array: ['elements'],
|
|
13
|
-
String: [],
|
|
14
|
-
Number: [],
|
|
15
|
-
Boolean: [],
|
|
16
|
-
Null: [],
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
/** Determines if a given value is an AST node. */
|
|
20
|
-
export function isNode(value) {
|
|
21
|
-
return value && typeof value === 'object' && 'type' in value && typeof value.type === 'string';
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Get ObjectNode members as object
|
|
26
|
-
* @param {ObjectNode} node
|
|
27
|
-
* @return {Record<string, ValueNode}
|
|
28
|
-
*/
|
|
29
|
-
export function getObjMembers(node) {
|
|
30
|
-
const members = {};
|
|
31
|
-
if (node.type !== 'Object') {
|
|
32
|
-
return members;
|
|
33
|
-
}
|
|
34
|
-
for (const m of node.members) {
|
|
35
|
-
if (m.name.type !== 'String' && m.name.type !== 'Number') {
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
members[m.name.value] = m.value;
|
|
39
|
-
}
|
|
40
|
-
return members;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Inject members to ObjectNode and return a clone
|
|
45
|
-
* @param {ObjectNode} node
|
|
46
|
-
* @param {MemberNode[]} members
|
|
47
|
-
* @return {ObjectNode}
|
|
48
|
-
*/
|
|
49
|
-
export function injectObjMembers(node, members = []) {
|
|
50
|
-
if (node.type !== 'Object') {
|
|
51
|
-
return node;
|
|
52
|
-
}
|
|
53
|
-
const newNode = structuredClone(node);
|
|
54
|
-
newNode.members.push(...members);
|
|
55
|
-
return newNode;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Variation of Momoa’s traverse(), which keeps track of global path
|
|
60
|
-
*/
|
|
61
|
-
export function traverse(root, visitor) {
|
|
62
|
-
/**
|
|
63
|
-
* Recursively visits a node.
|
|
64
|
-
* @param {AnyNode} node The node to visit.
|
|
65
|
-
* @param {AnyNode} [parent] The parent of the node to visit.
|
|
66
|
-
* @return {void}
|
|
67
|
-
*/
|
|
68
|
-
function visitNode(node, parent, path = []) {
|
|
69
|
-
const nextPath = [...path];
|
|
70
|
-
if (node.type === 'Member') {
|
|
71
|
-
nextPath.push(node.name.value);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
visitor.enter?.(node, parent, nextPath);
|
|
75
|
-
|
|
76
|
-
for (const key of CHILD_KEYS[node.type] ?? []) {
|
|
77
|
-
const value = node[key];
|
|
78
|
-
|
|
79
|
-
if (value && typeof value === 'object') {
|
|
80
|
-
if (Array.isArray(value)) {
|
|
81
|
-
for (let i = 0; i < value.length; i++) {
|
|
82
|
-
visitNode(value[i], node, key === 'elements' ? [...nextPath, String(i)] : nextPath);
|
|
83
|
-
}
|
|
84
|
-
} else if (isNode(value)) {
|
|
85
|
-
visitNode(value, node, nextPath);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
visitor.exit?.(node, parent, nextPath);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
visitNode(root, undefined, []);
|
|
94
|
-
}
|
package/parse/normalize.d.ts
DELETED
package/parse/validate.d.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import type { AnyNode, MemberNode, ValueNode } from '@humanwhocodes/momoa';
|
|
2
|
-
import type Logger from '../logger.js';
|
|
3
|
-
|
|
4
|
-
declare const FONT_WEIGHT_VALUES: Set<string>;
|
|
5
|
-
|
|
6
|
-
declare const STROKE_STYLE_VALUES: Set<string>;
|
|
7
|
-
declare const STROKE_STYLE_LINE_CAP_VALUES: Set<string>;
|
|
8
|
-
|
|
9
|
-
export interface ValidateOptions {
|
|
10
|
-
filename?: URL;
|
|
11
|
-
src: string;
|
|
12
|
-
logger: Logger;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function validateAliasSyntax($value: ValueNode, node: AnyNode, options: ValidateOptions): void;
|
|
16
|
-
|
|
17
|
-
export function validateBorder($value: ValueNode, node: AnyNode, options: ValidateOptions): void;
|
|
18
|
-
|
|
19
|
-
export function validateColor($value: ValueNode, node: AnyNode, options: ValidateOptions): void;
|
|
20
|
-
|
|
21
|
-
export function validateCubicBezier($value: ValueNode, node: AnyNode, options: ValidateOptions): void;
|
|
22
|
-
|
|
23
|
-
export function validateDimension($value: ValueNode, node: AnyNode, options: ValidateOptions): void;
|
|
24
|
-
|
|
25
|
-
export function validateDuration($value: ValueNode, node: AnyNode, options: ValidateOptions): void;
|
|
26
|
-
|
|
27
|
-
export function validateFontFamily($value: ValueNode, node: AnyNode, options: ValidateOptions): void;
|
|
28
|
-
|
|
29
|
-
export function validateFontWeight($value: ValueNode, node: AnyNode, options: ValidateOptions): void;
|
|
30
|
-
|
|
31
|
-
export function validateGradient($value: ValueNode, node: AnyNode, options: ValidateOptions): void;
|
|
32
|
-
|
|
33
|
-
export function validateNumber($value: ValueNode, node: AnyNode, options: ValidateOptions): void;
|
|
34
|
-
|
|
35
|
-
export function validateShadowLayer($value: ValueNode, node: AnyNode, options: ValidateOptions): void;
|
|
36
|
-
|
|
37
|
-
export function validateStrokeStyle($value: ValueNode, node: AnyNode, options: ValidateOptions): void;
|
|
38
|
-
|
|
39
|
-
export function validateTransition($value: ValueNode, node: AnyNode, options: ValidateOptions): void;
|
|
40
|
-
|
|
41
|
-
export function validateTypography($value: ValueNode, node: AnyNode, options: ValidateOptions): void;
|
|
42
|
-
|
|
43
|
-
export default function validate(node: MemberNode, options: ValidateOptions): void;
|