diff --git a/src/app.ts b/src/app.ts index c609457..cb0420a 100644 --- a/src/app.ts +++ b/src/app.ts @@ -33,12 +33,12 @@ export async function main(argv: Array): Promise { } const ctx = new VisitorContext({ - innerOptions: { + logger, + schemaOptions: { coerce: args.coerce, defaults: args.defaults, mutate: mode === MODE.fix, }, - logger, }); const ruleSelector = createRuleSelector(args); diff --git a/src/rule/index.ts b/src/rule/index.ts index 41622ed..4a9ccc3 100644 --- a/src/rule/index.ts +++ b/src/rule/index.ts @@ -231,7 +231,7 @@ export async function visitRules(ctx: VisitorContext, rules: Array, data: rule: rule.name, }, 'rule passed with modifications'); - if (ctx.innerOptions.mutate) { + if (ctx.schemaOptions.mutate) { applyDiff(item, itemResult); } } else { diff --git a/src/visitor/VisitorContext.ts b/src/visitor/VisitorContext.ts index 93a7bc1..2231afb 100644 --- a/src/visitor/VisitorContext.ts +++ b/src/visitor/VisitorContext.ts @@ -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; @@ -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 { diff --git a/test/rule/TestLoadRule.ts b/test/rule/TestLoadRule.ts index 046a2ba..b632572 100644 --- a/test/rule/TestLoadRule.ts +++ b/test/rule/TestLoadRule.ts @@ -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([ diff --git a/test/rule/TestRule.ts b/test/rule/TestRule.ts index 8873f14..ad431a6 100644 --- a/test/rule/TestRule.ts +++ b/test/rule/TestRule.ts @@ -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], diff --git a/test/rule/TestSchemaRule.ts b/test/rule/TestSchemaRule.ts index 2f540c4..01b91c3 100644 --- a/test/rule/TestSchemaRule.ts +++ b/test/rule/TestSchemaRule.ts @@ -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, diff --git a/test/visitor/TestContext.ts b/test/visitor/TestContext.ts index 1d56978..a30adf3 100644 --- a/test/visitor/TestContext.ts +++ b/test/visitor/TestContext.ts @@ -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({