lint: rename context inner options to schema
This commit is contained in:
parent
02ccffda6b
commit
41ac1b5849
|
@ -33,12 +33,12 @@ export async function main(argv: Array<string>): Promise<number> {
|
||||||
}
|
}
|
||||||
|
|
||||||
const ctx = new VisitorContext({
|
const ctx = new VisitorContext({
|
||||||
innerOptions: {
|
logger,
|
||||||
|
schemaOptions: {
|
||||||
coerce: args.coerce,
|
coerce: args.coerce,
|
||||||
defaults: args.defaults,
|
defaults: args.defaults,
|
||||||
mutate: mode === MODE.fix,
|
mutate: mode === MODE.fix,
|
||||||
},
|
},
|
||||||
logger,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const ruleSelector = createRuleSelector(args);
|
const ruleSelector = createRuleSelector(args);
|
||||||
|
|
|
@ -231,7 +231,7 @@ export async function visitRules(ctx: VisitorContext, rules: Array<Rule>, data:
|
||||||
rule: rule.name,
|
rule: rule.name,
|
||||||
}, 'rule passed with modifications');
|
}, 'rule passed with modifications');
|
||||||
|
|
||||||
if (ctx.innerOptions.mutate) {
|
if (ctx.schemaOptions.mutate) {
|
||||||
applyDiff(item, itemResult);
|
applyDiff(item, itemResult);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -15,12 +15,12 @@ export interface RuleOptions {
|
||||||
|
|
||||||
export interface VisitorContextOptions {
|
export interface VisitorContextOptions {
|
||||||
logger: Logger;
|
logger: Logger;
|
||||||
innerOptions: RuleOptions;
|
schemaOptions: RuleOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class VisitorContext implements VisitorContextOptions, VisitorResult {
|
export class VisitorContext implements VisitorContextOptions, VisitorResult {
|
||||||
public readonly logger: Logger;
|
public readonly logger: Logger;
|
||||||
public readonly innerOptions: RuleOptions;
|
public readonly schemaOptions: RuleOptions;
|
||||||
|
|
||||||
protected readonly ajv: Ajv.Ajv;
|
protected readonly ajv: Ajv.Ajv;
|
||||||
protected readonly changeBuffer: Array<any>;
|
protected readonly changeBuffer: Array<any>;
|
||||||
|
@ -41,12 +41,12 @@ export class VisitorContext implements VisitorContextOptions, VisitorResult {
|
||||||
|
|
||||||
this.ajv = new Ajv({
|
this.ajv = new Ajv({
|
||||||
$data: true,
|
$data: true,
|
||||||
coerceTypes: options.innerOptions.coerce,
|
coerceTypes: options.schemaOptions.coerce,
|
||||||
useDefaults: options.innerOptions.defaults,
|
useDefaults: options.schemaOptions.defaults,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.logger = options.logger;
|
this.logger = options.logger;
|
||||||
this.innerOptions = options.innerOptions;
|
this.schemaOptions = options.schemaOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public addSchema(name: string, schema: any): void {
|
public addSchema(name: string, schema: any): void {
|
||||||
|
|
|
@ -25,12 +25,12 @@ describeLeaks('load rule file helper', async () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const ctx = new VisitorContext({
|
const ctx = new VisitorContext({
|
||||||
innerOptions: {
|
logger: NullLogger.global,
|
||||||
|
schemaOptions: {
|
||||||
coerce: false,
|
coerce: false,
|
||||||
defaults: false,
|
defaults: false,
|
||||||
mutate: false,
|
mutate: false,
|
||||||
},
|
},
|
||||||
logger: NullLogger.global,
|
|
||||||
});
|
});
|
||||||
const schemaSpy = spy(ctx, 'addSchema');
|
const schemaSpy = spy(ctx, 'addSchema');
|
||||||
|
|
||||||
|
@ -50,12 +50,12 @@ describeLeaks('load rule file helper', async () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const ctx = new VisitorContext({
|
const ctx = new VisitorContext({
|
||||||
innerOptions: {
|
logger: NullLogger.global,
|
||||||
|
schemaOptions: {
|
||||||
coerce: false,
|
coerce: false,
|
||||||
defaults: false,
|
defaults: false,
|
||||||
mutate: false,
|
mutate: false,
|
||||||
},
|
},
|
||||||
logger: NullLogger.global,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const rules = await loadRuleFiles([
|
const rules = await loadRuleFiles([
|
||||||
|
@ -78,12 +78,12 @@ describeLeaks('load rule path helper', async () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const ctx = new VisitorContext({
|
const ctx = new VisitorContext({
|
||||||
innerOptions: {
|
logger: NullLogger.global,
|
||||||
|
schemaOptions: {
|
||||||
coerce: false,
|
coerce: false,
|
||||||
defaults: false,
|
defaults: false,
|
||||||
mutate: false,
|
mutate: false,
|
||||||
},
|
},
|
||||||
logger: NullLogger.global,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const rules = await loadRulePaths([
|
const rules = await loadRulePaths([
|
||||||
|
@ -109,12 +109,12 @@ describeLeaks('load rule path helper', async () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const ctx = new VisitorContext({
|
const ctx = new VisitorContext({
|
||||||
innerOptions: {
|
logger: NullLogger.global,
|
||||||
|
schemaOptions: {
|
||||||
coerce: false,
|
coerce: false,
|
||||||
defaults: false,
|
defaults: false,
|
||||||
mutate: false,
|
mutate: false,
|
||||||
},
|
},
|
||||||
logger: NullLogger.global,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const rules = await loadRulePaths([
|
const rules = await loadRulePaths([
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import { ConsoleLogger, LogLevel } from 'noicejs';
|
import { LogLevel, NullLogger } from 'noicejs';
|
||||||
import { mock, spy, stub } from 'sinon';
|
import { mock, spy, stub } from 'sinon';
|
||||||
|
|
||||||
import { createRuleSelector, createRuleSources, resolveRules, visitRules } from '../../src/rule';
|
import { createRuleSelector, createRuleSources, resolveRules, visitRules } from '../../src/rule';
|
||||||
|
@ -104,12 +104,12 @@ describeLeaks('rule resolver', async () => {
|
||||||
describeLeaks('rule visitor', async () => {
|
describeLeaks('rule visitor', async () => {
|
||||||
itLeaks('should only call visit for selected items', async () => {
|
itLeaks('should only call visit for selected items', async () => {
|
||||||
const ctx = new VisitorContext({
|
const ctx = new VisitorContext({
|
||||||
innerOptions: {
|
logger: NullLogger.global,
|
||||||
|
schemaOptions: {
|
||||||
coerce: false,
|
coerce: false,
|
||||||
defaults: false,
|
defaults: false,
|
||||||
mutate: false,
|
mutate: false,
|
||||||
},
|
},
|
||||||
logger: new ConsoleLogger(),
|
|
||||||
});
|
});
|
||||||
const data = {};
|
const data = {};
|
||||||
const rule = new SchemaRule({
|
const rule = new SchemaRule({
|
||||||
|
@ -136,12 +136,12 @@ describeLeaks('rule visitor', async () => {
|
||||||
|
|
||||||
itLeaks('should call visit for each selected item', async () => {
|
itLeaks('should call visit for each selected item', async () => {
|
||||||
const ctx = new VisitorContext({
|
const ctx = new VisitorContext({
|
||||||
innerOptions: {
|
logger: NullLogger.global,
|
||||||
|
schemaOptions: {
|
||||||
coerce: false,
|
coerce: false,
|
||||||
defaults: false,
|
defaults: false,
|
||||||
mutate: false,
|
mutate: false,
|
||||||
},
|
},
|
||||||
logger: new ConsoleLogger(),
|
|
||||||
});
|
});
|
||||||
const data = {};
|
const data = {};
|
||||||
const rule = new SchemaRule({
|
const rule = new SchemaRule({
|
||||||
|
@ -171,12 +171,12 @@ describeLeaks('rule visitor', async () => {
|
||||||
|
|
||||||
itLeaks('should visit individual items', async () => {
|
itLeaks('should visit individual items', async () => {
|
||||||
const ctx = new VisitorContext({
|
const ctx = new VisitorContext({
|
||||||
innerOptions: {
|
logger: NullLogger.global,
|
||||||
|
schemaOptions: {
|
||||||
coerce: false,
|
coerce: false,
|
||||||
defaults: false,
|
defaults: false,
|
||||||
mutate: false,
|
mutate: false,
|
||||||
},
|
},
|
||||||
logger: new ConsoleLogger(),
|
|
||||||
});
|
});
|
||||||
const data = {
|
const data = {
|
||||||
foo: [1, 2, 3],
|
foo: [1, 2, 3],
|
||||||
|
@ -204,12 +204,12 @@ describeLeaks('rule visitor', async () => {
|
||||||
|
|
||||||
itLeaks('should visit individual items', async () => {
|
itLeaks('should visit individual items', async () => {
|
||||||
const ctx = new VisitorContext({
|
const ctx = new VisitorContext({
|
||||||
innerOptions: {
|
logger: NullLogger.global,
|
||||||
|
schemaOptions: {
|
||||||
coerce: false,
|
coerce: false,
|
||||||
defaults: false,
|
defaults: false,
|
||||||
mutate: false,
|
mutate: false,
|
||||||
},
|
},
|
||||||
logger: new ConsoleLogger(),
|
|
||||||
});
|
});
|
||||||
const data = {
|
const data = {
|
||||||
foo: [1, 2, 3],
|
foo: [1, 2, 3],
|
||||||
|
|
|
@ -13,12 +13,12 @@ const TEST_NAME = 'test-rule';
|
||||||
describeLeaks('schema rule', async () => {
|
describeLeaks('schema rule', async () => {
|
||||||
itLeaks('should pick items from the scope', async () => {
|
itLeaks('should pick items from the scope', async () => {
|
||||||
const ctx = new VisitorContext({
|
const ctx = new VisitorContext({
|
||||||
innerOptions: {
|
logger: NullLogger.global,
|
||||||
|
schemaOptions: {
|
||||||
coerce: false,
|
coerce: false,
|
||||||
defaults: false,
|
defaults: false,
|
||||||
mutate: false,
|
mutate: false,
|
||||||
},
|
},
|
||||||
logger: NullLogger.global,
|
|
||||||
});
|
});
|
||||||
const data = {
|
const data = {
|
||||||
foo: 3,
|
foo: 3,
|
||||||
|
@ -38,12 +38,12 @@ describeLeaks('schema rule', async () => {
|
||||||
|
|
||||||
itLeaks('should filter out items', async () => {
|
itLeaks('should filter out items', async () => {
|
||||||
const ctx = new VisitorContext({
|
const ctx = new VisitorContext({
|
||||||
innerOptions: {
|
logger: NullLogger.global,
|
||||||
|
schemaOptions: {
|
||||||
coerce: false,
|
coerce: false,
|
||||||
defaults: false,
|
defaults: false,
|
||||||
mutate: false,
|
mutate: false,
|
||||||
},
|
},
|
||||||
logger: NullLogger.global,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
|
@ -72,12 +72,12 @@ describeLeaks('schema rule', async () => {
|
||||||
|
|
||||||
itLeaks('should pick items from the root', async () => {
|
itLeaks('should pick items from the root', async () => {
|
||||||
const ctx = new VisitorContext({
|
const ctx = new VisitorContext({
|
||||||
innerOptions: {
|
logger: NullLogger.global,
|
||||||
|
schemaOptions: {
|
||||||
coerce: false,
|
coerce: false,
|
||||||
defaults: false,
|
defaults: false,
|
||||||
mutate: false,
|
mutate: false,
|
||||||
},
|
},
|
||||||
logger: NullLogger.global,
|
|
||||||
});
|
});
|
||||||
const rule = new SchemaRule({
|
const rule = new SchemaRule({
|
||||||
check: undefined,
|
check: undefined,
|
||||||
|
@ -95,12 +95,12 @@ describeLeaks('schema rule', async () => {
|
||||||
|
|
||||||
itLeaks('should visit selected items', async () => {
|
itLeaks('should visit selected items', async () => {
|
||||||
const ctx = new VisitorContext({
|
const ctx = new VisitorContext({
|
||||||
innerOptions: {
|
logger: NullLogger.global,
|
||||||
|
schemaOptions: {
|
||||||
coerce: false,
|
coerce: false,
|
||||||
defaults: false,
|
defaults: false,
|
||||||
mutate: false,
|
mutate: false,
|
||||||
},
|
},
|
||||||
logger: NullLogger.global,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const check = {};
|
const check = {};
|
||||||
|
@ -128,12 +128,12 @@ describeLeaks('schema rule', async () => {
|
||||||
|
|
||||||
itLeaks('should skip filtered items', async () => {
|
itLeaks('should skip filtered items', async () => {
|
||||||
const ctx = new VisitorContext({
|
const ctx = new VisitorContext({
|
||||||
innerOptions: {
|
logger: NullLogger.global,
|
||||||
|
schemaOptions: {
|
||||||
coerce: false,
|
coerce: false,
|
||||||
defaults: false,
|
defaults: false,
|
||||||
mutate: false,
|
mutate: false,
|
||||||
},
|
},
|
||||||
logger: NullLogger.global,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const checkSpy = stub().throws(new Error('check spy error'));
|
const checkSpy = stub().throws(new Error('check spy error'));
|
||||||
|
@ -169,12 +169,12 @@ describe('friendly errors', () => {
|
||||||
tags: [TEST_NAME],
|
tags: [TEST_NAME],
|
||||||
});
|
});
|
||||||
const ctx = new VisitorContext({
|
const ctx = new VisitorContext({
|
||||||
innerOptions: {
|
logger: NullLogger.global,
|
||||||
|
schemaOptions: {
|
||||||
coerce: false,
|
coerce: false,
|
||||||
defaults: false,
|
defaults: false,
|
||||||
mutate: false,
|
mutate: false,
|
||||||
},
|
},
|
||||||
logger: NullLogger.global,
|
|
||||||
});
|
});
|
||||||
ctx.visitData = {
|
ctx.visitData = {
|
||||||
itemIndex: 0,
|
itemIndex: 0,
|
||||||
|
@ -200,12 +200,12 @@ describe('friendly errors', () => {
|
||||||
tags: [TEST_NAME],
|
tags: [TEST_NAME],
|
||||||
});
|
});
|
||||||
const ctx = new VisitorContext({
|
const ctx = new VisitorContext({
|
||||||
innerOptions: {
|
logger: NullLogger.global,
|
||||||
|
schemaOptions: {
|
||||||
coerce: false,
|
coerce: false,
|
||||||
defaults: false,
|
defaults: false,
|
||||||
mutate: false,
|
mutate: false,
|
||||||
},
|
},
|
||||||
logger: NullLogger.global,
|
|
||||||
});
|
});
|
||||||
ctx.visitData = {
|
ctx.visitData = {
|
||||||
itemIndex: 0,
|
itemIndex: 0,
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import { ConsoleLogger, LogLevel } from 'noicejs';
|
import { LogLevel, NullLogger } from 'noicejs';
|
||||||
|
|
||||||
import { VisitorContext } from '../../src/visitor/VisitorContext';
|
import { VisitorContext } from '../../src/visitor/VisitorContext';
|
||||||
|
|
||||||
describe('visitor context', () => {
|
describe('visitor context', () => {
|
||||||
it('should merge results', () => {
|
it('should merge results', () => {
|
||||||
const firstCtx = new VisitorContext({
|
const firstCtx = new VisitorContext({
|
||||||
innerOptions: {
|
logger: NullLogger.global,
|
||||||
|
schemaOptions: {
|
||||||
coerce: false,
|
coerce: false,
|
||||||
defaults: false,
|
defaults: false,
|
||||||
mutate: false,
|
mutate: false,
|
||||||
},
|
},
|
||||||
logger: new ConsoleLogger(),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const nextCtx = firstCtx.mergeResult({
|
const nextCtx = firstCtx.mergeResult({
|
||||||
|
|
Loading…
Reference in New Issue