Make rules more type-safe

This commit is contained in:
Yury Bondarenko
2024-03-15 13:19:47 +01:00
parent b0758c23e5
commit 6e22b5376a
15 changed files with 314 additions and 158 deletions

View File

@@ -10,53 +10,42 @@ import { RuleTester } from 'eslint';
import { EnumType } from 'typescript';
export type Meta = TSESLint.RuleMetaData<string>;
export type Valid = RuleTester.ValidTestCase | TSESLint.ValidTestCase<unknown[]>;
export type Invalid = RuleTester.InvalidTestCase | TSESLint.InvalidTestCase<string, unknown[]>;
export type Valid = TSESLint.ValidTestCase<unknown[]> | RuleTester.ValidTestCase;
export type Invalid = TSESLint.InvalidTestCase<string, unknown[]> | RuleTester.InvalidTestCase;
export interface DSpaceESLintRuleInfo {
name: string;
meta: Meta,
defaultOptions: any[],
defaultOptions: unknown[],
}
export interface DSpaceESLintTestInfo {
rule: string;
export interface NamedTests {
plugin: string;
valid: Valid[];
invalid: Invalid[];
}
export interface DSpaceESLintPluginInfo {
name: string;
description: string;
rules: DSpaceESLintRuleInfo;
tests: DSpaceESLintTestInfo;
}
export interface DSpaceESLintInfo {
html: DSpaceESLintPluginInfo;
ts: DSpaceESLintPluginInfo;
}
export interface RuleExports {
Message: EnumType,
info: DSpaceESLintRuleInfo,
rule: any,
tests: any,
default: any,
rule: TSESLint.RuleModule<string>,
tests: NamedTests,
default: unknown,
}
export interface PluginExports {
name: string,
language: string,
rules: Record<string, unknown>,
index: RuleExports[],
}
export function bundle(
name: string,
language: string,
index: RuleExports[],
): {
name: string,
language: string,
rules: Record<string, any>,
index: RuleExports[],
} {
return index.reduce((o: any, i: any) => {
): PluginExports {
return index.reduce((o: PluginExports, i: RuleExports) => {
o.rules[i.info.name] = i.rule;
return o;
}, {