fix issues reported by eslint

This commit is contained in:
Jesse D. McDonald 2020-05-12 18:32:34 -05:00
parent e9ab6fa400
commit 5ee39d77c0
2 changed files with 29 additions and 46 deletions

19
.eslintrc.js Normal file
View File

@ -0,0 +1,19 @@
module.exports = {
"env": {
"commonjs": true,
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018
},
"rules": {
"no-console": "off",
"semi": "warn",
}
};

View File

@ -16,16 +16,6 @@ function monotonicTime() {
return mono;
}
var appendJournal = (function() {
let lastJournalText = null;
return function appendJournal(text) {
if (text !== lastJournalText) {
fs.appendFileSync('journal/journal.txt', text + '\n');
lastJournalText = text;
}
};
})();
function logDbError(label) {
return function(err) {
console.error(label + ':', ((err && err.message) || err));
@ -124,29 +114,7 @@ function waitForAnyGameUpdate() {
}
function waitFor(duration) {
return new Promise((resolve, reject) => setTimeout(() => { resolve(); }, duration));
}
function checkString(value, label, dflt) {
try {
if (arguments.length >= 3 && (value === undefined || value === null)) {
return dflt;
} else if (typeof value === 'string') {
return value;
}
} catch (err) {}
throw { message: `${label || 'value'} should be a string` };
}
function checkInteger(value, label, dflt) {
try {
if (arguments.length >= 3 && (value === undefined || value === null)) {
return dflt;
} else if (Number.isInteger(value)) {
return value;
}
} catch(err) {}
throw { message: `${label || 'value'} should be an integer` };
return new Promise((resolve) => setTimeout(() => { resolve(); }, duration));
}
function catchExceptionsJson(wrapped) {
@ -171,10 +139,10 @@ function catchExceptionsJson(wrapped) {
} catch (err) {
internalErrorJson(err);
}
}
};
}
async function getGameListHandler(req, res, next) {
async function getGameListHandler(req, res) {
res.set('Cache-Control', 'no-store');
const afterTime =
@ -191,7 +159,7 @@ async function getGameListHandler(req, res, next) {
const pollTimeout = waitFor(POLLING_TIMEOUT).then(() => 'timeout').catch(()=>{});
while (true) {
for (;;) {
/* Save the async promise _before_ the query so we don't miss any updates while suspended. */
const gameUpdate = waitForAnyGameUpdate().then(() => 'update');
@ -226,7 +194,7 @@ async function getGameListHandler(req, res, next) {
}
}
async function getGameHandler(req, res, next) {
async function getGameHandler(req, res) {
res.set('Cache-Control', 'no-store');
const gameId = req.params.gameId;
@ -248,7 +216,7 @@ async function getGameHandler(req, res, next) {
const pollTimeout = waitFor(POLLING_TIMEOUT).then(() => 'timeout').catch(()=>{});
while (true) {
for (;;) {
/* Save the async promise _before_ the query so we don't miss any updates while suspended. */
const gameUpdate = waitForGameUpdate(gameId).then(() => 'update');
@ -286,7 +254,7 @@ const updateTemplate = {
moves(x) { return Number.isInteger(x); },
status(x) { return typeof x === 'string'; },
timestamp(x) { return Number.isInteger(x); },
board(x) { return true; },
board(/*x*/) { return true; },
modified(x) { return Number.isInteger(x); },
};
@ -311,7 +279,7 @@ function validateUpdate(body) {
return body;
}
async function postGameHandler(req, res, next) {
async function postGameHandler(req, res) {
res.set('Cache-Control', 'no-store');
const gameId = req.params.gameId;
@ -344,8 +312,6 @@ async function postGameHandler(req, res, next) {
let setClause = '';
let whereClause = '';
let hasBoard = false;
let hasMeta = false;
for (const key in body) {
if (key !== 'modified') {
@ -354,10 +320,8 @@ async function postGameHandler(req, res, next) {
}
if (key === 'board') {
params['$' + key] = JSON.stringify(body[key]);
hasBoard = true;
} else {
params['$' + key] = body[key];
hasMeta = true;
}
if (setClause !== '') {
setClause += ', ';
@ -381,7 +345,7 @@ async function postGameHandler(req, res, next) {
ON CONFLICT (gameId) DO UPDATE SET ${setClause}, modified = $time
WHERE (${whereClause}) AND modified = $modified
`;
const selectSql = `SELECT * FROM games WHERE gameId = $gameId`
const selectSql = `SELECT * FROM games WHERE gameId = $gameId`;
let transactionP;
db.serialize(() => {
/* Important: We need to start all these queries without waiting in between. */
@ -445,7 +409,7 @@ try {
maxAge: 0,
}));
}
} catch (err) {}
} catch (err) {/*ignore*/}
var config = { port: process.env.OPENSHIFT_NODEJS_PORT || process.env.VCAP_APP_PORT || process.env.PORT || process.argv[2] || 8765 };