added linting to generator
parent
66dd66959f
commit
a6ee8d4593
|
@ -123,7 +123,9 @@ module.exports = {
|
||||||
let spec = generateTemplate(config)
|
let spec = generateTemplate(config)
|
||||||
|
|
||||||
if(!args['skip-linting']) {
|
if(!args['skip-linting']) {
|
||||||
linter.lint(spec)
|
if(!linter.lint(spec).success) {
|
||||||
|
throw 'Lintin Error!'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!args.q && !args.quiet) {
|
if(!args.q && !args.quiet) {
|
||||||
|
|
|
@ -41,14 +41,22 @@ const linterMappings = [
|
||||||
|
|
||||||
|
|
||||||
module.exports.lint = function(spec) {
|
module.exports.lint = function(spec) {
|
||||||
let messages = [];
|
let results = {
|
||||||
|
success: true
|
||||||
|
}
|
||||||
linterMappings.forEach(element => {
|
linterMappings.forEach(element => {
|
||||||
let value = objectPath.get(spec, element.path);
|
let value = objectPath.get(spec, element.path);
|
||||||
element.linters.forEach(linter => {
|
element.linters.forEach(linter => {
|
||||||
linter(element.path, value, messages);
|
let msg = linter(element.path, value)
|
||||||
|
if(msg) {
|
||||||
|
results.success = false
|
||||||
|
}
|
||||||
|
msg = msg || 'OK'
|
||||||
|
results[element.path] = msg;
|
||||||
|
console.log(element.path, msg)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return messages;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.regex = {
|
module.exports.regex = {
|
||||||
|
|
|
@ -67,5 +67,18 @@ describe("gen command", () => {
|
||||||
expect(spec_json).to.have.ownProperty('namespace')
|
expect(spec_json).to.have.ownProperty('namespace')
|
||||||
fs.unlinkSync(spec_path)
|
fs.unlinkSync(spec_path)
|
||||||
})
|
})
|
||||||
|
it('fails on invalid linting properties', () => {
|
||||||
|
expect(() => commands.gen.run({
|
||||||
|
...test_spec,
|
||||||
|
name: 'Test'
|
||||||
|
})).to.throw()
|
||||||
|
})
|
||||||
|
it('does not fail on invalid linting properties when lintin disabled', () => {
|
||||||
|
expect(() => commands.gen.run({
|
||||||
|
...test_spec,
|
||||||
|
name: 'Test',
|
||||||
|
'skip-linting': true
|
||||||
|
})).to.not.throw()
|
||||||
|
})
|
||||||
|
|
||||||
})
|
})
|
|
@ -31,3 +31,23 @@ describe('linter validators', () => {
|
||||||
expect(linter.validators.regex(/.+/)('path', ' ')).to.not.be.empty
|
expect(linter.validators.regex(/.+/)('path', ' ')).to.not.be.empty
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
describe('linter for spec', () => {
|
||||||
|
it('fails on invalid name property', () => {
|
||||||
|
let result = linter.lint({
|
||||||
|
name: "Test",
|
||||||
|
description: "Test."
|
||||||
|
})
|
||||||
|
expect(result.success).to.equal(false)
|
||||||
|
expect(result.name).to.not.equal('OK')
|
||||||
|
})
|
||||||
|
it('fails on invalid description property', () => {
|
||||||
|
let result = linter.lint({
|
||||||
|
name: "test-service",
|
||||||
|
description: "test."
|
||||||
|
})
|
||||||
|
expect(result.success).to.equal(false)
|
||||||
|
expect(result.description).to.not.equal('OK')
|
||||||
|
})
|
||||||
|
})
|
Loading…
Reference in New Issue