1
0
Fork 0

lint: extract visit item method

This commit is contained in:
ssube 2019-11-15 18:56:08 -06:00 committed by Sean Sube
parent c053da9051
commit 6c33b81610
2 changed files with 30 additions and 24 deletions

View File

@ -20,7 +20,7 @@ export class RuleVisitor implements RuleVisitorOptions, Visitor {
} }
public async pick(ctx: VisitorContext, root: any): Promise<Array<any>> { public async pick(ctx: VisitorContext, root: any): Promise<Array<any>> {
return []; // why is this part of visitor rather than rule? return []; // TODO: why is this part of visitor rather than rule?
} }
public async visit(ctx: VisitorContext, root: any): Promise<VisitorContext> { public async visit(ctx: VisitorContext, root: any): Promise<VisitorContext> {
@ -32,13 +32,23 @@ export class RuleVisitor implements RuleVisitorOptions, Visitor {
itemIndex, itemIndex,
rule, rule,
}; };
await this.visitItem(ctx, item, itemIndex, rule);
itemIndex += 1;
}
}
return ctx;
}
public async visitItem(ctx: VisitorContext, item: any, itemIndex: number, rule: Rule): Promise<void> {
const itemResult = cloneDeep(item); const itemResult = cloneDeep(item);
const ruleResult = await rule.visit(ctx, itemResult); const ruleResult = await rule.visit(ctx, itemResult);
if (hasItems(ruleResult.errors)) { if (hasItems(ruleResult.errors)) {
ctx.logger.warn({ count: ruleResult.errors.length, rule }, 'rule failed'); ctx.logger.warn({ count: ruleResult.errors.length, rule }, 'rule failed');
ctx.mergeResult(ruleResult, ctx.visitData); ctx.mergeResult(ruleResult, ctx.visitData);
continue; return;
} }
const itemDiff = diff(item, itemResult); const itemDiff = diff(item, itemResult);
@ -55,11 +65,5 @@ export class RuleVisitor implements RuleVisitorOptions, Visitor {
} else { } else {
ctx.logger.info({ rule: rule.name }, 'rule passed'); ctx.logger.info({ rule: rule.name }, 'rule passed');
} }
itemIndex += 1;
}
}
return ctx;
} }
} }

View File

@ -81,4 +81,6 @@ describeLeaks('main app', async () => {
expect(status).to.equal(STATUS_ERROR); expect(status).to.equal(STATUS_ERROR);
}); });
it('should fix up partial documents'); // TODO: test fix mode
}); });