1
0
Fork 0

fix(visitor): remove error method from context

BREAKING CHANGE: rule errors must be grouped and returned in the rule
result, fixing #114 and keeping the context immutable.
This commit is contained in:
ssube 2019-11-02 11:09:22 -05:00 committed by Sean Sube
parent 247e1ab03d
commit 842006c34a
2 changed files with 2 additions and 12 deletions

View File

@ -1,6 +1,6 @@
import Ajv from 'ajv';
import { JSONPath } from 'jsonpath-plus';
import { Logger, logWithLevel } from 'noicejs';
import { Logger } from 'noicejs';
import { doesExist, hasItems } from '../utils';
import { VisitorError } from './VisitorError';
@ -63,14 +63,6 @@ export class VisitorContext implements VisitorContextOptions, VisitorResult {
return this.ajv.compile(schema);
}
public error(...errors: Array<VisitorError>) {
for (const err of errors) {
logWithLevel(this.logger, err.level, err.data, err.msg);
}
this.errorBuffer.push(...errors);
}
public mergeResult(other: VisitorResult): this {
this.changeBuffer.push(...other.changes);
this.errorBuffer.push(...other.errors);

View File

@ -1,6 +1,6 @@
import { expect } from 'chai';
import { ConsoleLogger } from 'noicejs';
import { mock, spy } from 'sinon';
import { mock } from 'sinon';
import { createRuleSelector, resolveRules, visitRules } from '../../src/rule';
import { SchemaRule } from '../../src/rule/SchemaRule';
@ -203,7 +203,6 @@ describeLeaks('rule visitor', async () => {
},
logger: new ConsoleLogger(),
});
const errorSpy = spy(ctx, 'error');
const data = {
foo: 3,
@ -227,6 +226,5 @@ describeLeaks('rule visitor', async () => {
const results = await rule.visit(ctx, data);
expect(results.errors.length).to.equal(0);
expect(errorSpy).to.have.callCount(0);
});
});