Skip to content

Commit

Permalink
use default yml ruleset file & support yml custom rulesets
Browse files Browse the repository at this point in the history
  • Loading branch information
jorge-ibm committed Sep 18, 2020
1 parent f5c1736 commit 6bfc910
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 33 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ bin/
.nyc_output/
coverage/
.spectral.json
.spectral.yaml
.spectral.yml
18 changes: 13 additions & 5 deletions src/cli-validator/utils/processConfiguration.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,20 +368,28 @@ const validateConfigOption = function(userOption, defaultOption) {
};

const getSpectralRuleset = async function(defaultRuleset) {
const ruleSetFileName = '.spectral.json';
// List of ruleset files to search for
const ruleSetFilesToFind = [
'.spectral.yaml',
'.spectral.yml',
'.spectral.json'
];
let ruleSetFile;

// search up the file system for the first instance
// of '.spectral.json'
// search up the file system for the first ruleset file found
try {
ruleSetFile = await findUp(ruleSetFileName);
for (const file of ruleSetFilesToFind) {
if (!ruleSetFile) {
ruleSetFile = await findUp(file);
}
}
} catch (err) {
// if there's any issue finding a custom ruleset, then
// just use the default
ruleSetFile = defaultRuleset;
}

if (ruleSetFile === null) {
if (!ruleSetFile) {
ruleSetFile = defaultRuleset;
}

Expand Down
27 changes: 0 additions & 27 deletions src/spectral/rulesets/.defaultsForSpectral.json

This file was deleted.

24 changes: 24 additions & 0 deletions src/spectral/rulesets/.defaultsForSpectral.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
extends: [[spectral:oas, off]]
formats: [oas2, oas3]
functionsDir": ../functions
rules:
no-eval-in-markdown: true
no-script-tags-in-markdown: true
openapi-tags: true
operation-description: true
operation-tags: true
operation-tag-defined: true
path-keys-no-trailing-slash: true
typed-enum: true
oas2-api-host: true
oas2-api-schemes: true
oas2-host-trailing-slash: true
oas2-valid-example: true
oas2-valid-definition-example: true
oas2-anyOf: true
oas2-oneOf: true
oas3-api-servers: true
oas3-examples-value-or-externalValue: true
oas3-server-trailing-slash: true
oas3-valid-example: true
oas3-valid-schema-example: true
2 changes: 1 addition & 1 deletion src/spectral/utils/spectral-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const config = require('../../cli-validator/utils/processConfiguration');
const { isOpenApiv2, isOpenApiv3 } = require('@stoplight/spectral');
// default spectral ruleset file
const defaultSpectralRuleset =
__dirname + '/../rulesets/.defaultsForSpectral.json';
__dirname + '/../rulesets/.defaultsForSpectral.yaml';

const parseResults = function(results, debug) {
const messages = new MessageCarrier();
Expand Down

0 comments on commit 6bfc910

Please sign in to comment.