|
1 | | -import { |
2 | | - BUILD_EMIT_OPTIONS, |
3 | | - CONTROL_FLOW_OPTIONS, |
4 | | - INTEROP_CONSTRAINTS, |
5 | | - LANGUAGE_ENVIRONMENT_OPTIONS, |
6 | | - MODULE_RESOLUTION, |
7 | | - PROJECT_REFERENCES, |
8 | | - STRICT_CHECKS, |
9 | | - TYPE_CHECKING_BEHAVIOR, |
10 | | - WATCH_OPTIONS |
11 | | -} from './runner/ts-error-codes.js'; |
12 | | -import type {Audit, Group} from "@code-pushup/models"; |
13 | | -import {formatTitle, kebabCaseToCamelCase} from "./utils.js"; |
| 1 | +import type { Audit, Group } from '@code-pushup/models'; |
| 2 | +import { TS_ERROR_CODES } from './runner/ts-error-codes.js'; |
| 3 | +import { camelCaseToKebabCase, formatTitle } from './utils.js'; |
14 | 4 |
|
15 | 5 | export const TYPESCRIPT_PLUGIN_SLUG = 'typescript'; |
16 | 6 |
|
17 | | -export const AUDITS = [ |
18 | | - STRICT_CHECKS, BUILD_EMIT_OPTIONS, |
19 | | - CONTROL_FLOW_OPTIONS, TYPE_CHECKING_BEHAVIOR, |
20 | | - MODULE_RESOLUTION, PROJECT_REFERENCES, |
21 | | - WATCH_OPTIONS, INTEROP_CONSTRAINTS, LANGUAGE_ENVIRONMENT_OPTIONS |
22 | | -].flatMap(i => Object.entries(i)).reduce<Audit[]>( |
23 | | - (audits, [slug]) => { |
24 | | - const anchorText = kebabCaseToCamelCase(slug); |
25 | | - const title = formatTitle(slug); |
| 7 | +export const AUDITS = Object.values(TS_ERROR_CODES) |
| 8 | + .flatMap(i => Object.entries(i)) |
| 9 | + .reduce<Audit[]>((audits, [name]) => { |
| 10 | + const slug = camelCaseToKebabCase(name); |
| 11 | + const title = formatTitle(name); |
26 | 12 | return [ |
27 | 13 | ...audits, |
28 | 14 | { |
29 | 15 | slug, |
30 | 16 | title, |
31 | | - docsUrl: `https://www.typescriptlang.org/tsconfig/#${anchorText}` |
32 | | - }]; |
| 17 | + docsUrl: `https://www.typescriptlang.org/tsconfig/#${name}`, |
| 18 | + }, |
| 19 | + ]; |
33 | 20 | }, []); |
34 | 21 |
|
35 | | -export const GROUPS: Group[] = Object.entries({ |
36 | | - 'strict-checks': Object.keys(STRICT_CHECKS).map((slug) => ({slug, weight: 3})), |
37 | | - 'type-checking-behavior': Object.keys(TYPE_CHECKING_BEHAVIOR).map((slug) => ({slug, weight: 2})), |
38 | | - 'control-flow-options': Object.keys(CONTROL_FLOW_OPTIONS).map((slug) => ({slug, weight: 2})), |
39 | | - 'interop-constraints': Object.keys(INTEROP_CONSTRAINTS).map((slug) => ({slug, weight: 2})), |
40 | | - 'module-resolution': Object.keys(MODULE_RESOLUTION).map((slug) => ({slug, weight: 2})), |
41 | | - 'build-emit-options': Object.keys(BUILD_EMIT_OPTIONS).map((slug) => ({slug, weight: 1})), |
42 | | - 'project-references': Object.keys(PROJECT_REFERENCES).map((slug) => ({slug, weight: 1})), |
43 | | - 'watch-options': Object.keys(WATCH_OPTIONS).map((slug) => ({slug, weight: 1})), |
44 | | - 'language-environment-options': Object.keys(LANGUAGE_ENVIRONMENT_OPTIONS).map((slug) => ({slug, weight: 1})) |
45 | | -}) |
46 | | - .reduce((groups, [slug, refs]) => { |
47 | | - const group: Group = { |
48 | | - slug, |
49 | | - title: formatTitle(slug), |
50 | | - refs |
51 | | - }; |
52 | | - return [ |
53 | | - ...groups, |
54 | | - group |
55 | | - ] |
56 | | - }, [] as Group[]); |
| 22 | +const weights = { |
| 23 | + // eslint-disable-next-line @typescript-eslint/no-magic-numbers |
| 24 | + strictChecks: 3, |
| 25 | + typeCheckingBehavior: 2, |
| 26 | + controlFlowOptions: 2, |
| 27 | + interopConstraints: 2, |
| 28 | +}; |
| 29 | +export const GROUPS: Group[] = Object.entries(TS_ERROR_CODES).map( |
| 30 | + ([groupSlug, auditMap]) => ({ |
| 31 | + slug: camelCaseToKebabCase(groupSlug), |
| 32 | + title: formatTitle(groupSlug), |
| 33 | + refs: Object.keys(auditMap).map(audit => ({ |
| 34 | + slug: camelCaseToKebabCase(audit), |
| 35 | + weight: weights[audit as keyof typeof weights] ?? 1, |
| 36 | + })), |
| 37 | + }), |
| 38 | +); |
0 commit comments