-
Notifications
You must be signed in to change notification settings - Fork 213
Expand file tree
/
Copy pathlint-with-many-rules.bench.ts
More file actions
44 lines (38 loc) · 1.25 KB
/
lint-with-many-rules.bench.ts
File metadata and controls
44 lines (38 loc) · 1.25 KB
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
import { readFileSync } from 'node:fs';
import { join as pathJoin, resolve as pathResolve, dirname } from 'node:path';
import { lintDocument } from '../../lint.js';
import { BaseResolver } from '../../resolve.js';
import { parseYamlToDocument, makeConfigForRuleset } from '../utils.js';
import { fileURLToPath } from 'node:url';
import type { StyleguideConfig } from '../../config/index.js';
const __internalDirname = dirname(fileURLToPath(import.meta.url ?? __dirname));
export const name = 'Validate with 50 top-level rules';
export const count = 10;
const rebillyDefinitionRef = pathResolve(pathJoin(__internalDirname, 'rebilly.yaml'));
const rebillyDocument = parseYamlToDocument(
readFileSync(rebillyDefinitionRef, 'utf-8'),
rebillyDefinitionRef
);
const ruleset: any = {};
for (let i = 0; i < 50; i++) {
ruleset['rule-' + i] = () => {
let count = 0;
return {
Schema() {
count++;
if (count === -1) throw new Error('Disable optimization');
},
};
};
}
let config: StyleguideConfig;
export async function setupAsync() {
config = await makeConfigForRuleset(ruleset);
}
export function measureAsync() {
return lintDocument({
externalRefResolver: new BaseResolver(),
document: rebillyDocument,
config,
});
}