-
-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): support overrides in rulesets (#1684)
Co-authored-by: William Hilton <wmhilton@gmail.com>
- Loading branch information
1 parent
f95cac4
commit 153d685
Showing
30 changed files
with
1,293 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
packages/core/src/ruleset/__tests__/__fixtures__/overrides/_base.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { pattern } from '@stoplight/spectral-functions'; | ||
import { DiagnosticSeverity } from '@stoplight/types'; | ||
|
||
export default { | ||
rules: { | ||
'description-matches-stoplight': { | ||
message: 'Description must contain Stoplight', | ||
given: '$.info', | ||
recommended: true, | ||
severity: DiagnosticSeverity.Error, | ||
then: { | ||
field: 'description', | ||
function: pattern, | ||
functionOptions: { | ||
match: 'Stoplight', | ||
}, | ||
}, | ||
}, | ||
'title-matches-stoplight': { | ||
message: 'Title must contain Stoplight', | ||
given: '$.info', | ||
then: { | ||
field: 'title', | ||
function: pattern, | ||
functionOptions: { | ||
match: 'Stoplight', | ||
}, | ||
}, | ||
}, | ||
'contact-name-matches-stoplight': { | ||
message: 'Contact name must contain Stoplight', | ||
given: '$.info.contact', | ||
recommended: false, | ||
then: { | ||
field: 'name', | ||
function: pattern, | ||
functionOptions: { | ||
match: 'Stoplight', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; |
14 changes: 14 additions & 0 deletions
14
packages/core/src/ruleset/__tests__/__fixtures__/overrides/extends/all.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { RulesetDefinition } from '@stoplight/spectral-core'; | ||
|
||
import _base from '../_base'; | ||
|
||
export { ruleset as default }; | ||
|
||
const ruleset: RulesetDefinition = { | ||
overrides: [ | ||
{ | ||
files: ['**/*.json'], | ||
extends: [[_base, 'all']], | ||
}, | ||
], | ||
}; |
15 changes: 15 additions & 0 deletions
15
packages/core/src/ruleset/__tests__/__fixtures__/overrides/extends/both.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { RulesetDefinition } from '@stoplight/spectral-core'; | ||
|
||
import _base from '../_base'; | ||
|
||
export { ruleset as default }; | ||
|
||
const ruleset: RulesetDefinition = { | ||
extends: [[_base, 'off']], | ||
overrides: [ | ||
{ | ||
files: ['**/*.json'], | ||
extends: [[_base, 'all']], | ||
}, | ||
], | ||
}; |
18 changes: 18 additions & 0 deletions
18
packages/core/src/ruleset/__tests__/__fixtures__/overrides/extends/multiple-extends.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { RulesetDefinition } from '@stoplight/spectral-core'; | ||
|
||
import _base from '../_base'; | ||
|
||
export { ruleset as default }; | ||
|
||
const ruleset: RulesetDefinition = { | ||
overrides: [ | ||
{ | ||
files: ['**/*.json'], | ||
extends: [[_base, 'all']], | ||
}, | ||
{ | ||
files: ['v2/**/*.json'], | ||
extends: [[_base, 'off']], | ||
}, | ||
], | ||
}; |
49 changes: 49 additions & 0 deletions
49
packages/core/src/ruleset/__tests__/__fixtures__/overrides/formats.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { jsonSchemaDraft4, jsonSchemaDraft7 } from '@stoplight/spectral-formats'; | ||
import { schema } from '@stoplight/spectral-functions'; | ||
import { RulesetDefinition } from '@stoplight/spectral-core'; | ||
|
||
import _base from './_base'; | ||
|
||
export { ruleset as default }; | ||
|
||
const ruleset: RulesetDefinition = { | ||
rules: { | ||
..._base.rules, | ||
}, | ||
overrides: [ | ||
{ | ||
files: ['schemas/**/*.draft7.json'], | ||
formats: [jsonSchemaDraft7], | ||
rules: { | ||
// if you stumbled upon this file and want to use this rule in your own ruleset - do NOT. | ||
// it doesn't cover many cases, and it's only purpose is to serve us as a test artefact | ||
'valid-number-validation': { | ||
given: ['$..exclusiveMinimum', '$..exclusiveMaximum'], | ||
then: { | ||
function: schema, | ||
functionOptions: { | ||
type: 'number', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
files: ['schemas/**/*.draft4.json'], | ||
formats: [jsonSchemaDraft4], | ||
rules: { | ||
// if you stumbled upon this file and want to use this rule in your own ruleset - do NOT. | ||
// it doesn't cover many cases, and it's only purpose is to serve us as a test artefact | ||
'valid-number-validation': { | ||
given: ['$..exclusiveMinimum', '$..exclusiveMaximum'], | ||
then: { | ||
function: schema, | ||
functionOptions: { | ||
type: 'boolean', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
], | ||
}; |
34 changes: 34 additions & 0 deletions
34
packages/core/src/ruleset/__tests__/__fixtures__/overrides/hierarchy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import _base from './_base'; | ||
import { RulesetDefinition } from '../../../types'; | ||
|
||
export { ruleset as default }; | ||
|
||
const ruleset: RulesetDefinition = { | ||
rules: { | ||
..._base.rules, | ||
}, | ||
overrides: [ | ||
{ | ||
files: ['legacy/**/*.json'], | ||
rules: { | ||
'description-matches-stoplight': 'off', | ||
'title-matches-stoplight': 'warn', | ||
'contact-name-matches-stoplight': true, | ||
}, | ||
}, | ||
{ | ||
files: ['v2/**/*.json'], | ||
rules: { | ||
'description-matches-stoplight': 'error', | ||
'title-matches-stoplight': 'hint', | ||
}, | ||
}, | ||
{ | ||
files: ['**/*.json'], | ||
rules: { | ||
'description-matches-stoplight': 'info', | ||
'title-matches-stoplight': 'off', | ||
}, | ||
}, | ||
], | ||
}; |
27 changes: 27 additions & 0 deletions
27
packages/core/src/ruleset/__tests__/__fixtures__/overrides/new-definitions-error.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import _base from './_base'; | ||
import { RulesetDefinition } from '../../../types'; | ||
|
||
export { ruleset as default }; | ||
|
||
const ruleset: RulesetDefinition = { | ||
extends: _base, | ||
overrides: [ | ||
{ | ||
files: ['legacy/**/*.json'], | ||
rules: { | ||
'new-definition': { | ||
given: '$', | ||
then: { | ||
function() {}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
files: ['v2/**/*.json'], | ||
rules: { | ||
'new-definition': 'off', // errors | ||
}, | ||
}, | ||
], | ||
}; |
30 changes: 30 additions & 0 deletions
30
packages/core/src/ruleset/__tests__/__fixtures__/overrides/new-definitions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { DiagnosticSeverity } from '@stoplight/types'; | ||
import { pattern } from '@stoplight/spectral-functions'; | ||
import { RulesetDefinition } from '@stoplight/spectral-core'; | ||
|
||
import _base from './_base'; | ||
|
||
export { ruleset as default }; | ||
|
||
const ruleset: RulesetDefinition = { | ||
extends: _base, | ||
overrides: [ | ||
{ | ||
files: ['legacy/**/*.json'], | ||
rules: { | ||
'value-matches-stoplight': { | ||
message: 'Value must contain Stoplight', | ||
given: '$..value', | ||
severity: DiagnosticSeverity.Error, | ||
then: { | ||
field: 'description', | ||
function: pattern, | ||
functionOptions: { | ||
match: 'Stoplight', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
], | ||
}; |
10 changes: 10 additions & 0 deletions
10
packages/core/src/ruleset/__tests__/__fixtures__/overrides/only-overrides.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import _base from './_base'; | ||
|
||
export default { | ||
overrides: [ | ||
{ | ||
files: ['**/*.json'], | ||
extends: [_base], | ||
}, | ||
], | ||
}; |
26 changes: 26 additions & 0 deletions
26
packages/core/src/ruleset/__tests__/__fixtures__/overrides/only-rules.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import _base from './_base'; | ||
import { RulesetDefinition } from '../../../types'; | ||
|
||
export { ruleset as default }; | ||
|
||
const ruleset: RulesetDefinition = { | ||
rules: { | ||
..._base.rules, | ||
}, | ||
overrides: [ | ||
{ | ||
files: ['legacy/**/*.json'], | ||
rules: { | ||
'description-matches-stoplight': 'off', | ||
'title-matches-stoplight': 'warn', | ||
}, | ||
}, | ||
{ | ||
files: ['v2/**/*.json'], | ||
rules: { | ||
'description-matches-stoplight': 'error', | ||
'title-matches-stoplight': 'hint', | ||
}, | ||
}, | ||
], | ||
}; |
Oops, something went wrong.