Skip to content

Commit

Permalink
Merge branch 'develop' into docs/vale-review
Browse files Browse the repository at this point in the history
  • Loading branch information
heitortsergent authored Dec 13, 2022
2 parents bf4d033 + 2cd1ac0 commit 095adcf
Show file tree
Hide file tree
Showing 18 changed files with 139 additions and 12 deletions.
7 changes: 7 additions & 0 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# [@stoplight/spectral-core-v1.16.0](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-core-v1.15.2...@stoplight/spectral-core-v1.16.0) (2022-11-30)


### Features

* **core:** support end-user extensions in the rule definitions ([#2345](https://github.com/stoplightio/spectral/issues/2345)) ([365fced](https://github.com/stoplightio/spectral/commit/365fcedb7c140946767ed28a92a120b3adb08e47))

# [@stoplight/spectral-core-v1.15.2](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-core-v1.15.1...@stoplight/spectral-core-v1.15.2) (2022-11-22)


Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stoplight/spectral-core",
"version": "1.15.2",
"version": "1.16.0",
"sideEffects": false,
"homepage": "https://github.com/stoplightio/spectral",
"bugs": "https://github.com/stoplightio/spectral/issues",
Expand Down
45 changes: 45 additions & 0 deletions packages/core/src/__tests__/linter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1637,4 +1637,49 @@ responses:: !!foo
}),
]);
});

