Skip to content

Commit

Permalink
WebUI: enforce parentheses around operators
Browse files Browse the repository at this point in the history
PR #20696.
  • Loading branch information
Chocobo1 authored Apr 15, 2024
1 parent 6c82d5e commit d7cded5
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 57 deletions.
8 changes: 8 additions & 0 deletions src/webui/www/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
"html"
],
"rules": {
"no-mixed-operators": [
"error",
{
"groups": [
["&", "|", "^", "~", "<<", ">>", ">>>", "==", "!=", "===", "!==", ">", ">=", "<", "<=", "&&", "||", "in", "instanceof"]
]
}
],
"no-undef": "off",
"no-unused-vars": "off",
"nonblock-statement-body-position": ["error", "below"],
Expand Down
2 changes: 1 addition & 1 deletion src/webui/www/private/rename.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
new Event(e).stop();
// check field
const name = $('rename').value.trim();
if (name === null || name === "")
if ((name === null) || (name === ""))
return false;

const hash = new URI().getData('hash');
Expand Down
6 changes: 3 additions & 3 deletions src/webui/www/private/scripts/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1567,23 +1567,23 @@ window.addEventListener("DOMContentLoaded", function() {
defaultEventType: 'keydown',
events: {
'ctrl+a': function(event) {
if (event.target.nodeName == "INPUT" || event.target.nodeName == "TEXTAREA")
if ((event.target.nodeName === "INPUT") || (event.target.nodeName === "TEXTAREA"))
return;
if (event.target.isContentEditable)
return;
torrentsTable.selectAll();
event.preventDefault();
},
'delete': function(event) {
if (event.target.nodeName == "INPUT" || event.target.nodeName == "TEXTAREA")
if ((event.target.nodeName === "INPUT") || (event.target.nodeName === "TEXTAREA"))
return;
if (event.target.isContentEditable)
return;
deleteFN();
event.preventDefault();
},
'shift+delete': (event) => {
if (event.target.nodeName == "INPUT" || event.target.nodeName == "TEXTAREA")
if ((event.target.nodeName === "INPUT") || (event.target.nodeName === "TEXTAREA"))
return;
if (event.target.isContentEditable)
return;
Expand Down
14 changes: 7 additions & 7 deletions src/webui/www/private/scripts/contextmenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ window.qBittorrent.ContextMenu = (function() {
// position the menu
let xPosMenu = e.page.x + this.options.offsets.x;
let yPosMenu = e.page.y + this.options.offsets.y;
if (xPosMenu + this.menu.offsetWidth > document.documentElement.clientWidth)
if ((xPosMenu + this.menu.offsetWidth) > document.documentElement.clientWidth)
xPosMenu -= this.menu.offsetWidth;
if (yPosMenu + this.menu.offsetHeight > document.documentElement.clientHeight)
if ((yPosMenu + this.menu.offsetHeight) > document.documentElement.clientHeight)
yPosMenu = document.documentElement.clientHeight - this.menu.offsetHeight;
if (xPosMenu < 0)
xPosMenu = 0;
Expand All @@ -145,9 +145,9 @@ window.qBittorrent.ContextMenu = (function() {
const yPosOrigin = rectParent.bottom;
let xPos = xPosOrigin + rectParent.width - 1;
let yPos = yPosOrigin - rectParent.height - 1;
if (xPos + ul.offsetWidth > document.documentElement.clientWidth)
if ((xPos + ul.offsetWidth) > document.documentElement.clientWidth)
xPos -= (ul.offsetWidth + rectParent.width - 2);
if (yPos + ul.offsetHeight > document.documentElement.clientHeight)
if ((yPos + ul.offsetHeight) > document.documentElement.clientHeight)
yPos = document.documentElement.clientHeight - ul.offsetHeight;
if (xPos < 0)
xPos = 0;
Expand Down Expand Up @@ -240,7 +240,7 @@ window.qBittorrent.ContextMenu = (function() {

//show menu
show: function(trigger) {
if (lastShownContextMenu && lastShownContextMenu != this)
if (lastShownContextMenu && (lastShownContextMenu != this))
lastShownContextMenu.hide();
this.fx.start(1);
this.fireEvent('show');
Expand Down Expand Up @@ -338,7 +338,7 @@ window.qBittorrent.ContextMenu = (function() {
else if (data['super_seeding'] !== true)
all_are_super_seeding = false;

if (data['state'] != 'stoppedUP' && data['state'] != 'stoppedDL')
if ((data['state'] != 'stoppedUP') && (data['state'] != 'stoppedDL'))
all_are_stopped = false;
else
there_are_stopped = true;
Expand All @@ -363,7 +363,7 @@ window.qBittorrent.ContextMenu = (function() {
// hide renameFiles when more than 1 torrent is selected
if (selectedRows.length == 1) {
const data = torrentsTable.rows.get(selectedRows[0]).full_data;
let metadata_downloaded = !(data['state'] == 'metaDL' || data['state'] == 'forcedMetaDL' || data['total_size'] == -1);
let metadata_downloaded = !((data['state'] == 'metaDL') || (data['state'] == 'forcedMetaDL') || (data['total_size'] == -1));

// hide renameFiles when metadata hasn't been downloaded yet
metadata_downloaded
Expand Down
32 changes: 16 additions & 16 deletions src/webui/www/private/scripts/dynamicTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,12 @@ window.qBittorrent.DynamicTable = (function() {
this.canResize = false;

const resetElementBorderStyle = function(el, side) {
if (side === 'left' || side !== 'right') {
if ((side === 'left') || (side !== 'right')) {
el.setStyle('border-left-style', '');
el.setStyle('border-left-color', '');
el.setStyle('border-left-width', '');
}
if (side === 'right' || side !== 'left') {
if ((side === 'right') || (side !== 'left')) {
el.setStyle('border-right-style', '');
el.setStyle('border-right-color', '');
el.setStyle('border-right-width', '');
Expand All @@ -167,7 +167,7 @@ window.qBittorrent.DynamicTable = (function() {
const brect = e.target.getBoundingClientRect();
const mouseXRelative = e.event.clientX - brect.left;
if (this.currentHeaderAction === '') {
if (brect.width - mouseXRelative < 5) {
if ((brect.width - mouseXRelative) < 5) {
this.resizeTh = e.target;
this.canResize = true;
e.target.getParent("tr").style.cursor = 'col-resize';
Expand All @@ -187,7 +187,7 @@ window.qBittorrent.DynamicTable = (function() {
let borderChangeElement = previousVisibleSibling;
let changeBorderSide = 'right';

if (mouseXRelative > brect.width / 2) {
if (mouseXRelative > (brect.width / 2)) {
borderChangeElement = e.target;
this.dropSide = 'right';
}
Expand All @@ -200,7 +200,7 @@ window.qBittorrent.DynamicTable = (function() {
if (!previousVisibleSibling) { // right most column
borderChangeElement = e.target;

if (mouseXRelative <= brect.width / 2)
if (mouseXRelative <= (brect.width / 2))
changeBorderSide = 'left';
}

Expand Down Expand Up @@ -429,7 +429,7 @@ window.qBittorrent.DynamicTable = (function() {
loadColumnsOrder: function() {
const columnsOrder = [];
const val = LocalPreferences.get('columns_order_' + this.dynamicTableDivId);
if (val === null || val === undefined)
if ((val === null) || (val === undefined))
return;
val.split(',').forEach(function(v) {
if ((v in this.columns) && (!columnsOrder.contains(v)))
Expand Down Expand Up @@ -1141,7 +1141,7 @@ window.qBittorrent.DynamicTable = (function() {
this.columns['progress'].updateTd = function(td, row) {
const progress = this.getRowValue(row);
let progressFormatted = (progress * 100).round(1);
if (progressFormatted == 100.0 && progress != 1.0)
if ((progressFormatted == 100.0) && (progress != 1.0))
progressFormatted = 99.9;

if (td.getChildren('div').length > 0) {
Expand Down Expand Up @@ -1310,7 +1310,7 @@ window.qBittorrent.DynamicTable = (function() {
td.set('title', '∞');
}
else {
const formattedVal = 'QBT_TR(%1 ago)QBT_TR[CONTEXT=TransferListDelegate]'.replace('%1', window.qBittorrent.Misc.friendlyDuration((new Date()) / 1000 - val));
const formattedVal = 'QBT_TR(%1 ago)QBT_TR[CONTEXT=TransferListDelegate]'.replace('%1', window.qBittorrent.Misc.friendlyDuration((new Date() / 1000) - val));
td.set('text', formattedVal);
td.set('title', formattedVal);
}
Expand Down Expand Up @@ -1343,7 +1343,7 @@ window.qBittorrent.DynamicTable = (function() {
return false;
break;
case 'seeding':
if (state != 'uploading' && state != 'forcedUP' && state != 'stalledUP' && state != 'queuedUP' && state != 'checkingUP')
if ((state != 'uploading') && (state != 'forcedUP') && (state != 'stalledUP') && (state != 'queuedUP') && (state != 'checkingUP'))
return false;
break;
case 'completed':
Expand Down Expand Up @@ -1377,20 +1377,20 @@ window.qBittorrent.DynamicTable = (function() {
if (state == 'stalledDL')
r = (row['full_data'].upspeed > 0);
else
r = state == 'metaDL' || state == 'forcedMetaDL' || state == 'downloading' || state == 'forcedDL' || state == 'uploading' || state == 'forcedUP';
r = (state == 'metaDL') || (state == 'forcedMetaDL') || (state == 'downloading') || (state == 'forcedDL') || (state == 'uploading') || (state == 'forcedUP');
if (r == inactive)
return false;
break;
case 'checking':
if (state !== 'checkingUP' && state !== 'checkingDL' && state !== 'checkingResumeData')
if ((state !== 'checkingUP') && (state !== 'checkingDL') && (state !== 'checkingResumeData'))
return false;
break;
case 'moving':
if (state !== 'moving')
return false;
break;
case 'errored':
if (state != 'error' && state != "unknown" && state != "missingFiles")
if ((state != 'error') && (state != 'unknown') && (state != 'missingFiles'))
return false;
break;
}
Expand Down Expand Up @@ -1632,7 +1632,7 @@ window.qBittorrent.DynamicTable = (function() {
this.columns['progress'].updateTd = function(td, row) {
const progress = this.getRowValue(row);
let progressFormatted = (progress * 100).round(1);
if (progressFormatted == 100.0 && progress != 1.0)
if ((progressFormatted == 100.0) && (progress != 1.0))
progressFormatted = 99.9;
progressFormatted += "%";
td.set('text', progressFormatted);
Expand Down Expand Up @@ -3157,12 +3157,12 @@ window.qBittorrent.DynamicTable = (function() {
this.filterText = window.qBittorrent.Log.getFilterText();
const filterTerms = (this.filterText.length > 0) ? this.filterText.toLowerCase().split(' ') : [];
const logLevels = window.qBittorrent.Log.getSelectedLevels();
if (filterTerms.length > 0 || logLevels.length < 4) {
if ((filterTerms.length > 0) || (logLevels.length < 4)) {
for (let i = 0; i < rows.length; ++i) {
if (logLevels.indexOf(rows[i].full_data.type.toString()) == -1)
continue;

if (filterTerms.length > 0 && !window.qBittorrent.Misc.containsAllTerms(rows[i].full_data.message, filterTerms))
if ((filterTerms.length > 0) && !window.qBittorrent.Misc.containsAllTerms(rows[i].full_data.message, filterTerms))
continue;

filteredRows.push(rows[i]);
Expand Down Expand Up @@ -3225,7 +3225,7 @@ window.qBittorrent.DynamicTable = (function() {
const filterTerms = (this.filterText.length > 0) ? this.filterText.toLowerCase().split(' ') : [];
if (filterTerms.length > 0) {
for (let i = 0; i < rows.length; ++i) {
if (filterTerms.length > 0 && !window.qBittorrent.Misc.containsAllTerms(rows[i].full_data.ip, filterTerms))
if ((filterTerms.length > 0) && !window.qBittorrent.Misc.containsAllTerms(rows[i].full_data.ip, filterTerms))
continue;

filteredRows.push(rows[i]);
Expand Down
4 changes: 2 additions & 2 deletions src/webui/www/private/scripts/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ window.qBittorrent.Misc = (function() {
return "QBT_TR(Unknown)QBT_TR[CONTEXT=misc]";

let i = 0;
while (value >= 1024.0 && i < 6) {
while ((value >= 1024.0) && (i < 6)) {
value /= 1024.0;
++i;
}
Expand Down Expand Up @@ -104,7 +104,7 @@ window.qBittorrent.Misc = (function() {
* JS counterpart of the function in src/misc.cpp
*/
const friendlyDuration = function(seconds, maxCap = -1) {
if (seconds < 0 || ((seconds >= maxCap) && (maxCap >= 0)))
if ((seconds < 0) || ((seconds >= maxCap) && (maxCap >= 0)))
return "∞";
if (seconds === 0)
return "0";
Expand Down
2 changes: 1 addition & 1 deletion src/webui/www/private/scripts/progressbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ window.qBittorrent.ProgressBar = (function() {
'lightbg': 'var(--color-background-default)',
'lightfg': 'var(--color-text-default)'
};
if (parameters && $type(parameters) == 'object')
if (parameters && ($type(parameters) == 'object'))
$extend(vals, parameters);
if (vals.height < 12)
vals.height = 12;
Expand Down
6 changes: 3 additions & 3 deletions src/webui/www/private/scripts/rename-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ window.qBittorrent.MultiRename = (function() {

// Maximum of 250 matches per file
++count;
} while (regex.global && count < 250);
} while (regex.global && (count < 250));

return matches;
};
Expand Down Expand Up @@ -182,7 +182,7 @@ window.qBittorrent.MultiRename = (function() {
break;
}
// Ignore rows without a match
if (!matches || matches.length == 0) {
if (!matches || (matches.length === 0)) {
continue;
}

Expand Down Expand Up @@ -219,7 +219,7 @@ window.qBittorrent.MultiRename = (function() {
},

rename: async function() {
if (!this.matchedFiles || this.matchedFiles.length === 0 || !this.hash) {
if (!this.matchedFiles || (this.matchedFiles.length === 0) || !this.hash) {
this.onRenamed([]);
return;
}
Expand Down
6 changes: 4 additions & 2 deletions src/webui/www/private/shareratio.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@
};

// select default when orig values not passed. using double equals to compare string and int
if ((origValues[0] === "") || ((values.ratioLimit == UseGlobalLimit) && (values.seedingTimeLimit == UseGlobalLimit))
&& (values.inactiveSeedingTimeLimit == UseGlobalLimit)) {
if ((origValues[0] === "")
|| ((values.ratioLimit == UseGlobalLimit)
&& (values.seedingTimeLimit == UseGlobalLimit)
&& (values.inactiveSeedingTimeLimit == UseGlobalLimit))) {
// use default option
setSelectedRadioValue('shareLimit', 'default');
}
Expand Down
Loading

0 comments on commit d7cded5

Please sign in to comment.