1
0
Fork 0

fix(rules): remove redundant rule field from result

the value of the rule field is always this and it is unused by the
visitor.
This commit is contained in:
ssube 2019-11-02 10:26:22 -05:00 committed by Sean Sube
parent a2a0fb4423
commit b5d4698e5a
2 changed files with 4 additions and 9 deletions

View File

@ -10,11 +10,7 @@ import { VisitorContext } from '../visitor/VisitorContext';
import { VisitorError } from '../visitor/VisitorError';
import { VisitorResult } from '../visitor/VisitorResult';
export interface RuleResult extends VisitorResult {
rule: SchemaRule;
}
export class SchemaRule implements RuleData, Visitor<RuleResult> {
export class SchemaRule implements RuleData, Visitor {
public readonly check: ValidateFunction;
public readonly desc: string;
public readonly filter?: ValidateFunction;
@ -47,16 +43,15 @@ export class SchemaRule implements RuleData, Visitor<RuleResult> {
return items;
}
public async visit(ctx: VisitorContext, node: any): Promise<RuleResult> {
public async visit(ctx: VisitorContext, node: any): Promise<VisitorResult> {
ctx.logger.debug({ item: node, rule: this }, 'visiting node');
const check = ctx.compile(this.check);
const filter = this.compileFilter(ctx);
const errors: Array<VisitorError> = [];
const result: RuleResult = {
const result: VisitorResult = {
changes: [],
errors,
rule: this,
};
if (filter(node)) {

View File

@ -1,7 +1,7 @@
import { VisitorContext } from './VisitorContext';
import { VisitorResult } from './VisitorResult';
export interface Visitor<TResult extends VisitorResult> {
export interface Visitor<TResult extends VisitorResult = VisitorResult> {
/**
* Select nodes eligible to be visited.
**/