test.concurrent('should handle direct circular file $refs', async () => {
const spectral = new Spectral();
spectral.setRuleset({
rules: {
'valid-type': {
given: '$..type',
then: {
function() {
return [
{
message: 'Restricted type',
},
];
},
},
},
},
});

const documentUri = path.join(__dirname, './__fixtures__/test.json');
const document = new Document(
JSON.stringify({
oneOf: [
{
type: 'number',
},
{
$ref: './test.json',
},
],
}),
Parsers.Json,
documentUri,
);
const results = spectral.run(document);

await expect(results).resolves.toEqual([
expect.objectContaining({
code: 'valid-type',
path: ['oneOf', '0', 'type'],
severity: DiagnosticSeverity.Warning,
}),
]);
});
});
32 changes: 32 additions & 0 deletions packages/core/src/ruleset/__tests__/ruleset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ describe('Ruleset', () => {
description: null,
documentationUrl: null,
enabled: true,
extensions: null,
formats: null,
given: ['$'],
message: null,
Expand Down Expand Up @@ -322,6 +323,30 @@ describe('Ruleset', () => {
`);
});

it('should respect extensions', async () => {
const ruleset = {
rules: {
'foo-rule': {
given: '$',
then: {
function() {
return;
},
},
extensions: {
foo: 'bar',
},
},
},
};

const rulesetInstance = new Ruleset(ruleset);

expect(rulesetInstance.rules['foo-rule'].extensions).toEqual({
foo: 'bar',
});
});

it('should include parserOptions', async () => {
const { parserOptions } = await loadRuleset(import('./__fixtures__/parser-options-ruleset'));

Expand Down Expand Up @@ -581,6 +606,7 @@ describe('Ruleset', () => {
description: null,
documentationUrl: null,
enabled: false,
extensions: null,
formats: null,
given: ['$.info.contact'],
message: 'Contact name must contain Stoplight',
Expand All @@ -600,6 +626,7 @@ describe('Ruleset', () => {
description: null,
documentationUrl: null,
enabled: true,
extensions: null,
formats: null,
given: ['$.info'],
message: 'Description must contain Stoplight',
Expand All @@ -619,6 +646,7 @@ describe('Ruleset', () => {
description: null,
documentationUrl: null,
enabled: true,
extensions: null,
formats: null,
given: ['$.info'],
message: 'Title must contain Stoplight',
Expand Down Expand Up @@ -1144,6 +1172,7 @@ describe('Ruleset', () => {
description: null,
documentationUrl: null,
enabled: true,
extensions: null,
formats: null,
given: ['#PathItem'],
message: null,
Expand All @@ -1163,6 +1192,7 @@ describe('Ruleset', () => {
description: null,
documentationUrl: null,
enabled: true,
extensions: null,
formats: null,
given: ['#Name', '#Description'],
message: null,
Expand All @@ -1182,6 +1212,7 @@ describe('Ruleset', () => {
description: null,
documentationUrl: null,
enabled: true,
extensions: null,
formats: null,
given: ['#Info.contact'],
message: null,
Expand Down Expand Up @@ -1606,6 +1637,7 @@ describe('Ruleset', () => {
description: null,
documentationUrl: null,
enabled: true,
extensions: null,
formats: null,
given: ['#Id'],
message: null,
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/ruleset/meta/rule.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@
"enum": ["style", "validation"],
"type": "string",
"errorMessage": "allowed types are \"style\" and \"validation\""
},
"extensions": {
"type": "object"
}
},
"required": ["given", "then"],
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/ruleset/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface IRule {
documentationUrl: string | null;
then: IRuleThen[];
given: string[];
extensions: Record<string, unknown> | null;
}

type RuleJson = Omit<IRule, 'then'> & {
Expand All @@ -43,6 +44,7 @@ export class Rule implements IRule {
#enabled: boolean;
public recommended: boolean;
public documentationUrl: string | null;
public extensions: Record<string, unknown> | null;
#then!: IRuleThen[];
#given!: string[];

Expand All @@ -61,6 +63,7 @@ export class Rule implements IRule {
this.formats = 'formats' in definition ? new Formats(definition.formats) : null;
this.then = definition.then;
this.given = definition.given;
this.extensions = definition.extensions ?? null;
}

public overrides?: { rulesetSource: string; definition: Map<string, Map<string, DiagnosticSeverity | -1>> };
Expand Down Expand Up @@ -188,6 +191,7 @@ export class Rule implements IRule {
})),
given: Array.isArray(this.definition.given) ? this.definition.given : [this.definition.given],
owner: this.owner.id,
extensions: this.extensions,
};
}
}
3 changes: 3 additions & 0 deletions packages/core/src/ruleset/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ export type RuleDefinition = {
resolved?: boolean;

then: IRuleThen | IRuleThen[];

// User extensions/metadata point
extensions?: Record<string, unknown>;
};

export interface IRuleThen {
Expand Down
7 changes: 7 additions & 0 deletions packages/functions/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# [@stoplight/spectral-functions-v1.7.2](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-functions-v1.7.1...@stoplight/spectral-functions-v1.7.2) (2022-12-13)


### Bug Fixes

* **rulesets:** length.min said "must not be longer than" ([#2355](https://github.com/stoplightio/spectral/issues/2355)) ([df3b6f9](https://github.com/stoplightio/spectral/commit/df3b6f917cf46456f698445ed67fabbb4306eb4c))

# [@stoplight/spectral-functions-v1.7.1](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-functions-v1.7.0...@stoplight/spectral-functions-v1.7.1) (2022-08-22)


Expand Down
2 changes: 1 addition & 1 deletion packages/functions/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stoplight/spectral-functions",
"version": "1.7.1",
"version": "1.7.2",
"sideEffects": false,
"homepage": "https://github.com/stoplightio/spectral",
"bugs": "https://github.com/stoplightio/spectral/issues",
Expand Down
2 changes: 1 addition & 1 deletion packages/functions/src/__tests__/length.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('Core Functions / Length', () => {
async input => {
expect(await runLength(input, { min: 4 })).toEqual([
{
message: 'The document must not be longer than 4',
message: 'The document must be longer than 4',
path: [],
},
]);
Expand Down
2 changes: 1 addition & 1 deletion packages/functions/src/length.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default createRulesetFunction<unknown[] | Record<string, unknown> | strin
if ('min' in opts && value < opts.min) {
results = [
{
message: `#{{print("property")}}must not be longer than ${printValue(opts.min)}`,
message: `#{{print("property")}}must be longer than ${printValue(opts.min)}`,
},
];
}
Expand Down
7 changes: 7 additions & 0 deletions packages/ref-resolver/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# [@stoplight/spectral-ref-resolver-v1.0.3](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-ref-resolver-v1.0.2...@stoplight/spectral-ref-resolver-v1.0.3) (2022-12-13)


### Bug Fixes

* **ref-resolver:** bump @stoplight/json-ref-resolver from ~3.1.4 to ~3.1.5 ([#3635](https://github.com/stoplightio/spectral/issues/3635)) ([215ae93](https://github.com/stoplightio/spectral/commit/215ae93a3b06d73cc10a07b6c43c718450a2a2fd))

# [@stoplight/spectral-ref-resolver-v1.0.2](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-ref-resolver-v1.0.1...@stoplight/spectral-ref-resolver-v1.0.2) (2022-10-03)


Expand Down
4 changes: 2 additions & 2 deletions packages/ref-resolver/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stoplight/spectral-ref-resolver",
"version": "1.0.2",
"version": "1.0.3",
"homepage": "https://github.com/stoplightio/spectral",
"bugs": "https://github.com/stoplightio/spectral/issues",
"author": "Stoplight <[email protected]>",
Expand All @@ -22,7 +22,7 @@
},
"dependencies": {
"@stoplight/json-ref-readers": "1.2.2",
"@stoplight/json-ref-resolver": "~3.1.4",
"@stoplight/json-ref-resolver": "~3.1.5",
"@stoplight/spectral-runtime": "^1.1.2",
"dependency-graph": "0.11.0",
"tslib": "^2.3.1"
Expand Down
7 changes: 7 additions & 0 deletions packages/ruleset-bundler/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# [@stoplight/spectral-ruleset-bundler-v1.5.0](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-ruleset-bundler-v1.4.0...@stoplight/spectral-ruleset-bundler-v1.5.0) (2022-11-30)


### Features

* **core:** support end-user extensions in the rule definitions ([#2345](https://github.com/stoplightio/spectral/issues/2345)) ([365fced](https://github.com/stoplightio/spectral/commit/365fcedb7c140946767ed28a92a120b3adb08e47))

# [@stoplight/spectral-ruleset-bundler-v1.4.0](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-ruleset-bundler-v1.3.3...@stoplight/spectral-ruleset-bundler-v1.4.0) (2022-10-24)


Expand Down
2 changes: 1 addition & 1 deletion packages/ruleset-bundler/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stoplight/spectral-ruleset-bundler",
"version": "1.4.0",
"version": "1.5.0",
"homepage": "https://github.com/stoplightio/spectral",
"bugs": "https://github.com/stoplightio/spectral/issues",
"author": "Stoplight <[email protected]>",
Expand Down
6 changes: 6 additions & 0 deletions packages/ruleset-bundler/src/loader/__tests__/browser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export default {
description: null,
documentationUrl: null,
enabled: true,
extensions: null,
formats: null,
given: ['$'],
message: null,
Expand All @@ -134,6 +135,7 @@ export default {
description: null,
documentationUrl: null,
enabled: true,
extensions: null,
formats: null,
given: ['$'],
message: null,
Expand All @@ -152,6 +154,7 @@ export default {
description: null,
documentationUrl: null,
enabled: true,
extensions: null,
formats: null,
given: ['$'],
message: null,
Expand Down Expand Up @@ -189,6 +192,7 @@ export default {
description: null,
documentationUrl: null,
enabled: true,
extensions: null,
formats: null,
given: ['$'],
message: null,
Expand All @@ -207,6 +211,7 @@ export default {
description: null,
documentationUrl: null,
enabled: true,
extensions: null,
formats: null,
given: ['$'],
message: null,
Expand All @@ -225,6 +230,7 @@ export default {
description: null,
documentationUrl: null,
enabled: true,
extensions: null,
formats: null,
given: ['$'],
message: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export {default} from '/-/[email protected]/dist=es20
description: null,
documentationUrl: null,
enabled: true,
extensions: null,
formats: null,
given: ['$'],
message: null,
Expand All @@ -66,6 +67,7 @@ export {default} from '/-/[email protected]/dist=es20
description: null,
documentationUrl: null,
enabled: true,
extensions: null,
formats: null,
given: ['$'],
message: null,
Expand All @@ -84,6 +86,7 @@ export {default} from '/-/[email protected]/dist=es20
description: null,
documentationUrl: null,
enabled: true,
extensions: null,
formats: null,
given: ['$'],
message: null,
Expand Down Expand Up @@ -121,6 +124,7 @@ export {default} from '/-/[email protected]/dist=es20
description: null,
documentationUrl: null,
enabled: true,
extensions: null,
formats: null,
given: ['$'],
message: null,
Expand All @@ -139,6 +143,7 @@ export {default} from '/-/[email protected]/dist=es20
description: null,
documentationUrl: null,
enabled: true,
extensions: null,
formats: null,
given: ['$'],
message: null,
Expand All @@ -157,6 +162,7 @@ export {default} from '/-/[email protected]/dist=es20
description: null,
documentationUrl: null,
enabled: true,
extensions: null,
formats: null,
given: ['$'],
message: null,
Expand Down
Loading

0 comments on commit 095adcf

Please sign in to comment.