Skip to content

Commit db91553

Browse files
authored
fix(core): invalid then produced by Rule#toJSON (#2496)
1 parent ed6e1dc commit db91553

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ commands:
145145
steps:
146146
- checkout
147147
- cached-dependencies
148-
- run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
148+
- run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> .npmrc
149149
- build
150150

151151
jobs:

packages/core/src/ruleset/__tests__/ruleset.test.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -617,8 +617,11 @@ describe('Ruleset', () => {
617617
severity: DiagnosticSeverity.Warning,
618618
then: [
619619
{
620+
field: 'name',
620621
function: 'pattern',
621-
functionOptions: 'Object{}',
622+
functionOptions: {
623+
match: 'Stoplight',
624+
},
622625
},
623626
],
624627
},
@@ -637,8 +640,11 @@ describe('Ruleset', () => {
637640
severity: DiagnosticSeverity.Error,
638641
then: [
639642
{
643+
field: 'description',
640644
function: 'pattern',
641-
functionOptions: 'Object{}',
645+
functionOptions: {
646+
match: 'Stoplight',
647+
},
642648
},
643649
],
644650
},
@@ -657,8 +663,11 @@ describe('Ruleset', () => {
657663
severity: DiagnosticSeverity.Warning,
658664
then: [
659665
{
666+
field: 'title',
660667
function: 'pattern',
661-
functionOptions: 'Object{}',
668+
functionOptions: {
669+
match: 'Stoplight',
670+
},
662671
},
663672
],
664673
},

packages/core/src/ruleset/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ export { createRulesetFunction, SchemaDefinition as RulesetFunctionSchemaDefinit
44
export { Format } from './format';
55
export { RulesetDefinition, RuleDefinition, ParserOptions, HumanReadableDiagnosticSeverity } from './types';
66
export { Ruleset, StringifiedRuleset } from './ruleset';
7+
export { Formats } from './formats';
78
export { Rule, StringifiedRule } from './rule';

packages/core/src/ruleset/rule.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { isString } from 'lodash';
22
import { DiagnosticSeverity, JsonPath, Optional } from '@stoplight/types';
33
import { dirname, relative } from '@stoplight/path';
44
import { pathToPointer } from '@stoplight/json';
5-
import { printValue } from '@stoplight/spectral-runtime';
65

76
import { DEFAULT_SEVERITY_LEVEL, getDiagnosticSeverity } from './utils/severity';
87
import { Ruleset } from './ruleset';
@@ -29,7 +28,7 @@ export interface IRule {
2928

3029
type RuleJson = Omit<IRule, 'then'> & {
3130
name: string;
32-
then: (Pick<IRuleThen, 'field'> & { function: string; functionOptions?: string })[];
31+
then: (Omit<IRuleThen, 'function'> & { function: string })[];
3332
owner: number;
3433
};
3534

@@ -185,9 +184,8 @@ export class Rule implements IRule {
185184
resolved: this.resolved,
186185
formats: this.formats,
187186
then: this.then.map(then => ({
188-
...then.function,
187+
...then,
189188
function: then.function.name,
190-
...('functionOptions' in then ? { functionOptions: printValue(then.functionOptions) } : null),
191189
})),
192190
given: Array.isArray(this.definition.given) ? this.definition.given : [this.definition.given],
193191
owner: this.owner.id,

0 commit comments

Comments
 (0)