fix issues reported by eslint

This commit is contained in:
Jesse D. McDonald 2020-05-12 18:26:05 -05:00
parent 04638e650d
commit 6dd6c2e3d6
7 changed files with 72 additions and 38 deletions

21
.eslintrc.js Normal file
View File

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

View File

@ -90,6 +90,9 @@ export class Iterator {
} }
flatMap(f) { flatMap(f) {
if (typeof f === 'undefined') {
f = identity;
}
const next = this.next; const next = this.next;
let innerNext; let innerNext;
@ -108,7 +111,8 @@ export class Iterator {
return z; return z;
} }
const iter = y.value.__proto__[Symbol.iterator].call(y.value); const mapped = f(z.value);
const iter = mapped.__proto__[Symbol.iterator].call(mapped);
innerNext = iter.next.bind(iter); innerNext = iter.next.bind(iter);
} }
}); });
@ -194,6 +198,6 @@ export class Iterator {
strictlyIncludes(x) { strictlyIncludes(x) {
return this.some(function matches(y) { return y === x; }); return this.some(function matches(y) { return y === x; });
} }
}; }
export default Iterator; export default Iterator;

View File

@ -1,6 +1,7 @@
'use strict'; 'use strict';
import {Iterator} from './iterator.js'; import {Iterator} from './iterator.js';
import {Buffer} from 'buffer';
/* Game states */ /* Game states */
const PLAYING = 'playing'; const PLAYING = 'playing';
@ -271,7 +272,7 @@ class Board {
function testFunction(getPiece, match) { function testFunction(getPiece, match) {
if (match === undefined) { if (match === undefined) {
return function(here) { return true; } return function(/*here*/) { return true; };
} else if (match === false) { } else if (match === false) {
return function(here) { return getPiece(here) === EMPTY; }; return function(here) { return getPiece(here) === EMPTY; };
} else if (match === true) { } else if (match === true) {
@ -286,7 +287,7 @@ class Board {
const test = function(here) { return testSide(here) && testOther(here); }; const test = function(here) { return testSide(here) && testOther(here); };
if (this._phantom && this._phantom.side === side) { if (this._phantom && this._phantom.side === side) {
const getPhantom = (here) => this._phantom.type; const getPhantom = (/*here*/) => this._phantom.type;
const testPhantom = testFunction(getPhantom, type); const testPhantom = testFunction(getPhantom, type);
if (testPhantom(PHANTOM)) { if (testPhantom(PHANTOM)) {
yield this._phantom.from; yield this._phantom.from;
@ -315,8 +316,8 @@ const KNIGHT_DIR =
[-1, -2], [ 1, -2]]; [-1, -2], [ 1, -2]];
const NBSP = '\u00a0'; /* non-breaking space */ const NBSP = '\u00a0'; /* non-breaking space */
const SHY = '\u00ad' /* soft hyphen */ const SHY = '\u00ad'; /* soft hyphen */
const ZWSP = '\u200b'; /* zero-width space */ /* const ZWSP = '\u200b'; */ /* zero-width space */
function addHistory(game) { function addHistory(game) {
const prior = game._undo; const prior = game._undo;
@ -748,8 +749,6 @@ class Game {
/* if a piece has few moves (king, pawn, knight) then just enumerate them */ /* if a piece has few moves (king, pawn, knight) then just enumerate them */
/* if movement is more extensive (bishop, rook, queen) then we can do better */ /* if movement is more extensive (bishop, rook, queen) then we can do better */
if (type === BISHOP || type === ROOK || type === QUEEN) { if (type === BISHOP || type === ROOK || type === QUEEN) {
const ortho = (type === ROOK || type === QUEEN);
const diag = (type === BISHOP || type === QUEEN);
const fromIndex = squareIndex(fromSquare); const fromIndex = squareIndex(fromSquare);
const toIndex = squareIndex(to); const toIndex = squareIndex(to);
const rowsDiff = (toIndex >>> 3) - (fromIndex >>> 3); const rowsDiff = (toIndex >>> 3) - (fromIndex >>> 3);
@ -833,7 +832,7 @@ class Game {
try { try {
sim.move(from, king); sim.move(from, king);
check = diffHistory(this, sim) || true; check = diffHistory(this, sim) || true;
} catch(err) {} } catch(err) {/*ignore*/}
} }
return recordCheck(this, check); return recordCheck(this, check);
} }
@ -889,7 +888,7 @@ class Game {
try { try {
game2.move(PHANTOM, king); game2.move(PHANTOM, king);
check = diffHistory(this, game2) || true; check = diffHistory(this, game2) || true;
} catch(err) {} } catch(err) {/*ignore*/}
} }
return recordCheck(this, check); return recordCheck(this, check);
} }

View File

@ -23,7 +23,7 @@ const meta = {
}; };
const stateListeners = {}; const stateListeners = {};
const stateNextId = 1; let stateNextId = 1;
/* One-time request, no caching or polling */ /* One-time request, no caching or polling */
function getGameState(gameId, retries) { function getGameState(gameId, retries) {
@ -37,7 +37,7 @@ function getGameState(gameId, retries) {
url: `${API_BASE}/game/${gameId}`, url: `${API_BASE}/game/${gameId}`,
cache: false, cache: false,
timeout: SHORT_TIMEOUT, timeout: SHORT_TIMEOUT,
}).done((data, textStatus, jqXHR) => { }).done((data/*, textStatus, jqXHR*/) => {
resolve(data); resolve(data);
}).fail((jqXHR, textStatus, errorThrown) => { }).fail((jqXHR, textStatus, errorThrown) => {
if ((!jqXHR.status || jqXHR.status < 400 || jqXHR.status > 499) && retries > 0) { if ((!jqXHR.status || jqXHR.status < 400 || jqXHR.status > 499) && retries > 0) {
@ -63,7 +63,7 @@ function getGameMeta(gameId, retries) {
url: `${API_BASE}/meta/${gameId}`, url: `${API_BASE}/meta/${gameId}`,
cache: false, cache: false,
timeout: SHORT_TIMEOUT, timeout: SHORT_TIMEOUT,
}).done((data, textStatus, jqXHR) => { }).done((data/*, textStatus, jqXHR*/) => {
resolve(data); resolve(data);
}).fail((jqXHR, textStatus, errorThrown) => { }).fail((jqXHR, textStatus, errorThrown) => {
if ((!jqXHR.status || jqXHR.status < 400 || jqXHR.status > 499) && retries > 0) { if ((!jqXHR.status || jqXHR.status < 400 || jqXHR.status > 499) && retries > 0) {
@ -106,7 +106,7 @@ function onGameUpdate(gameId, callback) {
stopGamePoll(gameId); stopGamePoll(gameId);
} }
} }
} };
} }
function getCachedGame(gameId) { function getCachedGame(gameId) {
@ -150,7 +150,7 @@ function onMetaUpdate(callback) {
stopMetaPoll(); stopMetaPoll();
} }
} }
} };
} }
function sendUpdate(gameId, data, retries) { function sendUpdate(gameId, data, retries) {
@ -306,7 +306,7 @@ function startGamePoll(gameId, afterTime) {
setConnectionState(game, 'polling'); setConnectionState(game, 'polling');
startGamePoll(gameId, afterTime); startGamePoll(gameId, afterTime);
} }
}).fail((jqXHR, textStatus, errorThrown) => { }).fail((/*jqXHR, textStatus, errorThrown*/) => {
if (game.currentRequest === thisRequest) { if (game.currentRequest === thisRequest) {
setConnectionState(game, 'failed'); setConnectionState(game, 'failed');
setTimeout(() => { setTimeout(() => {
@ -383,7 +383,7 @@ function startMetaPoll(afterTime) {
setConnectionState('polling'); setConnectionState('polling');
startMetaPoll(afterTime); startMetaPoll(afterTime);
} }
}).fail((jqXHR, textStatus, errorThrown) => { }).fail((/*jqXHR, textStatus, errorThrown*/) => {
if (meta.currentRequest === thisRequest) { if (meta.currentRequest === thisRequest) {
setConnectionState('failed'); setConnectionState('failed');
setTimeout(() => { setTimeout(() => {

View File

@ -97,7 +97,7 @@ $(function (){
square.hide().appendTo('body').droppable({ square.hide().appendTo('body').droppable({
accept: '.cb-piece', accept: '.cb-piece',
disabled: true, disabled: true,
deactivate: function(ev, ui){ deactivate: function(/*ev, ui*/) {
$(this).droppable('disable'); $(this).droppable('disable');
}, },
drop: squareDropDestination, drop: squareDropDestination,
@ -105,7 +105,7 @@ $(function (){
} }
return square; return square;
} else if (where.match(/^[a-h][1-8]$/)) { } else if (where.match(/^[a-h][1-8]$/)) {
return $('#cb_' + where).first() return $('#cb_' + where).first();
} else { } else {
return null; return null;
} }
@ -139,7 +139,6 @@ $(function (){
function pieceStartMove(piece, event) { function pieceStartMove(piece, event) {
const side = piece.data('side'); const side = piece.data('side');
const type = piece.data('type');
const from = piece.data('location'); const from = piece.data('location');
const legals = currentGame.legalMoves(side, from); const legals = currentGame.legalMoves(side, from);
for (const there of legals) { for (const there of legals) {
@ -148,7 +147,7 @@ $(function (){
} }
const square = cbSquare(there); const square = cbSquare(there);
square.addClass('cb-legal') square.addClass('cb-legal');
if (event === 'drag') { if (event === 'drag') {
square.droppable('enable'); square.droppable('enable');
} else if (event === 'click') { } else if (event === 'click') {
@ -177,7 +176,7 @@ $(function (){
putState(); putState();
} }
function squareClickDestination(ev, ui) { function squareClickDestination(/*ev, ui*/) {
let selected = $('#cb_board .cb-selected'); let selected = $('#cb_board .cb-selected');
if (selected.length !== 1) { if (selected.length !== 1) {
renderBoard(); renderBoard();
@ -196,11 +195,11 @@ $(function (){
} }
} }
function squareClickUnselect(ev, ui) { function squareClickUnselect(/*ev, ui*/) {
renderBoard(); renderBoard();
} }
function squareClickSelect(ev, ui) { function squareClickSelect(/*ev, ui*/) {
renderBoard(); renderBoard();
const clicked = $(this).children('.cb-piece.ui-draggable').not('.ui-draggable-disabled'); const clicked = $(this).children('.cb-piece.ui-draggable').not('.ui-draggable-disabled');
clicked.addClass('cb-selected'); clicked.addClass('cb-selected');
@ -214,7 +213,7 @@ $(function (){
} }
} }
function pieceStartDrag(ev, ui) { function pieceStartDrag(/*ev, ui*/) {
const dragged = $(this); const dragged = $(this);
$('#cb_board .cb-selected').removeClass('cb-selected'); $('#cb_board .cb-selected').removeClass('cb-selected');
$('#cb_board .cb-legal').removeClass('cb-legal'); $('#cb_board .cb-legal').removeClass('cb-legal');
@ -223,7 +222,7 @@ $(function (){
pieceStartMove(dragged, 'drag'); pieceStartMove(dragged, 'drag');
} }
function pieceStopDrag(ev, ui) { function pieceStopDrag(/*ev, ui*/) {
const dragged = $(this); const dragged = $(this);
dragged.attr('style', dragged.data('saved-style')); dragged.attr('style', dragged.data('saved-style'));
dragged.removeData('saved-style'); dragged.removeData('saved-style');
@ -340,7 +339,7 @@ $(function (){
pieceStartMove(piece, 'click'); pieceStartMove(piece, 'click');
} }
} else if (liveView && playing) { } else if (liveView && playing) {
const pieces = $('#cb_board .' + clss) const pieces = $('#cb_board .' + clss);
pieces.parent().on('click.select', squareClickSelect); pieces.parent().on('click.select', squareClickSelect);
pieces.draggable('enable'); pieces.draggable('enable');
} }
@ -467,7 +466,6 @@ $(function (){
signal_idle: function() {}, signal_idle: function() {},
add(gameId, data, modified) { add(gameId, data, modified) {
const wasEmpty = this.isEmpty();
data = Object.assign({}, data, { modified }); data = Object.assign({}, data, { modified });
this[this.tail] = { gameId, data }; this[this.tail] = { gameId, data };
@ -577,7 +575,6 @@ $(function (){
function putState() { function putState() {
const boardElem = $('#cb_board'); const boardElem = $('#cb_board');
const gameId = boardElem.data('gameId');
notifyLocalMove(currentGame, boardElem.data('gameId')); notifyLocalMove(currentGame, boardElem.data('gameId'));
putMeta({ board: JSON.parse(currentGame.toJSON()) }); putMeta({ board: JSON.parse(currentGame.toJSON()) });
} }
@ -649,7 +646,7 @@ $(function (){
$('#cb_light_name').val(''); $('#cb_light_name').val('');
$('#cb_dark_name').val(''); $('#cb_dark_name').val('');
cancelGameCallback = IO.onGameUpdate(newId, function(data, gameId) { cancelGameCallback = IO.onGameUpdate(newId, function(data/*, gameId*/) {
updateQueue.idle.then(() => { updateQueue.idle.then(() => {
if (data.modified > $('#cb_board').data('modified')) { if (data.modified > $('#cb_board').data('modified')) {
try { try {
@ -723,7 +720,7 @@ $(function (){
const notifyAudio = new Audio(Waterdrop); const notifyAudio = new Audio(Waterdrop);
function playNotifySound(){ function playNotifySound(){
try { notifyAudio.play(); } catch (err) {} try { notifyAudio.play(); } catch (err) {/*ignore*/}
} }
function notify(body) { function notify(body) {
@ -756,7 +753,7 @@ $(function (){
notification.close(); notification.close();
} }
} }
} catch (err) {} } catch (err) {/*ignore*/}
} }
function arrangeBoard(reversed) { function arrangeBoard(reversed) {
@ -818,11 +815,11 @@ $(function (){
} }
} }
function reloadForUpdate(event) { function reloadForUpdate(/*event*/) {
window.location.reload(); window.location.reload();
} }
wb.addEventListener('installed', (event) => { wb.addEventListener('installed', (/*event*/) => {
try { try {
if (Notification.permission === 'denied') { if (Notification.permission === 'denied') {
disableNotify(); disableNotify();
@ -839,6 +836,7 @@ $(function (){
wb.addEventListener('externalactivated', reloadForUpdate); wb.addEventListener('externalactivated', reloadForUpdate);
const registration = await wb.register(); const registration = await wb.register();
await registration.ready;
/* Check for updates every 4h without reloading the page. */ /* Check for updates every 4h without reloading the page. */
setInterval(() => { wb.update(); }, 4*3600*1000); setInterval(() => { wb.update(); }, 4*3600*1000);
@ -861,7 +859,7 @@ $(function (){
let gameList = undefined; let gameList = undefined;
const gameId = $('#cb_board').data('gameId'); const gameId = $('#cb_board').data('gameId');
if (value === 'on') { if (value === 'on') {
gameList = ['*'] gameList = ['*'];
} else if (value === null || value === 'off') { } else if (value === null || value === 'off') {
gameList = []; gameList = [];
} else { } else {
@ -920,7 +918,7 @@ $(function (){
applyTheme(value); applyTheme(value);
} }
} }
} };
$(window).on('storage', function(event){ $(window).on('storage', function(event){
fromStorage(event.originalEvent.key, event.originalEvent.newValue); fromStorage(event.originalEvent.key, event.originalEvent.newValue);
@ -935,7 +933,7 @@ $(function (){
$('.cb-square').droppable({ $('.cb-square').droppable({
accept: '.cb-piece', accept: '.cb-piece',
disabled: true, disabled: true,
deactivate: function(ev, ui){ deactivate: function(/*ev, ui*/){
$(this).droppable('disable'); $(this).droppable('disable');
}, },
drop: squareDropDestination, drop: squareDropDestination,
@ -1347,7 +1345,7 @@ $(function (){
IO.onMetaUpdate(notifyForGame); IO.onMetaUpdate(notifyForGame);
window.onpopstate = function(event){ window.onpopstate = function(/*event*/){
const foundId = location.hash.match(/^#\/([0-9a-f]{16}\b)/); const foundId = location.hash.match(/^#\/([0-9a-f]{16}\b)/);
if (foundId) { if (foundId) {
switchGameId(foundId[1]); switchGameId(foundId[1]);

11
package-lock.json generated
View File

@ -6718,6 +6718,17 @@
"vm-browserify": "^1.0.1" "vm-browserify": "^1.0.1"
}, },
"dependencies": { "dependencies": {
"buffer": {
"version": "4.9.2",
"resolved": "https://registry.npmjs.org/buffer/-/buffer-4.9.2.tgz",
"integrity": "sha512-xq+q3SRMOxGivLhBNaUdC64hDTQwejJ+H0T/NB1XMtTVEwNTrfFF3gAxiyW0Bu/xWEGhjVKgUcMhCrUy2+uCWg==",
"dev": true,
"requires": {
"base64-js": "^1.0.2",
"ieee754": "^1.1.4",
"isarray": "^1.0.0"
}
},
"punycode": { "punycode": {
"version": "1.4.1", "version": "1.4.1",
"resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz", "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz",

View File

@ -32,6 +32,7 @@
}, },
"devDependencies": { "devDependencies": {
"@fortawesome/fontawesome-free": "^5.13.0", "@fortawesome/fontawesome-free": "^5.13.0",
"buffer": "^4.9.2",
"clean-webpack-plugin": "^3.0.0", "clean-webpack-plugin": "^3.0.0",
"copy-webpack-plugin": "^5.1.1", "copy-webpack-plugin": "^5.1.1",
"css-element-queries": "^1.2.3", "css-element-queries": "^1.2.3",