Skip to content

Commit

Permalink
linting serverjs/cards.js
Browse files Browse the repository at this point in the history
  • Loading branch information
joshfinnie committed Feb 11, 2020
1 parent 5c939a5 commit 5f210f0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ rules:
no-param-reassign: off
no-underscore-dangle:
- error
- allow: ['_id']
- allow: ['_id', '_carddict']
camelcase:
- error
- properties: never
Expand Down
42 changes: 19 additions & 23 deletions serverjs/cards.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const fs = require('fs');
const util = require('./util.js');
const cardutil = require('../dist/utils/Card.js');

var data = {
const data = {
cardtree: {},
imagedict: {},
cardimages: {},
Expand All @@ -12,7 +12,8 @@ var data = {
english: {},
_carddict: {},
};
var fileToAttribute = {

const fileToAttribute = {
'carddict.json': '_carddict',
'cardtree.json': 'cardtree',
'names.json': 'cardnames',
Expand All @@ -24,9 +25,9 @@ var fileToAttribute = {
};

function getPlaceholderCard(_id) {
//placeholder card if we don't find the one due to a scryfall ID update bug
// placeholder card if we don't find the one due to a scryfall ID update bug
return {
_id: _id,
_id,
set: '',
collector_number: '',
promo: false,
Expand Down Expand Up @@ -55,13 +56,13 @@ function cardFromId(id, fields) {
if (data._carddict[id]) {
details = data._carddict[id];
} else {
console.log('Could not find card from id: ' + id);
console.log(`Could not find card from id: ${ id}`);
details = getPlaceholderCard(id);
}

if (typeof fields === 'undefined') {
return details;
} else if (!Array.isArray(fields)) {
} if (!Array.isArray(fields)) {
fields = fields.split(' ');
}

Expand All @@ -70,26 +71,26 @@ function cardFromId(id, fields) {

function getCardDetails(card) {
if (data._carddict[card.cardID]) {
var details = data._carddict[card.cardID];
const details = data._carddict[card.cardID];
card.details = details;
return details;
} else {
console.log('Could not find card details: ' + card.cardID);
}
console.log(`Could not find card details: ${ card.cardID}`);
return getPlaceholderCard(card.cardID);
}

}

function loadJSONFile(filename, attribute) {
return new Promise((resolve, reject) => {
fs.readFile(filename, 'utf8', function(err, contents) {
fs.readFile(filename, 'utf8', (err, contents) => {
if (!err) {
try {
data[attribute] = JSON.parse(contents);
} catch (e) {
console.log('Error parsing json from ', filename, ' : ', e);
err = e;
}
console.log(attribute + ' loaded');
console.log(`${attribute } loaded`);
}
if (err) {
reject(err);
Expand All @@ -101,8 +102,8 @@ function loadJSONFile(filename, attribute) {
}

function registerFileWatcher(filename, attribute) {
fs.watchFile(filename, (curr, prev) => {
console.log('File Changed: ' + filename);
fs.watchFile(filename, () => {
console.log(`File Changed: ${ filename}`);
loadJSONFile(filename, attribute);
});
}
Expand All @@ -111,12 +112,9 @@ function initializeCardDb(dataRoot, skipWatchers) {
if (dataRoot === undefined) {
dataRoot = 'private';
}
var promises = [],
filepath,
attribute;
for (var filename in fileToAttribute) {
filepath = dataRoot + '/' + filename;
attribute = fileToAttribute[filename];
const promises = [];
for (const [filename, attribute] of Object.values(fileToAttribute)) {
const filepath = `${dataRoot}/${filename}`;
promises.push(loadJSONFile(filepath, attribute));
if (skipWatchers !== true) {
registerFileWatcher(filepath, attribute);
Expand All @@ -126,9 +124,7 @@ function initializeCardDb(dataRoot, skipWatchers) {
}

function unloadCardDb() {
var attribute;
for (var filename in fileToAttribute) {
attribute = fileToAttribute[filename];
for (const attribute of Object.values(fileToAttribute)) {
delete data[attribute];
}
}
Expand Down

0 comments on commit 5f210f0

Please sign in to comment.