From 2b404a557416ca5e3b6a0990610fcaeafd0ee6e2 Mon Sep 17 00:00:00 2001 From: Lars Trieloff <trieloff@adobe.com> Date: Wed, 13 Dec 2017 12:30:38 +0000 Subject: [PATCH] [trivial] arrow parameter spacing --- .eslintrc | 3 ++- cli.js | 12 +++++------ lib/readSchemaFile.js | 2 +- lib/schema.js | 38 ++++++++++++++++----------------- spec/lib/readSchemaFile.spec.js | 12 +++++------ spec/lib/schema.spec.js | 4 ++-- 6 files changed, 36 insertions(+), 35 deletions(-) diff --git a/.eslintrc b/.eslintrc index 0de2b41..11155ed 100644 --- a/.eslintrc +++ b/.eslintrc @@ -32,6 +32,7 @@ "space-unary-ops": 2, "comma-spacing": ["error", { "before": false, "after": true }], "space-before-function-paren": ["error", "always"], - "arrow-spacing": "error" + "arrow-spacing": "error", + "arrow-parens": ["error", "as-needed"] } } diff --git a/cli.js b/cli.js index a90e1fa..c7efed4 100644 --- a/cli.js +++ b/cli.js @@ -77,7 +77,7 @@ if (target.isDirectory()) { // the ajv json validator will be passed into the main module to help with processing var files=[]; readdirp({ root: schemaPath, fileFilter: '*.schema.json' }) - .on('data', (entry) => { + .on('data', entry => { files.push(entry.fullPath); ajv.addSchema(require(entry.fullPath), entry.fullPath); }) @@ -85,25 +85,25 @@ if (target.isDirectory()) { Schema.setAjv(ajv); Schema.setSchemaPathMap(schemaPathMap); return Promise.reduce(files, readSchemaFile, schemaPathMap) - .then((schemaMap) => { + .then(schemaMap => { logger.info('finished reading all *.schema.json files in %s, beginning processing….', schemaPath); return Schema.load(schemaMap, schemaPath, outDir, schemaDir, metaElements); }) .then(() => { logger.info('Processing complete.'); }) - .catch((err) => { + .catch(err => { logger.error(err); process.exit(1); }); }) - .on('error', (err) => { + .on('error', err => { logger.error(err); process.exit(1); }); } else { readSchemaFile(schemaPathMap, schemaPath) - .then((schemaMap) => { + .then(schemaMap => { ajv.addSchema(require(schemaPath), schemaPath); Schema.setAjv(ajv); Schema.setSchemaPathMap(schemaPathMap); @@ -113,7 +113,7 @@ if (target.isDirectory()) { .then(() => { logger.info('Processing complete.'); }) - .catch((err) => { + .catch(err => { logger.error(err); process.exit(1); }); diff --git a/lib/readSchemaFile.js b/lib/readSchemaFile.js index 5a001e6..bffb7a6 100644 --- a/lib/readSchemaFile.js +++ b/lib/readSchemaFile.js @@ -15,7 +15,7 @@ module.exports = function readSchemaFile (schemaPathMap, fullPath) { schemaPathMap = {}; } return fs.readFileAsync(fullPath) - .then((data) => { + .then(data => { let schema = JSON.parse(data); let obj = {}; obj.filePath = fullPath; diff --git a/lib/schema.js b/lib/schema.js index e160c65..1d53b14 100644 --- a/lib/schema.js +++ b/lib/schema.js @@ -103,7 +103,7 @@ var processFurther = Promise.method(function (val, key, $id){ } else { if (val['items'] && val['type'] === 'array'){ if (val['items']['$ref']){ - resolve$ref(val['items']).then((s) => { + resolve$ref(val['items']).then(s => { _.forOwn(s, (v, k) => { if (k !== '$ref'){ val['items'][k]=v; @@ -125,12 +125,12 @@ processISchema = Promise.method(function (schema, base$id){ let arr = schema['anyOf']? schema['anyOf'] : schema['oneOf']; _.each(arr, function (value, index) { if (value['$ref']){ - resolve$ref(value, base$id).then((piSchema) => { + resolve$ref(value, base$id).then(piSchema => { delete arr[index]; arr[index]=piSchema; }); } else { - processISchema(value, base$id).then((piSchema) => { + processISchema(value, base$id).then(piSchema => { delete arr[index]; arr[index]=piSchema; }); @@ -149,7 +149,7 @@ processISchema = Promise.method(function (schema, base$id){ } else { if (val['$ref']){ - resolve$ref(val, base$id).then((piSchema) => {//check // not sending correct id + resolve$ref(val, base$id).then(piSchema => {//check // not sending correct id schema['items']=piSchema; }); } else { @@ -186,10 +186,10 @@ function processSchema (schema){ if (pointer.has(obj, refArr.endpart)){ var ischema = _.cloneDeep(pointer.get(obj, refArr.endpart)); if (refArr.refType === 'yAbsFSchema'){ - processSchema(ischema).then((psSchema) => { + processSchema(ischema).then(psSchema => { if ( psSchema['properties'] ){ _.forOwn(psSchema['properties'], (val, key) => { - processFurther(val, key, refArr.startpart).then((pfSchema) => { + processFurther(val, key, refArr.startpart).then(pfSchema => { if (pfSchema){ schema.properties[key] = pfSchema; schema.properties[key].$oSchema={}; @@ -212,7 +212,7 @@ function processSchema (schema){ } else { if ( ischema['properties'] ){ _.forOwn(ischema['properties'], (val, key) => { - processFurther(val, key, refArr.startpart).then((pfSchema) => { + processFurther(val, key, refArr.startpart).then(pfSchema => { if (pfSchema){ schema.properties[key] = pfSchema; if (refArr.refType === 'yAbsWithDef'){ @@ -251,7 +251,7 @@ function processSchema (schema){ resolve(schema); } else if (schema['properties']){ _.forOwn(schema['properties'], (val, key) => { - processFurther(val, key, base$id).then((pfSchema) => { + processFurther(val, key, base$id).then(pfSchema => { if (pfSchema){ schema.properties[key] = pfSchema; @@ -341,14 +341,14 @@ Schema.getExamples = function (filePath, schema){ filename=filename.split('.')[0]+'.example.*.json'; return new Promise((resolve, reject) => { readdirp({ root: dirname, fileFilter: filename }) - .on('data', (entry) => exampleFileNames.push(entry.fullPath)) + .on('data', entry => exampleFileNames.push(entry.fullPath)) .on('end', () => resolve(exampleFileNames)) - .on('error', (err) => reject(err)); - }).then((exampleFileNames) => { + .on('error', err => reject(err)); + }).then(exampleFileNames => { if (exampleFileNames.length > 0){ var validate=this._ajv.compile(schema); - return Promise.map(exampleFileNames, (entry) => { - return fs.readFileAsync(entry).then((example) => { + return Promise.map(exampleFileNames, entry => { + return fs.readFileAsync(entry).then(example => { var data = JSON.parse(example.toString()); var valid = validate(data); if (valid) {examples.push(data);} else {logger.error(entry+' is an invalid Example');} @@ -364,7 +364,7 @@ Schema.getDescription = function (filePath, schema){ //TODO should err be thrown here? temp=temp.split('.')[0]+'.description.md'; return fs.readFileAsync(path.resolve(path.dirname(filePath), temp), 'utf8') - .then((description) => { + .then(description => { schema.description=description; return schema; }) @@ -393,7 +393,7 @@ Schema.load = function (schemaMap, schemaPath, docDir, schemaDir, metaElements) schemaDir = schemaDir ? schemaDir : docDir; smap=schemaMap; let keys = Object.keys(schemaMap); - return Promise.mapSeries(keys, (schemaKey) => { + return Promise.mapSeries(keys, schemaKey => { var props = Object.keys(wmap); for (var i = 0; i < props.length; i++) { @@ -404,18 +404,18 @@ Schema.load = function (schemaMap, schemaPath, docDir, schemaDir, metaElements) let schema = schemaMap[schemaKey].jsonSchema; sPath = schemaMap[schemaKey].filePath; return Schema.getExamples(schemaMap[schemaKey].filePath, schema) - .then((egsSchema) => Schema.getDescription(schemaMap[schemaKey].filePath, egsSchema)) - .then((allSchema) => { + .then(egsSchema => Schema.getDescription(schemaMap[schemaKey].filePath, egsSchema)) + .then(allSchema => { var schemaClone = _.cloneDeep(allSchema); // return Promise.props({ // wSchema:schemaClone, // mSchema:traverseSchema(allSchema,schemaMap[schemaKey].filePath) // }) - return processSchema(schemaClone).then((mSchema) => { + return processSchema(schemaClone).then(mSchema => { mSchema.metaElements=metaElements; return { mSchema:mSchema, wSchema:allSchema, dep:wmap }; }); - }).then((object) => { + }).then(object => { return Promise.all([ Writer.generateMarkdown(schemaMap[schemaKey].filePath, object.mSchema, schemaPath, docDir, object.dep), Writer.generateNewSchemaFiles(schemaMap[schemaKey].filePath, object.wSchema, schemaPath, schemaDir) ]); diff --git a/spec/lib/readSchemaFile.spec.js b/spec/lib/readSchemaFile.spec.js index 95140a9..9f2f292 100644 --- a/spec/lib/readSchemaFile.spec.js +++ b/spec/lib/readSchemaFile.spec.js @@ -15,9 +15,9 @@ describe('readSchemaFile module', () => { spyOn(fs, 'readFileAsync').and.returnValue(Promise.resolve('{"schema":"yes"}')); }); describe('reading schema files without an $id key', () => { - it('should return a schema path map with path to the file as a key, and object value with path and json schema', (done) => { + it('should return a schema path map with path to the file as a key, and object value with path and json schema', done => { readSchemaFile({}, fakePath) - .then((map) => { + .then(map => { expect(map[fakePath]).toBeDefined(); expect(map[fakePath].filePath).toEqual(fakePath); expect(map[fakePath].jsonSchema).toEqual({ schema:'yes' }); @@ -30,9 +30,9 @@ describe('readSchemaFile module', () => { beforeEach(() => { fs.readFileAsync.and.returnValue(Promise.resolve('{"$id":"allyourbase"}')); }); - it('should return a schema path map with $id value as a key, and object value with path and json schema', (done) => { + it('should return a schema path map with $id value as a key, and object value with path and json schema', done => { readSchemaFile({}, fakePath) - .then((map) => { + .then(map => { expect(map['allyourbase']).toBeDefined(); expect(map['allyourbase'].filePath).toEqual(fakePath); expect(map['allyourbase'].jsonSchema).toEqual({ $id:'allyourbase' }); @@ -40,9 +40,9 @@ describe('readSchemaFile module', () => { .catch(fail) .done(done); }); - it('should not overwrite the value for an existing $id key in the schema path map', (done) => { + it('should not overwrite the value for an existing $id key in the schema path map', done => { readSchemaFile({ allyourbase:{} }, fakePath) - .then((map) => { + .then(map => { expect(map['allyourbase']).toBeDefined(); expect(map['allyourbase'].filePath).not.toBeDefined(); expect(map['allyourbase'].jsonSchema).not.toBeDefined(); diff --git a/spec/lib/schema.spec.js b/spec/lib/schema.spec.js index 9ceb971..2d9e7b6 100644 --- a/spec/lib/schema.spec.js +++ b/spec/lib/schema.spec.js @@ -14,12 +14,12 @@ describe('schema module', () => { beforeEach(() => { spyOn(fs, 'readFileAsync'); }); - it('should read a description.md file based on provided file path and tack it onto a provided schema', (done) => { + it('should read a description.md file based on provided file path and tack it onto a provided schema', done => { var fakeContents = 'IMPORTANT CONTENTS!'; fs.readFileAsync.and.returnValue(Promise.resolve(fakeContents)); var skeem = {}; schema.getDescription('/some/path', skeem) - .then((returnedSchema) => { + .then(returnedSchema => { expect(returnedSchema.description).toEqual(fakeContents); expect(skeem.description).toEqual(fakeContents); }).catch(() => { -- GitLab