1
0
Fork 0

lint: rename context inner options to schema

This commit is contained in:
ssube 2019-11-12 08:25:09 -06:00
parent 02ccffda6b
commit 41ac1b5849
Signed by: ssube
GPG Key ID: 3EED7B957D362AF1
7 changed files with 42 additions and 42 deletions

View File

@ -33,12 +33,12 @@ export async function main(argv: Array<string>): Promise<number> {
}
const ctx = new VisitorContext({
innerOptions: {
logger,
schemaOptions: {
coerce: args.coerce,
defaults: args.defaults,
mutate: mode === MODE.fix,
},
logger,
});
const ruleSelector = createRuleSelector(args);

View File

@ -231,7 +231,7 @@ export async function visitRules(ctx: VisitorContext, rules: Array<Rule>, data:
rule: rule.name,
}, 'rule passed with modifications');
if (ctx.innerOptions.mutate) {
if (ctx.schemaOptions.mutate) {
applyDiff(item, itemResult);
}
} else {

View File

@ -15,12 +15,12 @@ export interface RuleOptions {
export interface VisitorContextOptions {
logger: Logger;
innerOptions: RuleOptions;
schemaOptions: RuleOptions;
}
export class VisitorContext implements VisitorContextOptions, VisitorResult {
public readonly logger: Logger;
public readonly innerOptions: RuleOptions;
public readonly schemaOptions: RuleOptions;
protected readonly ajv: Ajv.Ajv;
protected readonly changeBuffer: Array<any>;
@ -41,12 +41,12 @@ export class VisitorContext implements VisitorContextOptions, VisitorResult {
this.ajv = new Ajv({
$data: true,
coerceTypes: options.innerOptions.coerce,
useDefaults: options.innerOptions.defaults,
coerceTypes: options.schemaOptions.coerce,
useDefaults: options.schemaOptions.defaults,
});
this.logger = options.logger;
this.innerOptions = options.innerOptions;
this.schemaOptions = options.schemaOptions;
}
public addSchema(name: string, schema: any): void {

View File

@ -25,12 +25,12 @@ describeLeaks('load rule file helper', async () => {
});
const ctx = new VisitorContext({
innerOptions: {
logger: NullLogger.global,
schemaOptions: {
coerce: false,
defaults: false,
mutate: false,
},
logger: NullLogger.global,
});
const schemaSpy = spy(ctx, 'addSchema');
@ -50,12 +50,12 @@ describeLeaks('load rule file helper', async () => {
});
const ctx = new VisitorContext({
innerOptions: {
logger: NullLogger.global,
schemaOptions: {
coerce: false,
defaults: false,
mutate: false,
},
logger: NullLogger.global,
});
const rules = await loadRuleFiles([
@ -78,12 +78,12 @@ describeLeaks('load rule path helper', async () => {
});
const ctx = new VisitorContext({
innerOptions: {
logger: NullLogger.global,
schemaOptions: {
coerce: false,
defaults: false,
mutate: false,
},
logger: NullLogger.global,
});
const rules = await loadRulePaths([
@ -109,12 +109,12 @@ describeLeaks('load rule path helper', async () => {
});
const ctx = new VisitorContext({
innerOptions: {
logger: NullLogger.global,
schemaOptions: {
coerce: false,
defaults: false,
mutate: false,
},
logger: NullLogger.global,
});
const rules = await loadRulePaths([

View File

@ -1,5 +1,5 @@
import { expect } from 'chai';
import { ConsoleLogger, LogLevel } from 'noicejs';
import { LogLevel, NullLogger } from 'noicejs';
import { mock, spy, stub } from 'sinon';
import { createRuleSelector, createRuleSources, resolveRules, visitRules } from '../../src/rule';
@ -104,12 +104,12 @@ describeLeaks('rule resolver', async () => {
describeLeaks('rule visitor', async () => {
itLeaks('should only call visit for selected items', async () => {
const ctx = new VisitorContext({
innerOptions: {
logger: NullLogger.global,
schemaOptions: {
coerce: false,
defaults: false,
mutate: false,
},
logger: new ConsoleLogger(),
});
const data = {};
const rule = new SchemaRule({
@ -136,12 +136,12 @@ describeLeaks('rule visitor', async () => {
itLeaks('should call visit for each selected item', async () => {
const ctx = new VisitorContext({
innerOptions: {
logger: NullLogger.global,
schemaOptions: {
coerce: false,
defaults: false,
mutate: false,
},
logger: new ConsoleLogger(),
});
const data = {};
const rule = new SchemaRule({
@ -171,12 +171,12 @@ describeLeaks('rule visitor', async () => {
itLeaks('should visit individual items', async () => {
const ctx = new VisitorContext({
innerOptions: {
logger: NullLogger.global,
schemaOptions: {
coerce: false,
defaults: false,
mutate: false,
},
logger: new ConsoleLogger(),
});
const data = {
foo: [1, 2, 3],
@ -204,12 +204,12 @@ describeLeaks('rule visitor', async () => {
itLeaks('should visit individual items', async () => {
const ctx = new VisitorContext({
innerOptions: {
logger: NullLogger.global,
schemaOptions: {
coerce: false,
defaults: false,
mutate: false,
},
logger: new ConsoleLogger(),
});
const data = {
foo: [1, 2, 3],

View File

@ -13,12 +13,12 @@ const TEST_NAME = 'test-rule';
describeLeaks('schema rule', async () => {
itLeaks('should pick items from the scope', async () => {
const ctx = new VisitorContext({
innerOptions: {
logger: NullLogger.global,
schemaOptions: {
coerce: false,
defaults: false,
mutate: false,
},
logger: NullLogger.global,
});
const data = {
foo: 3,
@ -38,12 +38,12 @@ describeLeaks('schema rule', async () => {
itLeaks('should filter out items', async () => {
const ctx = new VisitorContext({
innerOptions: {
logger: NullLogger.global,
schemaOptions: {
coerce: false,
defaults: false,
mutate: false,
},
logger: NullLogger.global,
});
const data = {
@ -72,12 +72,12 @@ describeLeaks('schema rule', async () => {
itLeaks('should pick items from the root', async () => {
const ctx = new VisitorContext({
innerOptions: {
logger: NullLogger.global,
schemaOptions: {
coerce: false,
defaults: false,
mutate: false,
},
logger: NullLogger.global,
});
const rule = new SchemaRule({
check: undefined,
@ -95,12 +95,12 @@ describeLeaks('schema rule', async () => {
itLeaks('should visit selected items', async () => {
const ctx = new VisitorContext({
innerOptions: {
logger: NullLogger.global,
schemaOptions: {
coerce: false,
defaults: false,
mutate: false,
},
logger: NullLogger.global,
});
const check = {};
@ -128,12 +128,12 @@ describeLeaks('schema rule', async () => {
itLeaks('should skip filtered items', async () => {
const ctx = new VisitorContext({
innerOptions: {
logger: NullLogger.global,
schemaOptions: {
coerce: false,
defaults: false,
mutate: false,
},
logger: NullLogger.global,
});
const checkSpy = stub().throws(new Error('check spy error'));
@ -169,12 +169,12 @@ describe('friendly errors', () => {
tags: [TEST_NAME],
});
const ctx = new VisitorContext({
innerOptions: {
logger: NullLogger.global,
schemaOptions: {
coerce: false,
defaults: false,
mutate: false,
},
logger: NullLogger.global,
});
ctx.visitData = {
itemIndex: 0,
@ -200,12 +200,12 @@ describe('friendly errors', () => {
tags: [TEST_NAME],
});
const ctx = new VisitorContext({
innerOptions: {
logger: NullLogger.global,
schemaOptions: {
coerce: false,
defaults: false,
mutate: false,
},
logger: NullLogger.global,
});
ctx.visitData = {
itemIndex: 0,

View File

@ -1,17 +1,17 @@
import { expect } from 'chai';
import { ConsoleLogger, LogLevel } from 'noicejs';
import { LogLevel, NullLogger } from 'noicejs';
import { VisitorContext } from '../../src/visitor/VisitorContext';
describe('visitor context', () => {
it('should merge results', () => {
const firstCtx = new VisitorContext({
innerOptions: {
logger: NullLogger.global,
schemaOptions: {
coerce: false,
defaults: false,
mutate: false,
},
logger: new ConsoleLogger(),
});
const nextCtx = firstCtx.mergeResult({