fix issues reported by eslint
This commit is contained in:
parent
04638e650d
commit
6dd6c2e3d6
|
|
@ -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",
|
||||
}
|
||||
};
|
||||
|
|
@ -90,6 +90,9 @@ export class Iterator {
|
|||
}
|
||||
|
||||
flatMap(f) {
|
||||
if (typeof f === 'undefined') {
|
||||
f = identity;
|
||||
}
|
||||
const next = this.next;
|
||||
let innerNext;
|
||||
|
||||
|
|
@ -108,7 +111,8 @@ export class Iterator {
|
|||
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);
|
||||
}
|
||||
});
|
||||
|
|
@ -194,6 +198,6 @@ export class Iterator {
|
|||
strictlyIncludes(x) {
|
||||
return this.some(function matches(y) { return y === x; });
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export default Iterator;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
import {Iterator} from './iterator.js';
|
||||
import {Buffer} from 'buffer';
|
||||
|
||||
/* Game states */
|
||||
const PLAYING = 'playing';
|
||||
|
|
@ -271,7 +272,7 @@ class Board {
|
|||
|
||||
function testFunction(getPiece, match) {
|
||||
if (match === undefined) {
|
||||
return function(here) { return true; }
|
||||
return function(/*here*/) { return true; };
|
||||
} else if (match === false) {
|
||||
return function(here) { return getPiece(here) === EMPTY; };
|
||||
} else if (match === true) {
|
||||
|
|
@ -286,7 +287,7 @@ class Board {
|
|||
const test = function(here) { return testSide(here) && testOther(here); };
|
||||
|
||||
if (this._phantom && this._phantom.side === side) {
|
||||
const getPhantom = (here) => this._phantom.type;
|
||||
const getPhantom = (/*here*/) => this._phantom.type;
|
||||
const testPhantom = testFunction(getPhantom, type);
|
||||
if (testPhantom(PHANTOM)) {
|
||||
yield this._phantom.from;
|
||||
|
|
@ -315,8 +316,8 @@ const KNIGHT_DIR =
|
|||
[-1, -2], [ 1, -2]];
|
||||
|
||||
const NBSP = '\u00a0'; /* non-breaking space */
|
||||
const SHY = '\u00ad' /* soft hyphen */
|
||||
const ZWSP = '\u200b'; /* zero-width space */
|
||||
const SHY = '\u00ad'; /* soft hyphen */
|
||||
/* const ZWSP = '\u200b'; */ /* zero-width space */
|
||||
|
||||
function addHistory(game) {
|
||||
const prior = game._undo;
|
||||
|
|
@ -748,8 +749,6 @@ class Game {
|
|||
/* 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 (type === BISHOP || type === ROOK || type === QUEEN) {
|
||||
const ortho = (type === ROOK || type === QUEEN);
|
||||
const diag = (type === BISHOP || type === QUEEN);
|
||||
const fromIndex = squareIndex(fromSquare);
|
||||
const toIndex = squareIndex(to);
|
||||
const rowsDiff = (toIndex >>> 3) - (fromIndex >>> 3);
|
||||
|
|
@ -833,7 +832,7 @@ class Game {
|
|||
try {
|
||||
sim.move(from, king);
|
||||
check = diffHistory(this, sim) || true;
|
||||
} catch(err) {}
|
||||
} catch(err) {/*ignore*/}
|
||||
}
|
||||
return recordCheck(this, check);
|
||||
}
|
||||
|
|
@ -889,7 +888,7 @@ class Game {
|
|||
try {
|
||||
game2.move(PHANTOM, king);
|
||||
check = diffHistory(this, game2) || true;
|
||||
} catch(err) {}
|
||||
} catch(err) {/*ignore*/}
|
||||
}
|
||||
return recordCheck(this, check);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ const meta = {
|
|||
};
|
||||
|
||||
const stateListeners = {};
|
||||
const stateNextId = 1;
|
||||
let stateNextId = 1;
|
||||
|
||||
/* One-time request, no caching or polling */
|
||||
function getGameState(gameId, retries) {
|
||||
|
|
@ -37,7 +37,7 @@ function getGameState(gameId, retries) {
|
|||
url: `${API_BASE}/game/${gameId}`,
|
||||
cache: false,
|
||||
timeout: SHORT_TIMEOUT,
|
||||
}).done((data, textStatus, jqXHR) => {
|
||||
}).done((data/*, textStatus, jqXHR*/) => {
|
||||
resolve(data);
|
||||
}).fail((jqXHR, textStatus, errorThrown) => {
|
||||
if ((!jqXHR.status || jqXHR.status < 400 || jqXHR.status > 499) && retries > 0) {
|
||||
|
|
@ -63,7 +63,7 @@ function getGameMeta(gameId, retries) {
|
|||
url: `${API_BASE}/meta/${gameId}`,
|
||||
cache: false,
|
||||
timeout: SHORT_TIMEOUT,
|
||||
}).done((data, textStatus, jqXHR) => {
|
||||
}).done((data/*, textStatus, jqXHR*/) => {
|
||||
resolve(data);
|
||||
}).fail((jqXHR, textStatus, errorThrown) => {
|
||||
if ((!jqXHR.status || jqXHR.status < 400 || jqXHR.status > 499) && retries > 0) {
|
||||
|
|
@ -106,7 +106,7 @@ function onGameUpdate(gameId, callback) {
|
|||
stopGamePoll(gameId);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function getCachedGame(gameId) {
|
||||
|
|
@ -150,7 +150,7 @@ function onMetaUpdate(callback) {
|
|||
stopMetaPoll();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function sendUpdate(gameId, data, retries) {
|
||||
|
|
@ -306,7 +306,7 @@ function startGamePoll(gameId, afterTime) {
|
|||
setConnectionState(game, 'polling');
|
||||
startGamePoll(gameId, afterTime);
|
||||
}
|
||||
}).fail((jqXHR, textStatus, errorThrown) => {
|
||||
}).fail((/*jqXHR, textStatus, errorThrown*/) => {
|
||||
if (game.currentRequest === thisRequest) {
|
||||
setConnectionState(game, 'failed');
|
||||
setTimeout(() => {
|
||||
|
|
@ -383,7 +383,7 @@ function startMetaPoll(afterTime) {
|
|||
setConnectionState('polling');
|
||||
startMetaPoll(afterTime);
|
||||
}
|
||||
}).fail((jqXHR, textStatus, errorThrown) => {
|
||||
}).fail((/*jqXHR, textStatus, errorThrown*/) => {
|
||||
if (meta.currentRequest === thisRequest) {
|
||||
setConnectionState('failed');
|
||||
setTimeout(() => {
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ $(function (){
|
|||
square.hide().appendTo('body').droppable({
|
||||
accept: '.cb-piece',
|
||||
disabled: true,
|
||||
deactivate: function(ev, ui){
|
||||
deactivate: function(/*ev, ui*/) {
|
||||
$(this).droppable('disable');
|
||||
},
|
||||
drop: squareDropDestination,
|
||||
|
|
@ -105,7 +105,7 @@ $(function (){
|
|||
}
|
||||
return square;
|
||||
} else if (where.match(/^[a-h][1-8]$/)) {
|
||||
return $('#cb_' + where).first()
|
||||
return $('#cb_' + where).first();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -139,7 +139,6 @@ $(function (){
|
|||
|
||||
function pieceStartMove(piece, event) {
|
||||
const side = piece.data('side');
|
||||
const type = piece.data('type');
|
||||
const from = piece.data('location');
|
||||
const legals = currentGame.legalMoves(side, from);
|
||||
for (const there of legals) {
|
||||
|
|
@ -148,7 +147,7 @@ $(function (){
|
|||
}
|
||||
|
||||
const square = cbSquare(there);
|
||||
square.addClass('cb-legal')
|
||||
square.addClass('cb-legal');
|
||||
if (event === 'drag') {
|
||||
square.droppable('enable');
|
||||
} else if (event === 'click') {
|
||||
|
|
@ -177,7 +176,7 @@ $(function (){
|
|||
putState();
|
||||
}
|
||||
|
||||
function squareClickDestination(ev, ui) {
|
||||
function squareClickDestination(/*ev, ui*/) {
|
||||
let selected = $('#cb_board .cb-selected');
|
||||
if (selected.length !== 1) {
|
||||
renderBoard();
|
||||
|
|
@ -196,11 +195,11 @@ $(function (){
|
|||
}
|
||||
}
|
||||
|
||||
function squareClickUnselect(ev, ui) {
|
||||
function squareClickUnselect(/*ev, ui*/) {
|
||||
renderBoard();
|
||||
}
|
||||
|
||||
function squareClickSelect(ev, ui) {
|
||||
function squareClickSelect(/*ev, ui*/) {
|
||||
renderBoard();
|
||||
const clicked = $(this).children('.cb-piece.ui-draggable').not('.ui-draggable-disabled');
|
||||
clicked.addClass('cb-selected');
|
||||
|
|
@ -214,7 +213,7 @@ $(function (){
|
|||
}
|
||||
}
|
||||
|
||||
function pieceStartDrag(ev, ui) {
|
||||
function pieceStartDrag(/*ev, ui*/) {
|
||||
const dragged = $(this);
|
||||
$('#cb_board .cb-selected').removeClass('cb-selected');
|
||||
$('#cb_board .cb-legal').removeClass('cb-legal');
|
||||
|
|
@ -223,7 +222,7 @@ $(function (){
|
|||
pieceStartMove(dragged, 'drag');
|
||||
}
|
||||
|
||||
function pieceStopDrag(ev, ui) {
|
||||
function pieceStopDrag(/*ev, ui*/) {
|
||||
const dragged = $(this);
|
||||
dragged.attr('style', dragged.data('saved-style'));
|
||||
dragged.removeData('saved-style');
|
||||
|
|
@ -340,7 +339,7 @@ $(function (){
|
|||
pieceStartMove(piece, 'click');
|
||||
}
|
||||
} else if (liveView && playing) {
|
||||
const pieces = $('#cb_board .' + clss)
|
||||
const pieces = $('#cb_board .' + clss);
|
||||
pieces.parent().on('click.select', squareClickSelect);
|
||||
pieces.draggable('enable');
|
||||
}
|
||||
|
|
@ -467,7 +466,6 @@ $(function (){
|
|||
signal_idle: function() {},
|
||||
|
||||
add(gameId, data, modified) {
|
||||
const wasEmpty = this.isEmpty();
|
||||
data = Object.assign({}, data, { modified });
|
||||
|
||||
this[this.tail] = { gameId, data };
|
||||
|
|
@ -577,7 +575,6 @@ $(function (){
|
|||
|
||||
function putState() {
|
||||
const boardElem = $('#cb_board');
|
||||
const gameId = boardElem.data('gameId');
|
||||
notifyLocalMove(currentGame, boardElem.data('gameId'));
|
||||
putMeta({ board: JSON.parse(currentGame.toJSON()) });
|
||||
}
|
||||
|
|
@ -649,7 +646,7 @@ $(function (){
|
|||
$('#cb_light_name').val('');
|
||||
$('#cb_dark_name').val('');
|
||||
|
||||
cancelGameCallback = IO.onGameUpdate(newId, function(data, gameId) {
|
||||
cancelGameCallback = IO.onGameUpdate(newId, function(data/*, gameId*/) {
|
||||
updateQueue.idle.then(() => {
|
||||
if (data.modified > $('#cb_board').data('modified')) {
|
||||
try {
|
||||
|
|
@ -723,7 +720,7 @@ $(function (){
|
|||
const notifyAudio = new Audio(Waterdrop);
|
||||
|
||||
function playNotifySound(){
|
||||
try { notifyAudio.play(); } catch (err) {}
|
||||
try { notifyAudio.play(); } catch (err) {/*ignore*/}
|
||||
}
|
||||
|
||||
function notify(body) {
|
||||
|
|
@ -756,7 +753,7 @@ $(function (){
|
|||
notification.close();
|
||||
}
|
||||
}
|
||||
} catch (err) {}
|
||||
} catch (err) {/*ignore*/}
|
||||
}
|
||||
|
||||
function arrangeBoard(reversed) {
|
||||
|
|
@ -818,11 +815,11 @@ $(function (){
|
|||
}
|
||||
}
|
||||
|
||||
function reloadForUpdate(event) {
|
||||
function reloadForUpdate(/*event*/) {
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
wb.addEventListener('installed', (event) => {
|
||||
wb.addEventListener('installed', (/*event*/) => {
|
||||
try {
|
||||
if (Notification.permission === 'denied') {
|
||||
disableNotify();
|
||||
|
|
@ -839,6 +836,7 @@ $(function (){
|
|||
wb.addEventListener('externalactivated', reloadForUpdate);
|
||||
|
||||
const registration = await wb.register();
|
||||
await registration.ready;
|
||||
|
||||
/* Check for updates every 4h without reloading the page. */
|
||||
setInterval(() => { wb.update(); }, 4*3600*1000);
|
||||
|
|
@ -861,7 +859,7 @@ $(function (){
|
|||
let gameList = undefined;
|
||||
const gameId = $('#cb_board').data('gameId');
|
||||
if (value === 'on') {
|
||||
gameList = ['*']
|
||||
gameList = ['*'];
|
||||
} else if (value === null || value === 'off') {
|
||||
gameList = [];
|
||||
} else {
|
||||
|
|
@ -920,7 +918,7 @@ $(function (){
|
|||
applyTheme(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$(window).on('storage', function(event){
|
||||
fromStorage(event.originalEvent.key, event.originalEvent.newValue);
|
||||
|
|
@ -935,7 +933,7 @@ $(function (){
|
|||
$('.cb-square').droppable({
|
||||
accept: '.cb-piece',
|
||||
disabled: true,
|
||||
deactivate: function(ev, ui){
|
||||
deactivate: function(/*ev, ui*/){
|
||||
$(this).droppable('disable');
|
||||
},
|
||||
drop: squareDropDestination,
|
||||
|
|
@ -1347,7 +1345,7 @@ $(function (){
|
|||
|
||||
IO.onMetaUpdate(notifyForGame);
|
||||
|
||||
window.onpopstate = function(event){
|
||||
window.onpopstate = function(/*event*/){
|
||||
const foundId = location.hash.match(/^#\/([0-9a-f]{16}\b)/);
|
||||
if (foundId) {
|
||||
switchGameId(foundId[1]);
|
||||
|
|
|
|||
|
|
@ -6718,6 +6718,17 @@
|
|||
"vm-browserify": "^1.0.1"
|
||||
},
|
||||
"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": {
|
||||
"version": "1.4.1",
|
||||
"resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz",
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"@fortawesome/fontawesome-free": "^5.13.0",
|
||||
"buffer": "^4.9.2",
|
||||
"clean-webpack-plugin": "^3.0.0",
|
||||
"copy-webpack-plugin": "^5.1.1",
|
||||
"css-element-queries": "^1.2.3",
|
||||
|
|
|
|||
Loading…
Reference in New Issue