-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhelpers.ts
58 lines (50 loc) · 1.27 KB
/
helpers.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { LogLevel, NullLogger } from 'noicejs';
import { RuleChange, RuleError } from '../src/rule/index.js';
import { SchemaRule } from '../src/rule/SchemaRule.js';
import { Document, Element } from '../src/source.js';
import { VisitorContext } from '../src/visitor/VisitorContext.js';
export function createErrorContext(name: string) {
const rule = new SchemaRule({
check: {},
desc: name,
level: LogLevel.Info,
name,
select: '',
tags: [name],
});
const ctx = new VisitorContext({
logger: NullLogger.global,
schemaOptions: {
coerce: false,
defaults: false,
mutate: false,
},
});
return { ctx, rule };
}
export function makeDocument(data: unknown): Document {
return {data, source: {data: '', path: ''}};
}
export function makeElement(data: unknown): Element {
return {
data,
document: makeDocument({}),
index: 0,
};
}
export function makeResults(names: Array<string>, changes: Array<RuleChange> = [], errors: Array<RuleError> = []) {
const rules = names.map((name) => new SchemaRule({
check: {},
desc: name,
level: LogLevel.Info,
name,
select: '',
tags: [],
}));
const results = rules.map((rule) => ({
changes,
errors,
rule,
}));
return { rules, results };
}