fixed most lint errors

This commit is contained in:
typer 2020-11-02 17:32:27 -08:00
parent 56e2910a4d
commit e70d38f541
10 changed files with 494 additions and 986 deletions

View file

@ -54,7 +54,7 @@ task("rebuild", series("clean", "build"));
let eslintConfig = {
parser: "babel-eslint",
extends: "eslint:recommended",
globals: ["jQuery", "$", "firebase"],
globals: ["jQuery", "$", "firebase", "moment"],
envs: ["es6", "browser", "node"],
rules: {
"constructor-super": "error",

1268
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -17,7 +17,7 @@
"concurrently": "^5.3.0",
"dart-sass": "^1.25.0",
"del": "^6.0.0",
"eslint": "^6.0.0",
"eslint": "^6.8.0",
"gulp": "^4.0.2",
"gulp-concat": "^2.6.1",
"gulp-eslint": "^6.0.0",

View file

@ -200,13 +200,13 @@ function signUp() {
.catch(function (error) {
// An error happened.
$(".pageLogin .preloader").addClass("hidden");
console.error(error);
});
});
})
.catch(function (error) {
// Handle Errors here.
$(".pageLogin .register .button").removeClass("disabled");
var errorCode = error.code;
var errorMessage = error.message;
showNotification(errorMessage, 5000);
$(".pageLogin .preloader").addClass("hidden");
@ -1763,7 +1763,7 @@ let visibleTableLines = 0;
function loadMoreLines() {
if (filteredResults == [] || filteredResults.length == 0) return;
for (let i = visibleTableLines; i < visibleTableLines + 10; i++) {
result = filteredResults[i];
const result = filteredResults[i];
if (result == undefined) continue;
let withpunc = "";
// if (result.punctuation) {
@ -1911,7 +1911,7 @@ function refreshGlobalStats() {
let tm = Math.floor((dbSnapshot.globalStats.time % 3600) / 60);
let ts = Math.floor((dbSnapshot.globalStats.time % 3600) % 60);
$(".pageAccount .globalTimeTyping .val").text(`
${th < 10 ? "0" + th : th}:${tm < 10 ? "0" + tm : tm}:${
ts < 10 ? "0" + ts : ts
}
@ -1939,7 +1939,8 @@ function refreshAccountPage() {
let chartData = [];
let wpmChartData = [];
let rawChartData = [];
//TODO: is this used?
//let rawChartData = [];
let accChartData = [];
visibleTableLines = 0;
@ -1970,7 +1971,8 @@ function refreshAccountPage() {
let totalCons10 = 0;
let consCount = 0;
let dailyActivityDays = [];
//TODO: is this used?
//let dailyActivityDays = [];
let activityChartData = {};
filteredResults = [];
@ -2365,7 +2367,7 @@ function refreshAccountPage() {
let tm = Math.floor((totalSeconds % 3600) / 60);
let ts = Math.floor((totalSeconds % 3600) % 60);
$(".pageAccount .timeTotal .val").text(`
${th < 10 ? "0" + th : th}:${tm < 10 ? "0" + tm : tm}:${
ts < 10 ? "0" + ts : ts
}
@ -2377,7 +2379,7 @@ function refreshAccountPage() {
let tfm = Math.floor((totalSecondsFiltered % 3600) / 60);
let tfs = Math.floor((totalSecondsFiltered % 3600) % 60);
$(".pageAccount .timeTotalFiltered .val").text(`
${tfh < 10 ? "0" + tfh : tfh}:${tfm < 10 ? "0" + tfm : tfm}:${
tfs < 10 ? "0" + tfs : tfs
}
@ -2500,7 +2502,7 @@ function refreshAccountPage() {
// cont();
showActiveFilters();
} else {
setTimeout((f) => {
setTimeout(() => {
changePage("");
}, 500);
// console.log("something went wrong");

View file

@ -9,7 +9,7 @@ function addChildCommands(
if (commandItem.subgroup) {
try {
commandItem.exec();
currentCommandsIndex = currentCommands.length - 1;
const currentCommandsIndex = currentCommands.length - 1;
currentCommands[currentCommandsIndex].list.forEach((cmd) =>
addChildCommands(unifiedCommands, cmd, commandItemDisplay)
);
@ -23,8 +23,8 @@ function addChildCommands(
}
function generateSingleListOfCommands() {
allCommands = [];
oldShowCommandLine = showCommandLine;
const allCommands = [];
const oldShowCommandLine = showCommandLine;
showCommandLine = () => {};
commands.list.forEach((c) => addChildCommands(allCommands, c));
showCommandLine = oldShowCommandLine;
@ -957,26 +957,6 @@ let commandsHighlightMode = {
],
};
let commandsAlwaysShowCPM = {
title: "Toggle always show cpm...",
list: [
{
id: "setAlwaysShowCPMTrue",
display: true,
exec: () => {
setAlwaysShowCPM(true);
},
},
{
id: "setAlwaysShowCPMFalse",
display: false,
exec: () => {
setHighlightMode(false);
},
},
],
};
let commandsTimerStyle = {
title: "Change timer/progress style...",
list: [
@ -1684,7 +1664,8 @@ $("#commandInput input").keydown((e) => {
if (obj.id == command) {
obj.exec(value);
if (obj.subgroup !== null && obj.subgroup !== undefined) {
subgroup = obj.subgroup;
//TODO: what is this for?
// subgroup = obj.subgroup;
}
}
});

View file

@ -70,28 +70,22 @@ async function db_getUserSnapshot() {
// console.log('getting data from db!');
let data = res.data();
if (data === undefined) return;
try {
if (data.personalBests !== undefined) {
snap.personalBests = data.personalBests;
}
snap.discordId = data.discordId;
snap.pairingCode =
data.discordPairingCode == null
? undefined
: data.discordPairingCode;
snap.config = data.config;
snap.favouriteThemes =
data.favouriteThemes === undefined ? [] : data.favouriteThemes;
snap.globalStats = {
time: data.timeTyping,
started: data.startedTests,
completed: data.completedTests,
};
if (data.lbMemory !== undefined) {
snap.lbMemory = data.lbMemory;
}
} catch (e) {
throw e;
if (data.personalBests !== undefined) {
snap.personalBests = data.personalBests;
}
snap.discordId = data.discordId;
snap.pairingCode =
data.discordPairingCode == null ? undefined : data.discordPairingCode;
snap.config = data.config;
snap.favouriteThemes =
data.favouriteThemes === undefined ? [] : data.favouriteThemes;
snap.globalStats = {
time: data.timeTyping,
started: data.startedTests,
completed: data.completedTests,
};
if (data.lbMemory !== undefined) {
snap.lbMemory = data.lbMemory;
}
})
.catch((e) => {
@ -119,7 +113,6 @@ async function db_getUserResults() {
.get()
.then((data) => {
dbSnapshot.results = [];
let len = data.docs.length;
data.docs.forEach((doc, index) => {
let result = doc.data();
result.id = doc.id;
@ -266,7 +259,6 @@ async function db_saveLocalPB(
}
}
let retval;
if (dbSnapshot == null) {
// await db_getUserResults().then(data => {
// retval = cont();

View file

@ -2,9 +2,9 @@ let themesList = null;
async function getThemesList() {
if (themesList == null) {
return $.getJSON("themes/list.json", function (data) {
list = data.sort(function (a, b) {
nameA = a.name.toLowerCase();
nameB = b.name.toLowerCase();
const list = data.sort(function (a, b) {
const nameA = a.name.toLowerCase();
const nameB = b.name.toLowerCase();
if (nameA < nameB) return -1;
if (nameA > nameB) return 1;
return 0;
@ -23,7 +23,7 @@ async function getSortedThemesList() {
if (themesList == null) {
await getThemesList();
}
sorted = themesList.sort((a, b) => {
const sorted = themesList.sort((a, b) => {
let b1 = hexToHSL(a.bgColor);
let b2 = hexToHSL(b.bgColor);
return b2.lgt - b1.lgt;
@ -40,7 +40,8 @@ async function getFunboxList() {
if (funboxList == null) {
return $.getJSON("funbox/list.json", function (data) {
funboxList = data.sort(function (a, b) {
(nameA = a.name.toLowerCase()), (nameB = b.name.toLowerCase());
const nameA = a.name.toLowerCase();
const nameB = b.name.toLowerCase();
if (nameA < nameB) return -1;
if (nameA > nameB) return 1;
return 0;
@ -57,7 +58,8 @@ async function getFontsList() {
if (fontsList == null) {
return $.getJSON("js/fonts.json", function (data) {
fontsList = data.sort(function (a, b) {
(nameA = a.name.toLowerCase()), (nameB = b.name.toLowerCase());
const nameA = a.name.toLowerCase();
const nameB = b.name.toLowerCase();
if (nameA < nameB) return -1;
if (nameA > nameB) return 1;
return 0;
@ -345,9 +347,9 @@ function getGibberish() {
}
function secondsToString(sec) {
hours = Math.floor(sec / 3600);
minutes = Math.floor((sec % 3600) / 60);
seconds = roundTo2((sec % 3600) % 60);
const hours = Math.floor(sec / 3600);
const minutes = Math.floor((sec % 3600) / 60);
const seconds = roundTo2((sec % 3600) % 60);
let hoursString;
let minutesString;
let secondsString;
@ -368,7 +370,7 @@ function getNumbers(len) {
let randLen = Math.floor(Math.random() * len) + 1;
let ret = "";
for (let i = 0; i < randLen; i++) {
randomNum = Math.floor(Math.random() * 10);
const randomNum = Math.floor(Math.random() * 10);
ret += randomNum.toString();
}
return ret;

View file

@ -499,9 +499,9 @@ async function initWords() {
wordset = customText;
}
for (let i = 0; i < wordsBound; i++) {
randomWord = wordset[Math.floor(Math.random() * wordset.length)];
previousWord = wordsList[i - 1];
previousWord2 = wordsList[i - 2];
let randomWord = wordset[Math.floor(Math.random() * wordset.length)];
const previousWord = wordsList[i - 1];
const previousWord2 = wordsList[i - 2];
if (config.mode == "custom" && customTextIsRandom) {
randomWord = wordset[Math.floor(Math.random() * wordset.length)];
} else if (config.mode == "custom" && !customTextIsRandom) {
@ -558,7 +558,7 @@ async function initWords() {
group = Math.floor(Math.random() * quotes.groups.length);
}
rq =
let rq =
quotes.groups[group][
Math.floor(Math.random() * quotes.groups[group].length)
];
@ -771,9 +771,11 @@ function addWord() {
};
const wordset = language.words;
let randomWord = wordset[Math.floor(Math.random() * wordset.length)];
previousWord = wordsList[wordsList.length - 1];
previousWordStripped = previousWord.replace(/[.?!":\-,]/g, "").toLowerCase();
previousWord2Stripped = wordsList[wordsList.length - 2]
const previousWord = wordsList[wordsList.length - 1];
const previousWordStripped = previousWord
.replace(/[.?!":\-,]/g, "")
.toLowerCase();
const previousWord2Stripped = wordsList[wordsList.length - 2]
.replace(/[.?!":\-,]/g, "")
.toLowerCase();
@ -872,7 +874,7 @@ function showWords() {
if (activeFunBox === "memory") {
memoryFunboxInterval = clearInterval(memoryFunboxInterval);
memoryFunboxTimer = Math.round(Math.pow(wordsList.length, 1.2));
memoryFunboxInterval = setInterval((fn) => {
memoryFunboxInterval = setInterval(() => {
memoryFunboxTimer -= 1;
showNotification(memoryFunboxTimer);
if (memoryFunboxTimer < 0) {
@ -1332,12 +1334,13 @@ function flashPressedKeymapKey(key, correct) {
// border-color: var(--sub-color);
// }
let errorColor;
if (config.colorfulMode) {
errorColor = themeColors.colorfulError;
} else {
errorColor = themeColors.error;
}
// TODO: is this used?
// let errorColor;
// if (config.colorfulMode) {
// errorColor = themeColors.colorfulError;
// } else {
// errorColor = themeColors.error;
// }
switch (key) {
case "\\":
@ -1434,44 +1437,45 @@ function updateHighlightedKeymapKey() {
.toString()
.toUpperCase();
let highlightKey;
switch (currentKey) {
case "\\":
case "|":
var highlightKey = "#KeyBackslash";
highlightKey = "#KeyBackslash";
break;
case "}":
case "]":
var highlightKey = "#KeyRightBracket";
highlightKey = "#KeyRightBracket";
break;
case "{":
case "[":
var highlightKey = "#KeyLeftBracket";
highlightKey = "#KeyLeftBracket";
break;
case '"':
case "'":
var highlightKey = "#KeyQuote";
highlightKey = "#KeyQuote";
break;
case ":":
case ";":
var highlightKey = "#KeySemicolon";
highlightKey = "#KeySemicolon";
break;
case "<":
case ",":
var highlightKey = "#KeyComma";
highlightKey = "#KeyComma";
break;
case ">":
case ".":
var highlightKey = "#KeyPeriod";
highlightKey = "#KeyPeriod";
break;
case "?":
case "/":
var highlightKey = "#KeySlash";
highlightKey = "#KeySlash";
break;
case "":
var highlightKey = "#KeySpace";
highlightKey = "#KeySpace";
break;
default:
var highlightKey = `#Key${currentKey}`;
highlightKey = `#Key${currentKey}`;
}
$(highlightKey).addClass("active-key");
@ -1814,14 +1818,15 @@ function showResult(difficultyFailed = false) {
$("#result .stats .time .bottom .afk").text(afkSecondsPercent + "% afk");
}
let correctcharpercent = roundTo2(
((stats.correctChars + stats.correctSpaces) /
(stats.correctChars +
stats.correctSpaces +
stats.incorrectChars +
stats.extraChars)) *
100
);
// TODO: is this used?
// let correctcharpercent = roundTo2(
// ((stats.correctChars + stats.correctSpaces) /
// (stats.correctChars +
// stats.correctSpaces +
// stats.incorrectChars +
// stats.extraChars)) *
// 100
// );
$("#result .stats .key .bottom").text(testtime + "s");
// $("#result .stats .key .bottom").attr("aria-label", `Correct, incorrect, missed and extra \n ${correctcharpercent}%`);
$("#words").removeClass("blurred");
@ -3303,7 +3308,7 @@ async function loadWordsHistory() {
let input = inputHistory[i];
let wordEl = "";
try {
if (input === "") throw Exception;
if (input === "") throw new Error("empty input word");
if (correctedHistory[i] !== undefined && correctedHistory[i] !== "") {
wordEl = `<div class='word' input="${correctedHistory[i].replace(
/"/g,
@ -3590,7 +3595,7 @@ function updateTestModesNotice() {
);
}
tagsString = "";
let tagsString = "";
// $.each($('.pageSettings .section.tags .tagsList .tag'), (index, tag) => {
// if($(tag).children('.active').attr('active') === 'true'){
// tagsString += $(tag).children('.title').text() + ', ';
@ -4269,7 +4274,7 @@ $(document).on("click", "#top .logo", (e) => {
});
$(document).on("click", "#top .config .wordCount .text-button", (e) => {
wrd = $(e.currentTarget).attr("wordCount");
const wrd = $(e.currentTarget).attr("wordCount");
if (wrd == "custom") {
// let newWrd = prompt("Custom word amount");
// if (newWrd !== null && !isNaN(newWrd) && newWrd > 0 && newWrd <= 10000) {
@ -4351,7 +4356,7 @@ $("#wordsWrapper").on("click", (e) => {
$(document).on("click", "#top .config .mode .text-button", (e) => {
if ($(e.currentTarget).hasClass("active")) return;
mode = $(e.currentTarget).attr("mode");
const mode = $(e.currentTarget).attr("mode");
changeMode(mode);
manualRestart = true;
restartTest();
@ -4362,7 +4367,7 @@ $(document).on("click", "#top #menu .icon-button", (e) => {
if ($(e.currentTarget).hasClass("leaderboards")) {
showLeaderboards();
} else {
href = $(e.currentTarget).attr("href");
const href = $(e.currentTarget).attr("href");
manualRestart = true;
changePage(href.replace("/", ""));
}

View file

@ -556,7 +556,7 @@ function refreshTagsSettingsSection() {
dbSnapshot.tags.forEach((tag) => {
if (tag.active === true) {
tagsEl.append(`
<div class="tag" id="${tag.id}">
<div class="active" active="true">
<i class="fas fa-check-square"></i>
@ -565,11 +565,11 @@ function refreshTagsSettingsSection() {
<div class="editButton"><i class="fas fa-pen"></i></div>
<div class="removeButton"><i class="fas fa-trash"></i></div>
</div>
`);
} else {
tagsEl.append(`
<div class="tag" id="${tag.id}">
<div class="active" active="false">
<i class="fas fa-square"></i>
@ -578,7 +578,7 @@ function refreshTagsSettingsSection() {
<div class="editButton"><i class="fas fa-pen"></i></div>
<div class="removeButton"><i class="fas fa-trash"></i></div>
</div>
`);
}
});
@ -869,7 +869,7 @@ $(".pageSettings #loadCustomColorsFromPreset").click((e) => {
document.documentElement.style.setProperty(e, "");
});
setTimeout((fn) => {
setTimeout(() => {
refreshThemeColorObject();
colorVars.forEach((colorName) => {
let color;

View file

@ -359,7 +359,7 @@ function setFavThemes(themes, nosave) {
//blind mode
function toggleBlindMode() {
blind = !config.blindMode;
let blind = !config.blindMode;
if (blind == undefined) {
blind = false;
}
@ -595,7 +595,7 @@ function setSingleListCommandLine(option, nosave) {
//show all lines
function toggleShowAllLines() {
sal = !config.showAllLines;
let sal = !config.showAllLines;
if (sal == undefined) {
sal = false;
}
@ -617,7 +617,7 @@ function setShowAllLines(sal, nosave) {
//quickend
function toggleQuickEnd() {
qe = !config.quickEnd;
let qe = !config.quickEnd;
if (qe == undefined) {
qe = false;
}
@ -1045,7 +1045,7 @@ function setConfidenceMode(cm, nosave) {
}
function toggleIndicateTypos() {
it = !config.indicateTypos;
let it = !config.indicateTypos;
if (it == undefined) {
it = false;
}
@ -1151,7 +1151,7 @@ function setCustomThemeColors(colors, nosave) {
}
function applyCustomThemeColors() {
array = config.customThemeColors;
const array = config.customThemeColors;
if (config.customTheme === true) {
$(".current-theme").text("custom");