1
0
Fork 0

fix most of the tests

This commit is contained in:
Sean Sube 2022-02-13 14:13:29 -06:00
parent 299f16b9ba
commit c9af9857f4
4 changed files with 9 additions and 11 deletions

View File

@ -73,7 +73,6 @@ export async function loadConfig(name: string, ...extras: Array<string>): Promis
path: p,
});
/* eslint-disable-next-line sonarjs/prefer-immediate-return,@typescript-eslint/no-explicit-any */
return head.data as ConfigData; // TODO: validate config
}
}

View File

@ -11,8 +11,6 @@ import { Rule, RuleData, RuleError, RuleResult, ValidatorResult } from './index.
/* eslint-disable-next-line @typescript-eslint/unbound-method */
const { cloneDeep, defaultTo } = lodash;
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/strict-boolean-expressions */
const DEFAULT_FILTER = () => true;
export class SchemaRule implements Rule, RuleData {
@ -115,6 +113,7 @@ export class SchemaRule implements Rule, RuleData {
if (doesExist(this.filterSchema)) {
return ctx.compile(this.filterSchema);
} else {
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
return DEFAULT_FILTER as any;
}
}

View File

@ -6,8 +6,6 @@ import { Logger } from 'noicejs';
import { RuleChange, RuleError, RuleResult } from '../rule/index.js';
import { Document, Element } from '../source.js';
/* eslint-disable @typescript-eslint/no-explicit-any */
export interface RuleOptions {
coerce: boolean;
defaults: boolean;
@ -26,7 +24,6 @@ export class VisitorContext implements VisitorContextOptions, RuleResult {
protected readonly ajv: Ajv;
protected readonly changeBuffer: Array<RuleChange>;
protected readonly errorBuffer: Array<RuleError>;
protected data: any;
public get changes(): ReadonlyArray<RuleChange> {
return this.changeBuffer;
@ -50,7 +47,7 @@ export class VisitorContext implements VisitorContextOptions, RuleResult {
this.schemaOptions = options.schemaOptions;
}
public addSchema(name: string, schema: any): void {
public addSchema(name: string, schema: object): void {
this.logger.debug({
schema,
schemaName: name,
@ -67,8 +64,9 @@ export class VisitorContext implements VisitorContextOptions, RuleResult {
}
/**
* @todo should take the element
* @todo what is data? should use the element
*/
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
public mergeResult(other: RuleResult, data: any = {}): this {
this.changeBuffer.push(...other.changes);
this.errorBuffer.push(...other.errors.map((err) => ({
@ -86,6 +84,7 @@ export class VisitorContext implements VisitorContextOptions, RuleResult {
*/
public pick(path: string, root: Document): Array<Element> {
const items = JSONPath({
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
json: root.data as any,
path,
});

View File

@ -53,6 +53,7 @@ describe('rule visitor', async () => {
},
});
const data = {};
const doc = makeDocument({});
const rule = new SchemaRule({
check: {},
desc: '',
@ -64,7 +65,7 @@ describe('rule visitor', async () => {
const mockRule = mock(rule);
const pickStub = mockRule.expects('pick').once().withArgs(ctx, data);
const pickStub = mockRule.expects('pick').once().withArgs(ctx, doc);
pickStub.onFirstCall().returns(Promise.resolve([data]));
pickStub.throws();
@ -75,7 +76,7 @@ describe('rule visitor', async () => {
const visitor = new RuleVisitor({
rules: [rule],
});
await visitor.visit(ctx, rule, makeElement({}));
await visitor.visitAll(ctx, rule, doc);
mockRule.verify();
expect(ctx.errors.length).to.equal(0);
@ -155,7 +156,7 @@ describe('rule visitor', async () => {
const visitor = new RuleVisitor({
rules: [rule],
});
await visitor.visit(ctx, rule, makeElement(data));
await visitor.visitAll(ctx, rule, makeDocument(data));
const EXPECTED_VISITS = 3;
expect(visitStub).to.have.callCount(EXPECTED_VISITS);