Created
March 27, 2019 22:14
-
-
Save tbarn/dceba0274e7eee60213c0d9dc14730db to your computer and use it in GitHub Desktop.
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
const { RuleFunction, Spectral } = require('@stoplight/spectral'); | |
const spectral = new Spectral(); | |
spectral.addRules({ | |
snake_case: { | |
summary: ‘Checks for snake case pattern’, | |
// evaluate every property | |
given: '$..*', | |
then: { | |
function: RuleFunction.PATTERN, | |
functionOptions: { | |
match: '^[a-z]+[a-z0-9_]*[a-z0-9]+$', | |
}, | |
}, | |
}, | |
}); | |
// run! | |
spectral.run({name: ‘helloWorld’,}).then(results => { | |
console.log(JSON.stringify(results, null, 4)); | |
}); | |
// => outputs a single result since helloWorld is not snake_case | |
// [ | |
// { | |
// “name”: “snake_case”, | |
// “message”: “must match the pattern ‘^[a-z]+[a-z0-9_]*[a-z0-9]+$’”, | |
// “severity”: 1, | |
// “path”: [ | |
// “name” | |
// ] | |
// } | |
// ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment