diff --git a/.eslintrc b/.eslintrc index e301a91089c70500e53901467be729240e8a30ea..ed3e560dfa395db1683d039a40c6a2506e81ee69 100644 --- a/.eslintrc +++ b/.eslintrc @@ -30,6 +30,7 @@ "after": true }], "space-unary-ops": 2, - "comma-spacing": ["error", { "before": false, "after": true }] + "comma-spacing": ["error", { "before": false, "after": true }], + "space-before-function-paren": ["error", "always"] } } diff --git a/cli.js b/cli.js index 4a5fbeb55fecaec9308b0c2014505c4e158a6b80..dc4337907fbb55832df9044d66e6198ae34ed0a0 100644 --- a/cli.js +++ b/cli.js @@ -58,7 +58,7 @@ if (argv.s){ if (argv.m) { if (_.isArray(argv.m)){ - _.each(argv.m, function(item){ + _.each(argv.m, function (item){ var meta=item.split('='); if (meta.length === 2) { metaElements[meta[0]] = meta[1]; diff --git a/lib/readSchemaFile.js b/lib/readSchemaFile.js index 7b29143816ee725c4426a5e1ddd463c0b8f8c3a1..0e49b3de032773349c199877f35830b43b1027cc 100644 --- a/lib/readSchemaFile.js +++ b/lib/readSchemaFile.js @@ -10,7 +10,7 @@ var fs = Promise.promisifyAll(require('fs')); // Reads a schema file and modifies a schema path map object based on the schema file. // Returns the schema path map object. -module.exports = function readSchemaFile(schemaPathMap, fullPath) { +module.exports = function readSchemaFile (schemaPathMap, fullPath) { if (!schemaPathMap) { schemaPathMap = {}; } diff --git a/lib/schema.js b/lib/schema.js index b3311bde5c9c97e4c3b278fa47c144cb5f369f0f..aa13189863c32f06d38db856fb2beedc03cafcc8 100644 --- a/lib/schema.js +++ b/lib/schema.js @@ -18,7 +18,7 @@ var pointer = require('json-pointer'); var smap; //TODO remove global var sPath; var wmap={}; -function get$refType(refValue){ +function get$refType (refValue){ var startpart = '', endpart = '', refType = ''; var arr = refValue.split('#'); if (arr.length > 1) {endpart=arr[1];} @@ -52,7 +52,7 @@ function get$refType(refValue){ return { startpart, endpart, refType }; } -function normaliseLinks(obj, refArr){ +function normaliseLinks (obj, refArr){ let basepath = refArr.startpart ; let $linkVal = '', $linkPath = ''; if (basepath in smap){ @@ -63,7 +63,7 @@ function normaliseLinks(obj, refArr){ return { $linkVal, $linkPath }; } } -var resolve$ref = Promise.method(function(val, base$id){ +var resolve$ref = Promise.method(function (val, base$id){ let obj, link; if (!(base$id in wmap) ) {wmap[base$id] = {};} let refArr = get$refType(val['$ref']); @@ -96,7 +96,7 @@ var resolve$ref = Promise.method(function(val, base$id){ } } }); -var processFurther = Promise.method(function(val, key, $id){ +var processFurther = Promise.method(function (val, key, $id){ let base$id =$id; if (val['$ref']){ return resolve$ref(val, base$id); @@ -116,14 +116,14 @@ var processFurther = Promise.method(function(val, key, $id){ return val; } }); -function processISchema() {}; // define w/ function so it gets hoisted and we avoid eslint errors about what is defined first: processISchema or resolve$ref. Both rely on each other! -processISchema = Promise.method(function(schema, base$id){ +function processISchema () {}; // define w/ function so it gets hoisted and we avoid eslint errors about what is defined first: processISchema or resolve$ref. Both rely on each other! +processISchema = Promise.method(function (schema, base$id){ if (!(base$id in wmap) ) {wmap[base$id] = {};} if (schema['anyOf'] || schema['oneOf']){ // var $definitions=[] schema['type'] = schema['anyOf'] ? 'anyOf' : 'oneOf'; let arr = schema['anyOf']? schema['anyOf'] : schema['oneOf']; - _.each(arr, function(value, index) { + _.each(arr, function (value, index) { if (value['$ref']){ resolve$ref(value, base$id).then((piSchema)=>{ delete arr[index]; @@ -160,14 +160,14 @@ processISchema = Promise.method(function(schema, base$id){ // schema.$definitions = $definitions return schema; }); -function processSchema(schema){ +function processSchema (schema){ return new Promise((resolve, reject)=>{ if (!schema.properties) {schema.properties={};} var $id = schema['$id'] || schema['id']; var base$id = $id; if (!(base$id in wmap)) {wmap[base$id] = {};} if (schema['allOf']){ - _.each(schema['allOf'], function(value) { + _.each(schema['allOf'], function (value) { if (value['$ref']){ let obj, link; var refArr = get$refType(value['$ref']); @@ -239,7 +239,7 @@ function processSchema(schema){ } else { - _.forOwn(value, function(val, key){ + _.forOwn(value, function (val, key){ schema[key]=val; // }); @@ -276,12 +276,12 @@ function processSchema(schema){ } -var Schema=function(ajv, schemaMap){ +var Schema=function (ajv, schemaMap){ this._ajv = ajv; this._schemaPathMap=schemaMap; }; -Schema.resolveRef=function(key, obj, currpath){ +Schema.resolveRef=function (key, obj, currpath){ if (key === '$ref'){ var refVal = obj[key]; var temp; @@ -333,7 +333,7 @@ var traverseSchema = function(object,schemaFilePath){ }; */ -Schema.getExamples = function(filePath, schema){ +Schema.getExamples = function (filePath, schema){ var exampleFileNames=[]; var examples=[]; var dirname=path.dirname(filePath); @@ -358,7 +358,7 @@ Schema.getExamples = function(filePath, schema){ }); }; -Schema.getDescription = function(filePath, schema){ +Schema.getDescription = function (filePath, schema){ var temp=path.basename(filePath, path.extname(filePath)); //TODO should err be thrown here? @@ -374,11 +374,11 @@ Schema.getDescription = function(filePath, schema){ }; -Schema.setAjv=function(ajv){ +Schema.setAjv=function (ajv){ this._ajv=ajv; }; -Schema.setSchemaPathMap=function(schemaMap){ +Schema.setSchemaPathMap=function (schemaMap){ this._schemaPathMap=schemaMap; }; /** @@ -389,7 +389,7 @@ Schema.setSchemaPathMap=function(schemaMap){ * @param {string} schemaDir - where schemas will be generated, if null, `docDir` will be used * @param {*} metaElements */ -Schema.load = function(schemaMap, schemaPath, docDir, schemaDir, metaElements) { +Schema.load = function (schemaMap, schemaPath, docDir, schemaDir, metaElements) { schemaDir = schemaDir ? schemaDir : docDir; smap=schemaMap; let keys = Object.keys(schemaMap); diff --git a/lib/writeFiles.js b/lib/writeFiles.js index eb212dc0a960f5577eda6daca020d5f6d2dc06df..608f1ab615c97a8854a2a33cd6f4deb691696901 100644 --- a/lib/writeFiles.js +++ b/lib/writeFiles.js @@ -18,7 +18,7 @@ var validUrl = require('valid-url'); // this._schemaPath = schemaPath; // }; var Writer = {}; -var writeFile = function(outputDir, fileName, data) { +var writeFile = function (outputDir, fileName, data) { if (!fs.existsSync(outputDir)){ return mkdirp(outputDir).then(()=>{ return fs.writeFileAsync(path.join(outputDir, fileName), data); @@ -28,7 +28,7 @@ var writeFile = function(outputDir, fileName, data) { } }; -Writer.generateMarkdown = function(filename, schema, schemaPath, outDir, dependencyMap) { +Writer.generateMarkdown = function (filename, schema, schemaPath, outDir, dependencyMap) { var ctx = { schema: schema, @@ -37,14 +37,14 @@ Writer.generateMarkdown = function(filename, schema, schemaPath, outDir, depende dependencyMap:dependencyMap }; - ejs.renderFile(path.join(__dirname, '../templates/md/topSchema.ejs'), ctx, { debug: false }, function(err, str){ + ejs.renderFile(path.join(__dirname, '../templates/md/topSchema.ejs'), ctx, { debug: false }, function (err, str){ if (err) {console.error(err);} return writeFile(path.join(path.join(outDir), path.dirname(filename.substr(schemaPath.length))), path.basename(filename).slice(0, -5)+ '.md', str); }); }; -Writer.generateNewSchemaFiles = function(filename, schema, schemaPath, outDir) { +Writer.generateNewSchemaFiles = function (filename, schema, schemaPath, outDir) { return writeFile(path.join(path.join(outDir), path.dirname(filename.substr(schemaPath.length))), path.basename(filename), JSON.stringify(schema, null, 4)); };