aboutsummaryrefslogtreecommitdiff
path: root/ext/js/pages/settings
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2024-02-14 22:26:29 -0500
committerGitHub <noreply@github.com>2024-02-15 03:26:29 +0000
commit6bf7b0055765c4f2011c9614753d6714dc09be65 (patch)
tree0e782ae66556eaa61a34d9f32d77c831b2443ce5 /ext/js/pages/settings
parent7a4096240ce4faf70a785d047945388baa0daab3 (diff)
Eslint rule updates (#673)
* Install unicorn * Add rules * Fix issues * Install sonarjs * Set up rules * Fix issues * Install eslint-plugin-import and fix import extensions * Simplify permitted error names
Diffstat (limited to 'ext/js/pages/settings')
-rw-r--r--ext/js/pages/settings/anki-controller.js7
-rw-r--r--ext/js/pages/settings/audio-controller.js2
-rw-r--r--ext/js/pages/settings/backup-controller.js4
-rw-r--r--ext/js/pages/settings/collapsible-dictionary-controller.js4
-rw-r--r--ext/js/pages/settings/dictionary-controller.js6
-rw-r--r--ext/js/pages/settings/dictionary-import-controller.js6
-rw-r--r--ext/js/pages/settings/extension-keyboard-shortcuts-controller.js2
-rw-r--r--ext/js/pages/settings/keyboard-shortcuts-controller.js2
-rw-r--r--ext/js/pages/settings/profile-controller.js4
-rw-r--r--ext/js/pages/settings/sentence-termination-characters-controller.js5
-rw-r--r--ext/js/pages/settings/settings-controller.js4
-rw-r--r--ext/js/pages/settings/settings-display-controller.js4
12 files changed, 24 insertions, 26 deletions
diff --git a/ext/js/pages/settings/anki-controller.js b/ext/js/pages/settings/anki-controller.js
index 3a6345ed..e161d86b 100644
--- a/ext/js/pages/settings/anki-controller.js
+++ b/ext/js/pages/settings/anki-controller.js
@@ -401,11 +401,11 @@ export class AnkiController {
if (typeof data !== 'undefined') {
details += `${JSON.stringify(data, null, 4)}\n\n`;
}
- details += `${error.stack}`.trimRight();
+ details += `${error.stack}`.trimEnd();
/** @type {HTMLElement} */ (this._ankiErrorMessageDetailsNode).textContent = details;
/** @type {HTMLElement} */ (this._ankiErrorMessageDetailsContainer).hidden = true;
- /** @type {HTMLElement} */ (this._ankiErrorInvalidResponseInfo).hidden = (errorString.indexOf('Invalid response') < 0);
+ /** @type {HTMLElement} */ (this._ankiErrorInvalidResponseInfo).hidden = !errorString.includes('Invalid response');
/** @type {HTMLElement} */ (this._ankiErrorMessageDetailsToggle).hidden = false;
}
@@ -762,7 +762,8 @@ class AnkiCardController {
const ELEMENT_NODE = Node.ELEMENT_NODE;
const container = this._ankiCardFieldsContainer;
if (container !== null) {
- for (const node of [...container.childNodes]) {
+ const childNodesFrozen = [...container.childNodes];
+ for (const node of childNodesFrozen) {
if (node.nodeType === ELEMENT_NODE && node instanceof HTMLElement && node.dataset.persistent === 'true') { continue; }
container.removeChild(node);
}
diff --git a/ext/js/pages/settings/audio-controller.js b/ext/js/pages/settings/audio-controller.js
index 9633c4b3..5b597d33 100644
--- a/ext/js/pages/settings/audio-controller.js
+++ b/ext/js/pages/settings/audio-controller.js
@@ -144,7 +144,7 @@ export class AudioController extends EventDispatcher {
const text = input.value || '';
const voiceUri = input.dataset.voice;
const audio = this._audioSystem.createTextToSpeechAudio(text, typeof voiceUri === 'string' ? voiceUri : '');
- audio.volume = 1.0;
+ audio.volume = 1;
audio.play();
} catch (e) {
// NOP
diff --git a/ext/js/pages/settings/backup-controller.js b/ext/js/pages/settings/backup-controller.js
index 59bcaed9..2bab00e3 100644
--- a/ext/js/pages/settings/backup-controller.js
+++ b/ext/js/pages/settings/backup-controller.js
@@ -144,7 +144,7 @@ export class BackupController {
}
}
- const data = {
+ return {
version: this._currentVersion,
date: this._getSettingsExportDateString(date, '-', ' ', ':', 6),
url: chrome.runtime.getURL('/'),
@@ -154,8 +154,6 @@ export class BackupController {
permissions,
options: optionsFull
};
-
- return data;
}
/**
diff --git a/ext/js/pages/settings/collapsible-dictionary-controller.js b/ext/js/pages/settings/collapsible-dictionary-controller.js
index 5ba61e0c..62f84b96 100644
--- a/ext/js/pages/settings/collapsible-dictionary-controller.js
+++ b/ext/js/pages/settings/collapsible-dictionary-controller.js
@@ -156,9 +156,7 @@ export class CollapsibleDictionaryController {
const versionNode = querySelectorNotNull(node, '.dictionary-version');
versionNode.textContent = version;
- /** @type {HTMLSelectElement} */
- const select = querySelectorNotNull(node, '.definitions-collapsible');
- return select;
+ return querySelectorNotNull(node, '.definitions-collapsible');
}
/** */
diff --git a/ext/js/pages/settings/dictionary-controller.js b/ext/js/pages/settings/dictionary-controller.js
index 1d3c1730..5020dc7c 100644
--- a/ext/js/pages/settings/dictionary-controller.js
+++ b/ext/js/pages/settings/dictionary-controller.js
@@ -558,7 +558,7 @@ export class DictionaryController {
const {profiles} = optionsFull;
for (let i = 0, ii = profiles.length; i < ii; ++i) {
let modified = false;
- const missingDictionaries = new Set([...installedDictionaries]);
+ const missingDictionaries = new Set(installedDictionaries);
const dictionaryOptionsArray = profiles[i].options.dictionaries;
for (let j = dictionaryOptionsArray.length - 1; j >= 0; --j) {
const {name} = dictionaryOptionsArray[j];
@@ -871,8 +871,8 @@ export class DictionaryController {
const onProgress = ({processed, count, storeCount, storesProcesed}) => {
const percent = (
(count > 0 && storesProcesed > 0) ?
- (processed / count) * (storesProcesed / storeCount) * 100.0 :
- 0.0
+ (processed / count) * (storesProcesed / storeCount) * 100 :
+ 0
);
const cssString = `${percent}%`;
const statusString = `${percent.toFixed(0)}%`;
diff --git a/ext/js/pages/settings/dictionary-import-controller.js b/ext/js/pages/settings/dictionary-import-controller.js
index 0484001d..34e21c5d 100644
--- a/ext/js/pages/settings/dictionary-import-controller.js
+++ b/ext/js/pages/settings/dictionary-import-controller.js
@@ -172,7 +172,7 @@ export class DictionaryImportController {
for (const label of infoLabels) { label.textContent = labelText; }
}
- const percent = count > 0 ? (index / count * 100.0) : 0.0;
+ const percent = count > 0 ? (index / count * 100) : 0;
const cssString = `${percent}%`;
const statusString = `${Math.floor(percent).toFixed(0)}%`;
for (const progressBar of progressBars) { progressBar.style.width = cssString; }
@@ -199,8 +199,8 @@ export class DictionaryImportController {
await this._importDictionary(files[i], importDetails, onProgress);
}
- } catch (err) {
- this._showErrors([toError(err)]);
+ } catch (error) {
+ this._showErrors([toError(error)]);
} finally {
prevention.end();
for (const progress of progressContainers) { progress.hidden = true; }
diff --git a/ext/js/pages/settings/extension-keyboard-shortcuts-controller.js b/ext/js/pages/settings/extension-keyboard-shortcuts-controller.js
index 61eefffa..b9d107ae 100644
--- a/ext/js/pages/settings/extension-keyboard-shortcuts-controller.js
+++ b/ext/js/pages/settings/extension-keyboard-shortcuts-controller.js
@@ -353,7 +353,7 @@ class ExtensionKeyboardShortcutHotkeyEntry {
* @param {boolean} updateInput
*/
async _tryUpdateInput(key, modifiers, updateInput) {
- let okay = (key === null ? (modifiers.length === 0) : (modifiers.length !== 0));
+ let okay = (key === null ? (modifiers.length === 0) : (modifiers.length > 0));
if (okay) {
try {
await this._parent.updateCommand(this._name, key, modifiers);
diff --git a/ext/js/pages/settings/keyboard-shortcuts-controller.js b/ext/js/pages/settings/keyboard-shortcuts-controller.js
index 7b28a322..907cf4a1 100644
--- a/ext/js/pages/settings/keyboard-shortcuts-controller.js
+++ b/ext/js/pages/settings/keyboard-shortcuts-controller.js
@@ -183,7 +183,7 @@ export class KeyboardShortcutController {
const listContainer = /** @type {HTMLElement} */ (this._listContainer);
listContainer.appendChild(fragment);
listContainer.hidden = (hotkeys.length === 0);
- /** @type {HTMLElement} */ (this._emptyIndicator).hidden = (hotkeys.length !== 0);
+ /** @type {HTMLElement} */ (this._emptyIndicator).hidden = (hotkeys.length > 0);
}
/**
diff --git a/ext/js/pages/settings/profile-controller.js b/ext/js/pages/settings/profile-controller.js
index 5a7b5ed4..a82a4b4e 100644
--- a/ext/js/pages/settings/profile-controller.js
+++ b/ext/js/pages/settings/profile-controller.js
@@ -544,7 +544,7 @@ export class ProfileController {
*/
_tryGetValidProfileIndex(stringValue) {
if (typeof stringValue !== 'string') { return null; }
- const intValue = parseInt(stringValue, 10);
+ const intValue = Number.parseInt(stringValue, 10);
return (
Number.isFinite(intValue) &&
intValue >= 0 &&
@@ -573,7 +573,7 @@ export class ProfileController {
suffix = match[5];
if (typeof match[2] === 'string') {
space = match[3];
- index = parseInt(match[4], 10) + 1;
+ index = Number.parseInt(match[4], 10) + 1;
} else {
space = ' ';
index = 2;
diff --git a/ext/js/pages/settings/sentence-termination-characters-controller.js b/ext/js/pages/settings/sentence-termination-characters-controller.js
index c393aaa1..4ceed22b 100644
--- a/ext/js/pages/settings/sentence-termination-characters-controller.js
+++ b/ext/js/pages/settings/sentence-termination-characters-controller.js
@@ -125,8 +125,9 @@ export class SentenceTerminationCharactersController {
entry.prepare();
}
- /** @type {HTMLElement} */ (this._listTable).hidden = (terminationCharacters.length === 0);
- /** @type {HTMLElement} */ (this._emptyIndicator).hidden = (terminationCharacters.length !== 0);
+ const empty = terminationCharacters.length === 0;
+ /** @type {HTMLElement} */ (this._listTable).hidden = empty;
+ /** @type {HTMLElement} */ (this._emptyIndicator).hidden = !empty;
}
/**
diff --git a/ext/js/pages/settings/settings-controller.js b/ext/js/pages/settings/settings-controller.js
index 3f389271..c835f8e6 100644
--- a/ext/js/pages/settings/settings-controller.js
+++ b/ext/js/pages/settings/settings-controller.js
@@ -195,6 +195,7 @@ export class SettingsController extends EventDispatcher {
*/
preventPageExit() {
/** @type {import('settings-controller').PageExitPrevention} */
+ // eslint-disable-next-line sonarjs/prefer-object-literal
const obj = {};
obj.end = this._endPreventPageExit.bind(this, obj);
if (this._pageExitPreventionEventListeners.size === 0) {
@@ -226,8 +227,7 @@ export class SettingsController extends EventDispatcher {
async getDefaultOptions() {
const optionsUtil = new OptionsUtil();
await optionsUtil.prepare();
- const optionsFull = optionsUtil.getDefault();
- return optionsFull;
+ return optionsUtil.getDefault();
}
// Private
diff --git a/ext/js/pages/settings/settings-display-controller.js b/ext/js/pages/settings/settings-display-controller.js
index 0a729d96..47aa9c9c 100644
--- a/ext/js/pages/settings/settings-display-controller.js
+++ b/ext/js/pages/settings/settings-display-controller.js
@@ -290,7 +290,7 @@ export class SettingsDisplayController {
*/
_getMoreContainer(link) {
const v = link.dataset.parentDistance;
- const distance = v ? parseInt(v, 10) : 1;
+ const distance = v ? Number.parseInt(v, 10) : 1;
if (Number.isNaN(distance)) { return null; }
/** @type {?Element} */
@@ -338,7 +338,7 @@ export class SettingsDisplayController {
let indent = '\t';
if (args.length > 1) {
- const count = parseInt(args[1], 10);
+ const count = Number.parseInt(args[1], 10);
indent = (Number.isFinite(count) && count >= 0 ? ' '.repeat(count) : args[1]);
}