Commit 6f0213da authored by David Sveningsson's avatar David Sveningsson
Browse files

fix(plugin): fix rule type definition

parent 9802dea5
......@@ -29,7 +29,7 @@ export class Engine<T extends Parser = Parser> {
protected report: Reporter;
protected config: Config;
protected ParserClass: new (config: Config) => T;
protected availableRules: { [key: string]: RuleConstructor };
protected availableRules: { [key: string]: RuleConstructor<any, any> };
public constructor(config: Config, ParserClass: new (config: Config) => T) {
this.report = new Reporter();
......@@ -309,7 +309,7 @@ export class Engine<T extends Parser = Parser> {
protected initPlugins(
config: Config
): {
availableRules: { [key: string]: RuleConstructor };
availableRules: { [key: string]: RuleConstructor<any, any> };
} {
for (const plugin of config.getPlugins()) {
if (plugin.init) {
......@@ -326,8 +326,10 @@ export class Engine<T extends Parser = Parser> {
* Initializes all rules from plugins and returns an object with a mapping
* between rule name and its constructor.
*/
protected initRules(config: Config): { [key: string]: RuleConstructor } {
const availableRules: { [key: string]: RuleConstructor } = {};
protected initRules(
config: Config
): { [key: string]: RuleConstructor<any, any> } {
const availableRules: { [key: string]: RuleConstructor<any, any> } = {};
for (const plugin of config.getPlugins()) {
for (const [name, rule] of Object.entries(plugin.rules || {})) {
availableRules[name] = rule;
......
......@@ -10,7 +10,7 @@ it("should compute correct line, column and offset when using transformed source
expect.assertions(2);
/* create a mock rule which reports error on root element */
class MockRule extends Rule {
class MockRule extends Rule<string, void> {
public setup(): void {
this.on("dom:ready", (event: DOMReadyEvent) => {
const root = event.document.root;
......
......@@ -56,7 +56,7 @@ export interface Plugin {
/**
* List of new rules present.
*/
rules?: Record<string, RuleConstructor>;
rules?: Record<string, RuleConstructor<any, any>>;
/**
* Transformer available in this plugin.
......
......@@ -25,7 +25,7 @@ export interface RuleDocumentation {
url?: string;
}
export type RuleConstructor = new (options?: any) => Rule;
export type RuleConstructor<T, U> = new (options?: any) => Rule<T, U>;
export abstract class Rule<ContextType = void, OptionsType = void> {
private reporter: Reporter;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment