WebUI: enforce coding style

* WebUI: prefer `classList.toggle()` over other pattern
  Addresses: https://github.com/qbittorrent/qBittorrent/pull/23231#discussion_r2328647152
* WebUI: prefer using built-in objects Constructor
* WebUI: combine function calls

PR #23261.
This commit is contained in:
Chocobo1 2025-09-14 22:11:23 +08:00 committed by GitHub
parent 5edaf2cf10
commit b0148ef36c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 14 additions and 22 deletions

View File

@ -36,6 +36,7 @@ export default [
"curly": ["error", "multi-or-nest", "consistent"], "curly": ["error", "multi-or-nest", "consistent"],
"eqeqeq": "error", "eqeqeq": "error",
"guard-for-in": "error", "guard-for-in": "error",
"no-implicit-coercion": "error",
"no-undef": "off", "no-undef": "off",
"no-unused-vars": "off", "no-unused-vars": "off",
"no-var": "error", "no-var": "error",
@ -73,7 +74,10 @@ export default [
"Unicorn/no-array-for-each": "error", "Unicorn/no-array-for-each": "error",
"Unicorn/no-for-loop": "error", "Unicorn/no-for-loop": "error",
"Unicorn/no-zero-fractions": "error", "Unicorn/no-zero-fractions": "error",
"Unicorn/prefer-classlist-toggle": "error",
"Unicorn/prefer-native-coercion-functions": "error",
"Unicorn/prefer-number-properties": "error", "Unicorn/prefer-number-properties": "error",
"Unicorn/prefer-single-call": "error",
"Unicorn/switch-case-braces": ["error", "avoid"] "Unicorn/switch-case-braces": ["error", "avoid"]
} }
} }

View File

@ -710,10 +710,8 @@ window.qBittorrent.DynamicTable ??= (() => {
colElem.classList.toggle("reverse", isReverse); colElem.classList.toggle("reverse", isReverse);
} }
const oldColElem = getCol(this.dynamicTableFixedHeaderDivId, oldColumn); const oldColElem = getCol(this.dynamicTableFixedHeaderDivId, oldColumn);
if (oldColElem !== null) { if (oldColElem !== null)
oldColElem.classList.remove("sorted"); oldColElem.classList.remove("sorted", "reverse");
oldColElem.classList.remove("reverse");
}
} }
getSelectedRowId() { getSelectedRowId() {

View File

@ -730,9 +730,7 @@ window.qBittorrent.Search ??= (() => {
for (const plugin of responseJSON) for (const plugin of responseJSON)
searchPlugins.push(plugin); searchPlugins.push(plugin);
const pluginOptions = []; const pluginOptions = [createOption("QBT_TR(Only enabled)QBT_TR[CONTEXT=SearchEngineWidget]", "enabled"), createOption("QBT_TR(All plugins)QBT_TR[CONTEXT=SearchEngineWidget]", "all")];
pluginOptions.push(createOption("QBT_TR(Only enabled)QBT_TR[CONTEXT=SearchEngineWidget]", "enabled"));
pluginOptions.push(createOption("QBT_TR(All plugins)QBT_TR[CONTEXT=SearchEngineWidget]", "all"));
const searchPluginsEmpty = (searchPlugins.length === 0); const searchPluginsEmpty = (searchPlugins.length === 0);
if (!searchPluginsEmpty) { if (!searchPluginsEmpty) {

View File

@ -17,12 +17,8 @@
MochaUI.initializeTabs("aboutTabs"); MochaUI.initializeTabs("aboutTabs");
const showContent = (element) => { const showContent = (element) => {
for (const content of document.querySelectorAll(".aboutTabContent")) { for (const content of document.querySelectorAll(".aboutTabContent"))
if (content === element) content.classList.toggle("invisible", (content !== element));
content.classList.remove("invisible");
else
content.classList.add("invisible");
}
}; };
document.getElementById("aboutAboutLink").addEventListener("click", (event) => { document.getElementById("aboutAboutLink").addEventListener("click", (event) => {

View File

@ -36,12 +36,8 @@
MochaUI.initializeTabs("preferencesTabs"); MochaUI.initializeTabs("preferencesTabs");
const showTab = (element) => { const showTab = (element) => {
for (const tab of document.querySelectorAll(".PrefTab")) { for (const tab of document.querySelectorAll(".PrefTab"))
if (tab === element) tab.classList.toggle("invisible", (tab !== element));
tab.classList.remove("invisible");
else
tab.classList.add("invisible");
}
}; };
document.getElementById("PrefBehaviorLink").addEventListener("click", (e) => { document.getElementById("PrefBehaviorLink").addEventListener("click", (e) => {

View File

@ -620,8 +620,8 @@
if (articlesDiffer) { if (articlesDiffer) {
// update unread count // update unread count
const oldUnread = feedData[r.uid].map((art) => !art.isRead).filter((v) => v).length; const oldUnread = feedData[r.uid].map((art) => !art.isRead).filter(Boolean).length;
const newUnread = r.articles.map((art) => !art.isRead).filter((v) => v).length; const newUnread = r.articles.map((art) => !art.isRead).filter(Boolean).length;
const unreadDifference = newUnread - oldUnread; const unreadDifference = newUnread - oldUnread;
// find all parents (and self) and add unread difference // find all parents (and self) and add unread difference
@ -733,7 +733,7 @@
}); });
// calculate number of unread // calculate number of unread
const numberOfUnread = dataEntry.articles.map((art) => !art.isRead).filter((v) => v).length; const numberOfUnread = dataEntry.articles.map((art) => !art.isRead).filter(Boolean).length;
// find all items that contain this rss feed and add unread count // find all items that contain this rss feed and add unread count
for (const row of rssFeedTable.getRowValues()) { for (const row of rssFeedTable.getRowValues()) {
if (dataEntry.fullName.slice(0, row.full_data.dataPath.length) === row.full_data.dataPath) if (dataEntry.fullName.slice(0, row.full_data.dataPath.length) === row.full_data.dataPath)