diff --git a/.eslintrc.cjs b/.eslintrc.cjs index c61e31457..6cc3863c6 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -18,5 +18,6 @@ module.exports = { "vue/attribute-hyphenation": "off", "vue/multi-word-component-names": "off", "vue/no-reserved-component-names": "off", + "no-param-reassign": "error", }, }; diff --git a/assets/js/components/Energyflow/Energyflow.vue b/assets/js/components/Energyflow/Energyflow.vue index e5620d689..772bcdb31 100644 --- a/assets/js/components/Energyflow/Energyflow.vue +++ b/assets/js/components/Energyflow/Energyflow.vue @@ -285,8 +285,7 @@ export default { }, loadpointsPower: function () { return this.loadpointsCompact.reduce((sum, lp) => { - sum += lp.power || 0; - return sum; + return sum + (lp.power || 0); }, 0); }, pvExport: function () { diff --git a/assets/js/components/Energyflow/EnergyflowEntry.vue b/assets/js/components/Energyflow/EnergyflowEntry.vue index 4519821d8..6a033d43f 100644 --- a/assets/js/components/Energyflow/EnergyflowEntry.vue +++ b/assets/js/components/Energyflow/EnergyflowEntry.vue @@ -124,12 +124,13 @@ export default { } return; } - if (!instance) { - instance = new Tooltip(ref, { html: true, title: " " }); + let newInstance = instance; + if (!newInstance) { + newInstance = new Tooltip(ref, { html: true, title: " " }); } const html = `
${content.join("
")}
`; - instance.setContent({ ".tooltip-inner": html }); - return instance; + newInstance.setContent({ ".tooltip-inner": html }); + return newInstance; }, powerClicked: function ($event) { if (this.powerTooltip) { diff --git a/assets/js/components/Savings.vue b/assets/js/components/Savings.vue index 847101727..9dc5326c9 100644 --- a/assets/js/components/Savings.vue +++ b/assets/js/components/Savings.vue @@ -327,8 +327,7 @@ export default { const { rates } = res.data.result; this.referenceGrid = rates.reduce((acc, slot) => { - acc += slot.price; - return acc; + return acc + slot.price; }, 0) / rates.length; } catch (e) { this.referenceGrid = undefined; diff --git a/assets/js/components/VehicleStatus.vue b/assets/js/components/VehicleStatus.vue index d2e8d9b6d..e1a3bba16 100644 --- a/assets/js/components/VehicleStatus.vue +++ b/assets/js/components/VehicleStatus.vue @@ -626,12 +626,13 @@ export default { } return; } - if (!instance) { + let newInstance = instance; + if (!newInstance) { const trigger = hoverOnly ? "hover" : "hover focus"; - instance = new Tooltip(ref, { title: " ", trigger }); + newInstance = new Tooltip(ref, { title: " ", trigger }); } - instance.setContent({ ".tooltip-inner": content }); - return instance; + newInstance.setContent({ ".tooltip-inner": content }); + return newInstance; }, }, }; diff --git a/assets/js/mixins/formatter.js b/assets/js/mixins/formatter.js index ec5d29b4c..bca36bb55 100644 --- a/assets/js/mixins/formatter.js +++ b/assets/js/mixins/formatter.js @@ -38,8 +38,10 @@ export default { if (val === undefined || val === null) { return 0; } - val = Math.abs(val); - return val >= this.fmtLimit ? this.round(val / 1e3, this.fmtDigits) : this.round(val, 0); + let absVal = Math.abs(val); + return absVal >= this.fmtLimit + ? this.round(absVal / 1e3, this.fmtDigits) + : this.round(absVal, 0); }, fmtW: function (watt = 0, format = POWER_UNIT.KW, withUnit = true, digits) { let unit = format; @@ -106,10 +108,10 @@ export default { if (duration <= 0) { return "—"; } - duration = Math.round(duration); - var seconds = duration % 60; - var minutes = Math.floor(duration / 60) % 60; - var hours = Math.floor(duration / 3600); + let roundedDuration = Math.round(duration); + var seconds = roundedDuration % 60; + var minutes = Math.floor(roundedDuration / 60) % 60; + var hours = Math.floor(roundedDuration / 3600); var result = ""; let unit = ""; if (hours >= 1 || minUnit === "h") {