From: Laurent Mazet Date: Sat, 4 Jul 2020 13:41:23 +0000 (+0200) Subject: correct errors reported by eslint X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=62edfe07e1192bc367fde6ea8d6357c030b21744;p=trivabble.git correct errors reported by eslint --- diff --git a/public/trivabble.js b/public/trivabble.js index b6b0433..92199b8 100644 --- a/public/trivabble.js +++ b/public/trivabble.js @@ -1519,7 +1519,7 @@ } /* Look for last letter in line */ - let word = {letters: "", row: row, col: col, incRow: incRow, incCol: incCol}; + const word = {letters: "", row: row, col: col, incRow: incRow, incCol: incCol}; let letter; while ((letter = getLetterFromBoard(row, col)) !== "") { word.letters += letter; @@ -1578,17 +1578,22 @@ } function modifyTileClass(word, value, action) { + /* action: true for add, false for remove */ + if (action) { + /* only for new words */ for (let l = 0; l < word.letters.length; l++) { - const index = ((word.row + l * word.incRow) * 15) + word.col + l * word.incCol; + const index = ((word.row + (l * word.incRow)) * 15) + word.col + (l * word.incCol); const tilePlaceholder = boardCells[index].getElementsByClassName("tile-placeholder")[0]; const tile = tilePlaceholder.getElementsByClassName("tile")[0]; tile.classList.add(value); } + } else { + /* tiles on board */ for (let index = 0; index < 15 * 15; index++) { const tilePlaceholder = boardCells[index].getElementsByClassName("tile-placeholder")[0]; @@ -1597,13 +1602,15 @@ tile.classList.remove(value); } } + /* tiles on rack */ - for (let tilePlaceholder of rack.getElementsByClassName("tile-placeholder")) { + for (const tilePlaceholder of rack.getElementsByClassName("tile-placeholder")) { const tile = tilePlaceholder.getElementsByClassName("tile")[0]; if (typeof tile !== "undefined") { tile.classList.remove(value); } } + /* tile on the move */ if (movingTile !== null) { movingTile.classList.remove(value); @@ -1613,7 +1620,7 @@ function checkSpelling() { - let newWords = searchNewWords(); + const newWords = searchNewWords(); if (newWords.length === 0) { myAlert(_("No new word found")); return; @@ -1623,12 +1630,12 @@ let words = []; let badWords = []; for (const k of Object.keys(newWords)) { - let currentWord = newWords[k].letters.replace(/ /g, "?"); + const currentWord = newWords[k].letters.replace(/ /gu, "?"); if (words.indexOf(currentWord) === -1) { words.push(currentWord); } modifyTileClass(newWords[k], "tile-spelling-ok", true); - const pattern = "^" + newWords[k].letters.replace(/ /g, ".") + "$"; + const pattern = "^" + newWords[k].letters.replace(/ /gu, ".") + "$"; if (!dictionary.find(function (word) {return word.match(pattern);})) { if (badWords.indexOf(currentWord) === -1) { badWords.push(currentWord); @@ -1636,7 +1643,8 @@ modifyTileClass(newWords[k], "tile-spelling-nok", true); } } - setTimeout(function () { + setTimeout( + function () { modifyTileClass(null, "tile-spelling-ok", false); modifyTileClass(null, "tile-spelling-nok", false); }, 5000);