Skip to content

Commit

Permalink
Fix ESLint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
pboyd04 committed Mar 1, 2019
1 parent cd3449f commit 1793778
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 48 deletions.
3 changes: 1 addition & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/EnumType.js
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {};
Expand All @@ -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);
Expand Down
63 changes: 31 additions & 32 deletions lib/Metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -27,7 +26,7 @@ class Metadata {
}
}

parse(string, callback, context) {
parse(string, callback) {
let doc;
try {
doc = new xmldoc.XmlDocument(string);
Expand All @@ -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);
});
Expand All @@ -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':
Expand All @@ -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() {
Expand All @@ -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) {
Expand Down
7 changes: 4 additions & 3 deletions lib/ParserCommon.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict'
/* eslint global-require: 0 */

class ParserCommon {
init(element) {
Expand Down Expand Up @@ -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);
});

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions lib/Reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
});
Expand Down
2 changes: 1 addition & 1 deletion lib/cache/csdlCache.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint accessor-pairs: 0 */
const fileCache = require('./fileCache');

const Metadata = require('../Metadata');

function CSDLCache(localDirs, useNetwork) {
Expand Down
6 changes: 3 additions & 3 deletions lib/cache/fileCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion test/corner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('<edmx:Edmx Version="4.0" xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx"><edmx:DataServices><Schema Namespace="Test1" xmlns="http://docs.oasis-open.org/odata/ns/edm"><EnumType Name="Test2"><Member Name="Test3"><Child Name="Test4"></Child></Member></EnumType></Schema></edmx:DataServices></edmx:Edmx>', {}, (error, meta) => {
assert.equal(error, null);
assert.notEqual(meta, null);
Expand Down
4 changes: 2 additions & 2 deletions test/redfish.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 1793778

Please sign in to comment.