@terrazzo/parser 0.1.2 → 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 +26 -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 -23
- package/{parse/validate.js → src/parse/validate.ts} +159 -227
- 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/index.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
// MIT License
|
|
2
|
-
//
|
|
3
|
-
// Copyright (c) 2021 Drew Powers
|
|
4
|
-
//
|
|
5
|
-
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
// of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
// in the Software without restriction, including without limitation the rights
|
|
8
|
-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
// copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
// furnished to do so, subject to the following conditions:
|
|
11
|
-
//
|
|
12
|
-
// The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
// copies or substantial portions of the Software.
|
|
14
|
-
//
|
|
15
|
-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
// SOFTWARE.
|
|
22
|
-
export { default as build } from './build/index.js';
|
|
23
|
-
export * from './build/index.js';
|
|
24
|
-
|
|
25
|
-
export { default as defineConfig } from './config.js';
|
|
26
|
-
export * from './config.js';
|
|
27
|
-
|
|
28
|
-
export { default as lintRunner } from './lint/index.js';
|
|
29
|
-
export * from './lint/index.js';
|
|
30
|
-
|
|
31
|
-
export { default as Logger } from './logger.js';
|
|
32
|
-
export * from './logger.js';
|
|
33
|
-
|
|
34
|
-
export { default as parse } from './parse/index.js';
|
|
35
|
-
export * from './parse/index.js';
|
package/lib/code-frame.d.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
// MIT License
|
|
2
|
-
//
|
|
3
|
-
// Copyright (c) 2014-present Sebastian McKenzie and other contributors
|
|
4
|
-
//
|
|
5
|
-
// Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
-
// a copy of this software and associated documentation files (the
|
|
7
|
-
// "Software"), to deal in the Software without restriction, including
|
|
8
|
-
// without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
-
// distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
-
// permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
-
// the following conditions:
|
|
12
|
-
//
|
|
13
|
-
// The above copyright notice and this permission notice shall be
|
|
14
|
-
// included in all copies or substantial portions of the Software.
|
|
15
|
-
//
|
|
16
|
-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
-
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
-
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
-
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
-
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
-
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
-
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
-
|
|
24
|
-
export interface Location {
|
|
25
|
-
line: number;
|
|
26
|
-
column: number;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface NodeLocation {
|
|
30
|
-
end?: Location;
|
|
31
|
-
start: Location;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export interface Options {
|
|
35
|
-
/** Syntax highlight the code as JavaScript for terminals. default: false */
|
|
36
|
-
highlightCode?: boolean;
|
|
37
|
-
/** The number of lines to show above the error. default: 2 */
|
|
38
|
-
linesAbove?: number;
|
|
39
|
-
/** The number of lines to show below the error. default: 3 */
|
|
40
|
-
linesBelow?: number;
|
|
41
|
-
/**
|
|
42
|
-
* Forcibly syntax highlight the code as JavaScript (for non-terminals);
|
|
43
|
-
* overrides highlightCode.
|
|
44
|
-
* default: false
|
|
45
|
-
*/
|
|
46
|
-
forceColor?: boolean;
|
|
47
|
-
/**
|
|
48
|
-
* Pass in a string to be displayed inline (if possible) next to the
|
|
49
|
-
* highlighted location in the code. If it can't be positioned inline,
|
|
50
|
-
* it will be placed above the code frame.
|
|
51
|
-
* default: nothing
|
|
52
|
-
*/
|
|
53
|
-
message?: string;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export function codeFrameColumns(input: string, location: NodeLocation, options?: Options): string;
|
package/lint/index.d.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type { AnyNode, DocumentNode } from '@humanwhocodes/momoa';
|
|
2
|
-
import type { Group } from '@terrazzo/token-tools';
|
|
3
|
-
import type { ConfigInit } from '../config.js';
|
|
4
|
-
import type Logger from '../logger.js';
|
|
5
|
-
|
|
6
|
-
export interface LintNotice {
|
|
7
|
-
/** Lint message shown to the user */
|
|
8
|
-
message: string;
|
|
9
|
-
/** Erring node (used to point to a specific line) */
|
|
10
|
-
node?: AnyNode;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export type LintRuleSeverity = 'error' | 'warn' | 'off';
|
|
14
|
-
export type LintRuleShorthand = LintRuleSeverity | 0 | 1 | 2;
|
|
15
|
-
export type LintRuleLonghand = [LintRuleSeverity | 0 | 1 | 2, any];
|
|
16
|
-
|
|
17
|
-
export interface LintRuleNormalized<O = any> {
|
|
18
|
-
id: string;
|
|
19
|
-
severity: LintRuleSeverity;
|
|
20
|
-
options?: O;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface LinterOptions<O = any> {
|
|
24
|
-
tokens: Group;
|
|
25
|
-
rule: {
|
|
26
|
-
id: string;
|
|
27
|
-
severity: LintRuleSeverity;
|
|
28
|
-
};
|
|
29
|
-
document: DocumentNode;
|
|
30
|
-
filename?: URL;
|
|
31
|
-
source?: string;
|
|
32
|
-
/** Any options the user has declared for this plugin */
|
|
33
|
-
options?: O;
|
|
34
|
-
}
|
|
35
|
-
export type Linter = (options: LinterOptions) => Promise<LintNotice[] | undefined>;
|
|
36
|
-
|
|
37
|
-
export interface LintRunnerOptions {
|
|
38
|
-
document: DocumentNode;
|
|
39
|
-
filename?: URL;
|
|
40
|
-
config: ConfigInit;
|
|
41
|
-
logger: Logger;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export default function lintRunner(options: LintRunnerOptions): Promise<void>;
|
package/lint/index.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { pluralize } from '@terrazzo/token-tools';
|
|
2
|
-
|
|
3
|
-
const listFormat = new Intl.ListFormat('en-us');
|
|
4
|
-
|
|
5
|
-
export default async function lintRunner({ tokens, ast, config = {}, logger }) {
|
|
6
|
-
const { plugins = [], lint = { rules: {} } } = config;
|
|
7
|
-
const unusedLintRules = Object.keys(lint?.rules ?? {});
|
|
8
|
-
|
|
9
|
-
for (const plugin of plugins) {
|
|
10
|
-
if (typeof plugin.lint === 'function') {
|
|
11
|
-
const s = performance.now();
|
|
12
|
-
logger.debug({ group: 'plugin', task: plugin.name, message: 'Start linting' });
|
|
13
|
-
|
|
14
|
-
const rules = plugin.lint();
|
|
15
|
-
const errorEntries = [];
|
|
16
|
-
const warnEntries = [];
|
|
17
|
-
await Promise.all(
|
|
18
|
-
Object.entries(rules).map(async ([id, linter]) => {
|
|
19
|
-
const { severity = 'warn' } = lint.rules[id] || {};
|
|
20
|
-
const results = await linter({ tokens, ast, rule: { id, severity } });
|
|
21
|
-
for (const result of results ?? []) {
|
|
22
|
-
const noticeList = severity === 'error' ? errorEntries : warnEntries;
|
|
23
|
-
noticeList.push({
|
|
24
|
-
message: result.message,
|
|
25
|
-
ast,
|
|
26
|
-
node: result.node,
|
|
27
|
-
continueOnError: true,
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// tick off used rule
|
|
32
|
-
const unusedLintRuleI = unusedLintRules.indexOf(id);
|
|
33
|
-
if (unusedLintRuleI !== -1) {
|
|
34
|
-
unusedLintRules.splice(unusedLintRuleI, 1);
|
|
35
|
-
}
|
|
36
|
-
}),
|
|
37
|
-
);
|
|
38
|
-
for (const entry of errorEntries) {
|
|
39
|
-
logger.error(entry);
|
|
40
|
-
}
|
|
41
|
-
for (const entry of warnEntries) {
|
|
42
|
-
logger.warn(entry);
|
|
43
|
-
}
|
|
44
|
-
logger.debug({ group: 'plugin', task: plugin.name, message: 'Finish linting', timing: performance.now() - s });
|
|
45
|
-
if (errorEntries.length) {
|
|
46
|
-
const counts = [pluralize(errorEntries.length, 'error', 'errors')];
|
|
47
|
-
if (warnEntries.length) {
|
|
48
|
-
counts.push(pluralize(warnEntries.length, 'warning', 'warnings'));
|
|
49
|
-
}
|
|
50
|
-
logger.error({ message: `Lint failed with ${listFormat.format(counts)}`, label: plugin.name });
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// warn user if they have unused lint rules (they might have meant to configure something!)
|
|
56
|
-
for (const unusedRule of unusedLintRules) {
|
|
57
|
-
logger.warn({ group: 'parser', task: 'lint', message: `Unknown lint rule "${unusedRule}"` });
|
|
58
|
-
}
|
|
59
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { LintNotice, LinterOptions } from '../../index.js';
|
|
2
|
-
|
|
3
|
-
export interface RuleDuplicateValueOptions {
|
|
4
|
-
/** (optional) Token IDs to ignore. Supports globs (`*`). */
|
|
5
|
-
ignore?: string[];
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export default function ruleDuplicateValues(
|
|
9
|
-
options: LinterOptions<RuleDuplicateValueOptions>,
|
|
10
|
-
): Promise<LintNotice[] | undefined>;
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { isAlias, isTokenMatch } from '@terrazzo/token-tools';
|
|
2
|
-
|
|
3
|
-
export default function ruleDuplicateValues({ tokens, rule: { severity }, options }) {
|
|
4
|
-
if (severity === 'off') {
|
|
5
|
-
return;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
const notices = [];
|
|
9
|
-
const values = {};
|
|
10
|
-
|
|
11
|
-
for (const id in tokens) {
|
|
12
|
-
if (!Object.hasOwn(tokens, id)) {
|
|
13
|
-
continue;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const t = tokens[id];
|
|
17
|
-
|
|
18
|
-
// skip ignored tokens
|
|
19
|
-
if (options?.ignore && isTokenMatch(id, options.ignore)) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (!values[t.$type]) {
|
|
24
|
-
values[t.$type] = new Set();
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// primitives: direct comparison is easy
|
|
28
|
-
if (
|
|
29
|
-
t.$type === 'color' ||
|
|
30
|
-
t.$type === 'dimension' ||
|
|
31
|
-
t.$type === 'duration' ||
|
|
32
|
-
t.$type === 'link' ||
|
|
33
|
-
t.$type === 'number' ||
|
|
34
|
-
t.$type === 'fontWeight'
|
|
35
|
-
) {
|
|
36
|
-
// skip aliases (note: $value will be resolved)
|
|
37
|
-
if (isAlias(t._original.$value)) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (values[t.$type]?.has(t.$value)) {
|
|
42
|
-
notices.push({ message: `Duplicated value: "${t.$value}" (${t.id})`, node: t.sourceNode });
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
values[t.$type]?.add(t.$value);
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// everything else: use deepEqual
|
|
51
|
-
let isDuplicate = false;
|
|
52
|
-
for (const v of values[t.$type]?.values() ?? []) {
|
|
53
|
-
if (JSON.stringify(t.$value) === JSON.stringify(v)) {
|
|
54
|
-
notices.push({ message: `Duplicated value (${t.id})`, node: t.sourceNode });
|
|
55
|
-
isDuplicate = true;
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (isDuplicate) {
|
|
61
|
-
continue;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
values[t.$type]?.add(t.$value);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return notices;
|
|
68
|
-
}
|
package/logger.d.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import type { AnyNode } from '@humanwhocodes/momoa';
|
|
2
|
-
|
|
3
|
-
declare const LOG_ORDER: readonly ['error', 'warn', 'info', 'debug'];
|
|
4
|
-
|
|
5
|
-
export type LogSeverity = 'error' | 'warn' | 'info' | 'debug';
|
|
6
|
-
|
|
7
|
-
export type LogLevel = LogSeverity | 'silent';
|
|
8
|
-
|
|
9
|
-
export type LogGroup = 'core' | 'plugin';
|
|
10
|
-
|
|
11
|
-
export interface LogEntry {
|
|
12
|
-
/** Error message to be logged */
|
|
13
|
-
message: string;
|
|
14
|
-
/** (optional) Prefix message with label */
|
|
15
|
-
label?: string;
|
|
16
|
-
/** (optional) File in disk */
|
|
17
|
-
filename?: URL;
|
|
18
|
-
/** Continue on error? (default: false) */
|
|
19
|
-
continueOnError?: boolean;
|
|
20
|
-
/** (optional) Show a code frame for the erring node */
|
|
21
|
-
node?: AnyNode;
|
|
22
|
-
/** (optional) To show a code frame, provide the original source code */
|
|
23
|
-
src?: string;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface DebugEntry {
|
|
27
|
-
/** `parser` | `plugin` */
|
|
28
|
-
group: 'parser' | 'plugin';
|
|
29
|
-
/** Current subtask or submodule */
|
|
30
|
-
task: string;
|
|
31
|
-
/** Error message to be logged */
|
|
32
|
-
message: string;
|
|
33
|
-
/** (optional) Show code below message */
|
|
34
|
-
codeFrame?: { src: string; line: number; column: number };
|
|
35
|
-
/** (optional) Display performance timing */
|
|
36
|
-
timing?: number;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export default class Logger {
|
|
40
|
-
constructor(options?: { level?: LogLevel; debugScope: string });
|
|
41
|
-
|
|
42
|
-
setLevel(level: LogLevel): void;
|
|
43
|
-
|
|
44
|
-
/** Log an error message (always; can’t be silenced) */
|
|
45
|
-
error(entry: LogEntry): void;
|
|
46
|
-
|
|
47
|
-
/** Log an info message (if logging level permits) */
|
|
48
|
-
info(entry: LogEntry): void;
|
|
49
|
-
|
|
50
|
-
/** Log a warning message (if logging level permits) */
|
|
51
|
-
warn(entry: LogEntry): void;
|
|
52
|
-
|
|
53
|
-
/** Log a diagnostics message (if logging level permits) */
|
|
54
|
-
debug(entry: DebugEntry): void;
|
|
55
|
-
|
|
56
|
-
/** Get current stats for logger instance */
|
|
57
|
-
stats(): {
|
|
58
|
-
errorCount: number;
|
|
59
|
-
infoCount: number;
|
|
60
|
-
warnCount: number;
|
|
61
|
-
debugCount: number;
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export class TokensJSONError extends Error {
|
|
66
|
-
level: LogLevel;
|
|
67
|
-
debugScope: string;
|
|
68
|
-
node?: AnyNode;
|
|
69
|
-
|
|
70
|
-
constructor(message: string, node: AnyNode);
|
|
71
|
-
}
|
package/parse/index.d.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import type { DocumentNode } from '@humanwhocodes/momoa';
|
|
2
|
-
import type { TokenNormalized } from '@terrazzo/token-tools';
|
|
3
|
-
import type yamlToMomoa from 'yaml-to-momoa';
|
|
4
|
-
import type { ConfigInit } from '../config.js';
|
|
5
|
-
import type Logger from '../logger.js';
|
|
6
|
-
|
|
7
|
-
export * from './validate.js';
|
|
8
|
-
|
|
9
|
-
export interface ParseInput {
|
|
10
|
-
/** Source filename (if read from disk) */
|
|
11
|
-
filename?: URL;
|
|
12
|
-
/** JSON/YAML string, or JSON-serializable object (if already in memory) */
|
|
13
|
-
src: string | object;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface ParseOptions {
|
|
17
|
-
logger?: Logger;
|
|
18
|
-
config: ConfigInit;
|
|
19
|
-
/** Skip lint step (default: false) */
|
|
20
|
-
skipLint?: boolean;
|
|
21
|
-
/** Continue on error? (Useful for `tz check`) (default: false) */
|
|
22
|
-
continueOnError?: boolean;
|
|
23
|
-
/** Provide yamlToMomoa module to parse YAML (by default, this isn’t shipped to cut down on package weight) */
|
|
24
|
-
yamlToMomoa?: typeof yamlToMomoa;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface ParseResult {
|
|
28
|
-
tokens: Record<string, TokenNormalized>;
|
|
29
|
-
/** ASTs are returned in order of input array */
|
|
30
|
-
sources: { filename?: URL; src: string; document: DocumentNode }[];
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Parse and validate Tokens JSON, and lint it
|
|
35
|
-
*/
|
|
36
|
-
export default function parse(input: ParseInput[], options: ParseOptions): Promise<ParseResult>;
|
|
37
|
-
|
|
38
|
-
/** Determine if an input is likely a JSON string */
|
|
39
|
-
export function maybeJSONString(input: unknown): boolean;
|
|
40
|
-
|
|
41
|
-
/** Resolve alias */
|
|
42
|
-
export function resolveAlias(
|
|
43
|
-
alias: string,
|
|
44
|
-
options: { tokens: Record<string, TokenNormalized>; logger: Logger; path: string[] },
|
|
45
|
-
): string | undefined;
|