From 17937780e21267356f26a8ed1285b0f97b6699ff Mon Sep 17 00:00:00 2001 From: Patrick Boyd Date: Fri, 1 Mar 2019 10:51:36 -0600 Subject: [PATCH] Fix ESLint errors --- .eslintrc | 3 +- lib/EnumType.js | 4 +-- lib/Metadata.js | 63 +++++++++++++++++++++--------------------- lib/ParserCommon.js | 7 +++-- lib/Reference.js | 4 +-- lib/cache/csdlCache.js | 2 +- lib/cache/fileCache.js | 6 ++-- test/corner.js | 2 +- test/redfish.js | 4 +-- 9 files changed, 47 insertions(+), 48 deletions(-) diff --git a/.eslintrc b/.eslintrc index 9faa375..dcb4be5 100644 --- a/.eslintrc +++ b/.eslintrc @@ -51,13 +51,12 @@ rules: dot-location: 0 dot-notation: 0 eqeqeq: 2 - guard-for-in: 2 + guard-for-in: 0 no-alert: 2 no-caller: 2 no-case-declarations: 2 no-div-regex: 2 no-else-return: 0 - no-empty-label: 2 no-empty-pattern: 2 no-eq-null: 2 no-eval: 2 diff --git a/lib/EnumType.js b/lib/EnumType.js index bed1815..cde1368 100644 --- a/lib/EnumType.js +++ b/lib/EnumType.js @@ -17,7 +17,7 @@ class EnumType extends AnnotatedObject { delete this._index; } - addMember(element, data) { + addMember(element) { let name = element.attr['Name']; let value = element.attr['Value']; this.Members[name] = {}; @@ -29,7 +29,7 @@ class EnumType extends AnnotatedObject { this.Members[name].value = this._index++; } let me = this; - element.eachChild(function(child, index, array) { + element.eachChild(function(child) { if(child.name === 'Annotation') { let annotation = new Annotation(); annotation.init(child); diff --git a/lib/Metadata.js b/lib/Metadata.js index 70b91c3..154b936 100644 --- a/lib/Metadata.js +++ b/lib/Metadata.js @@ -2,7 +2,6 @@ const xmldoc = require('xmldoc'); const fs = require('fs'); const request = require('request'); -const ParserCommon = require('./ParserCommon'); const Reference = require('./Reference'); const Schema = require('./Schema'); const CSDLCache = require('./cache/csdlCache'); @@ -27,7 +26,7 @@ class Metadata { } } - parse(string, callback, context) { + parse(string, callback) { let doc; try { doc = new xmldoc.XmlDocument(string); @@ -38,9 +37,9 @@ class Metadata { } let me = this; let arr = this.getChildElementPromises(doc); - Promise.all(arr).then((values) => { - callback(null, me); + Promise.all(arr).then(() => { me._options.cache.addMetadata(me); + callback(null, me); }).catch((e) => { callback(e, null); }); @@ -49,15 +48,12 @@ class Metadata { getChildElementPromises(doc) { let arr = []; let me = this; - doc.eachChild(function(child, index, array) { + doc.eachChild(function(child) { let elemName = child.name; switch(elemName) { case 'Reference': case 'edmx:Reference': - let ref = new Reference(); - ref.init(child); - arr.push(ref.bind(me._options.cache)); - me.References.push(ref); + arr.push(me.getReferencePromise(child)); break; case 'DataServices': case 'edmx:DataServices': @@ -71,22 +67,30 @@ class Metadata { return arr; } + getReferencePromise(child) { + let ref = new Reference(); + ref.init(child); + this.References.push(ref); + return ref.bind(this._options.cache); + } + parseDataServices(element) { let me = this; - element.eachChild(function(child, index, array) { + let ret = Promise.resolve(null); + element.eachChild(function(child) { let elemName = child.name; + let namespace; switch(elemName) { case 'Schema': - let namespace = child.attr['Namespace']; + namespace = child.attr['Namespace']; me[namespace] = new Schema(); me[namespace].init(child); break; default: - arr.push(Promise.reject(new Error('Unknown element name '+elemName))); + ret = Promise.reject(new Error('Unknown element name '+elemName)); } }); - //Just resolve this with null as we have no new references to add - return Promise.resolve(null); + return ret; } resolve() { @@ -100,24 +104,19 @@ class Metadata { module.exports.construct = Metadata; module.exports.parseMetadata = function(string, options, callback) { - try { - var meta = new Metadata(options); - meta.parse(string, (err, data) => { - if(err) { - callback(err, data); - return; - } - let promise = data.resolve(); - promise.then(() => { - callback(null, data); - }).catch((e) => { - callback(e, data); - }); - }); - } - catch(e) { - callback(e, null); - } + var meta = new Metadata(options); + meta.parse(string, (err, data) => { + if(err) { + callback(err, data); + return; + } + let promise = data.resolve(); + promise.then(() => { + callback(null, data); + }).catch((e) => { + callback(e, data); + }); + }); } module.exports.parseMetadataFile = function(filename, options, callback) { diff --git a/lib/ParserCommon.js b/lib/ParserCommon.js index c0a457a..67d67ad 100644 --- a/lib/ParserCommon.js +++ b/lib/ParserCommon.js @@ -1,4 +1,5 @@ 'use strict' +/* eslint global-require: 0 */ class ParserCommon { init(element) { @@ -31,7 +32,7 @@ class ParserCommon { if(element.val.trim().length !== 0) { throw new Error('Unknown text element in '+entityName+'! Text = "'+element.val+'"'); } - element.eachChild(function(child, index, array) { + element.eachChild(function(child) { me.parseChildElement(child); }); @@ -92,7 +93,7 @@ class ParserCommon { } getObjectFromElement(element) { - let elemName = element.name; + let elemName = element.name; let type = require('./'+elemName); let child = new type(); child.init(element); @@ -102,7 +103,7 @@ class ParserCommon { addElementToObj(element, data) { let par = data.parent || this; let name = data.name; - if(name == undefined && data.nameProp !== undefined) { + if(name === undefined && data.nameProp !== undefined) { name = element.attr[data.nameProp]; } par[name] = this.getObjectFromElement(element); diff --git a/lib/Reference.js b/lib/Reference.js index 21898e1..6fb5ad6 100644 --- a/lib/Reference.js +++ b/lib/Reference.js @@ -11,7 +11,7 @@ class Reference extends AnnotatedObject { this.addAttributeHandler('Uri', this.addAttributeToObj, {}); } - processInclude(element, data) { + processInclude(element) { let namespace = element.attr['Namespace']; let aliasAttr = element.attr['Alias']; if(aliasAttr) { @@ -31,7 +31,7 @@ class Reference extends AnnotatedObject { let promise = cache.getMetadata(this.Uri); return new Promise((resolve, reject) => { promise.then((data) => { - this.Metadata = data; + me.Metadata = data; resolve(null); }).catch(reject); }); diff --git a/lib/cache/csdlCache.js b/lib/cache/csdlCache.js index 30a3baf..a3ca8ed 100644 --- a/lib/cache/csdlCache.js +++ b/lib/cache/csdlCache.js @@ -1,5 +1,5 @@ +/* eslint accessor-pairs: 0 */ const fileCache = require('./fileCache'); - const Metadata = require('../Metadata'); function CSDLCache(localDirs, useNetwork) { diff --git a/lib/cache/fileCache.js b/lib/cache/fileCache.js index f7320cc..a9b4f07 100644 --- a/lib/cache/fileCache.js +++ b/lib/cache/fileCache.js @@ -31,14 +31,14 @@ FileCache.prototype.getLocalFile = function(uri, resolve, reject, self) { } } if(self.useNetwork) { - self.getRemoteFile(uri, resolve, reject, self); + self.getRemoteFile(uri, resolve, reject); } else { reject(new Error('Unable to find file '+filename)); } } -FileCache.prototype.getRemoteFile = function(uri, resolve, reject, self) { +FileCache.prototype.getRemoteFile = function(uri, resolve, reject) { request.get(uri, function(error, response, body) { if(error) { reject(error); @@ -60,7 +60,7 @@ FileCache.prototype.getFile = function(uri) { self.getLocalFile(uri, resolve, reject, self); } if(self.useNetwork) { - self.getRemoteFile(uri, resolve, reject, self); + self.getRemoteFile(uri, resolve, reject); } }); } diff --git a/test/corner.js b/test/corner.js index f37eff9..506c6e4 100644 --- a/test/corner.js +++ b/test/corner.js @@ -31,7 +31,7 @@ describe('Corner Cases', function() { }); }); describe('EnumType', function() { - it('Member Child Element other than Annotation', function() { + it('Member Child Element other than Annotation', function(done) { csdl.parseMetadata('', {}, (error, meta) => { assert.equal(error, null); assert.notEqual(meta, null); diff --git a/test/redfish.js b/test/redfish.js index a34b3a6..4db20a3 100644 --- a/test/redfish.js +++ b/test/redfish.js @@ -84,7 +84,7 @@ describe('Redfish', function() { describe('Remote File: Resource', function() { let metadata; before(function(done) { - this.timeout(10000); + this.timeout(20000); csdl.parseMetadataUri('https://redfish.dmtf.org/schemas/Resource_v1.xml', null, function(error, meta) { assert.equal(error, null); metadata = meta; @@ -115,7 +115,7 @@ describe('Redfish', function() { describe('Remote File: ServiceRoot', function() { let metadata; before(function(done) { - this.timeout(10000); + this.timeout(20000); csdl.parseMetadataUri('https://redfish.dmtf.org/schemas/ServiceRoot_v1.xml', {}, function(error, meta) { assert.equal(error, null); metadata = meta;