Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase the usage of compound assignment operators #390

Open
elfring opened this issue Dec 12, 2021 · 0 comments
Open

Increase the usage of compound assignment operators #390

elfring opened this issue Dec 12, 2021 · 0 comments

Comments

@elfring
Copy link

elfring commented Dec 12, 2021

👀 Some source code analysis tools can help to find opportunities for improving software components.
💭 I propose to increase the usage of compound operators accordingly.

diff --git a/src/usr/share/rpimonitor/web/addons/custom/custom.js b/src/usr/share/rpimonitor/web/addons/custom/custom.js
index 5b74d77..85f2080 100644
--- a/src/usr/share/rpimonitor/web/addons/custom/custom.js
+++ b/src/usr/share/rpimonitor/web/addons/custom/custom.js
@@ -64,7 +64,7 @@ $(window).resize(function() {
 
 window.onbeforeunload = function (e) {
   if ( !customwarning ) return;
-  e = e || window.event;
+  e ||= window.event;
   message="Closing or refreshing this page will also close your connection.";
   if (e) {
     e.returnValue = message;
diff --git a/src/usr/share/rpimonitor/web/js/bootstrap.js b/src/usr/share/rpimonitor/web/js/bootstrap.js
index 53da1c7..6813f47 100644
--- a/src/usr/share/rpimonitor/web/js/bootstrap.js
+++ b/src/usr/share/rpimonitor/web/js/bootstrap.js
@@ -94,7 +94,7 @@ if (typeof jQuery === 'undefined') { throw new Error('Bootstrap\'s JavaScript re
 
     if (!selector) {
       selector = $this.attr('href')
-      selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') // strip for ie7
+      selector &&= selector.replace(/.*(?=#[^\s]*$)/, '') // strip for ie7
     }
 
     var $parent = $(selector)
@@ -192,7 +192,7 @@ if (typeof jQuery === 'undefined') { throw new Error('Bootstrap\'s JavaScript re
     var val  = $el.is('input') ? 'val' : 'html'
     var data = $el.data()
 
-    state = state + 'Text'
+    state += 'Text'
 
     if (data.resetText == null) $el.data('resetText', $el[val]())
 
@@ -372,7 +372,7 @@ if (typeof jQuery === 'undefined') { throw new Error('Bootstrap\'s JavaScript re
 
   Carousel.prototype.slide = function (type, next) {
     var $active   = this.$element.find('.item.active')
-    var $next     = next || $active[type]()
+    var $next ||= $active[type]()
     var isCycling = this.interval
     var direction = type == 'next' ? 'left' : 'right'
     var fallback  = type == 'next' ? 'first' : 'last'
@@ -653,7 +653,7 @@ if (typeof jQuery === 'undefined') { throw new Error('Bootstrap\'s JavaScript re
     var data    = $target.data('bs.collapse')
     var option  = data ? 'toggle' : $this.data()
     var parent  = $this.attr('data-parent')
-    var $parent = parent && $(parent)
+    var $parent &&= $(parent)
 
     if (!data || !data.transitioning) {
       if ($parent) $parent.find('[data-toggle="collapse"][data-parent="' + parent + '"]').not($this).addClass('collapsed')
@@ -769,7 +769,7 @@ if (typeof jQuery === 'undefined') { throw new Error('Bootstrap\'s JavaScript re
 
     if (!selector) {
       selector = $this.attr('href')
-      selector = selector && /#[A-Za-z]/.test(selector) && selector.replace(/.*(?=#[^\s]*$)/, '') // strip for ie7
+      selector &&= /#[A-Za-z]/.test(selector) && selector.replace(/.*(?=#[^\s]*$)/, '') // strip for ie7
     }
 
     var $parent = selector && $(selector)
@@ -1024,7 +1024,7 @@ if (typeof jQuery === 'undefined') { throw new Error('Bootstrap\'s JavaScript re
 
   Modal.prototype.checkScrollbar = function () {
     if (document.body.clientWidth >= window.innerWidth) return
-    this.scrollbarWidth = this.scrollbarWidth || this.measureScrollbar()
+    this.scrollbarWidth ||= this.measureScrollbar()
   }
 
   Modal.prototype.setScrollbar = function () {
@@ -1325,8 +1325,8 @@ if (typeof jQuery === 'undefined') { throw new Error('Bootstrap\'s JavaScript re
     if (isNaN(marginTop))  marginTop  = 0
     if (isNaN(marginLeft)) marginLeft = 0
 
-    offset.top  = offset.top  + marginTop
-    offset.left = offset.left + marginLeft
+    offset.top += marginTop
+    offset.left += marginLeft
 
     // $.fn.offset doesn't round pixel values
     // so we use setOffset directly with our own function B-0
@@ -1346,7 +1346,7 @@ if (typeof jQuery === 'undefined') { throw new Error('Bootstrap\'s JavaScript re
     var actualHeight = $tip[0].offsetHeight
 
     if (placement == 'top' && actualHeight != height) {
-      offset.top = offset.top + height - actualHeight
+      offset.top += height - actualHeight
     }
 
     var delta = this.getViewportAdjustedDelta(placement, offset, actualWidth, actualHeight)
@@ -1479,11 +1479,11 @@ if (typeof jQuery === 'undefined') { throw new Error('Bootstrap\'s JavaScript re
   }
 
   Tooltip.prototype.tip = function () {
-    return (this.$tip = this.$tip || $(this.options.template))
+    return (this.$tip ||= $(this.options.template))
   }
 
   Tooltip.prototype.arrow = function () {
-    return (this.$arrow = this.$arrow || this.tip().find('.tooltip-arrow'))
+    return (this.$arrow ||= this.tip().find('.tooltip-arrow'))
   }
 
   Tooltip.prototype.validate = function () {
@@ -1630,7 +1630,7 @@ if (typeof jQuery === 'undefined') { throw new Error('Bootstrap\'s JavaScript re
   }
 
   Popover.prototype.arrow = function () {
-    return (this.$arrow = this.$arrow || this.tip().find('.arrow'))
+    return (this.$arrow ||= this.tip().find('.arrow'))
   }
 
   Popover.prototype.tip = function () {
@@ -1869,7 +1869,7 @@ if (typeof jQuery === 'undefined') { throw new Error('Bootstrap\'s JavaScript re
 
     if (!selector) {
       selector = $this.attr('href')
-      selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') // strip for ie7
+      selector &&= selector.replace(/.*(?=#[^\s]*$)/, '') // strip for ie7
     }
 
     if ($this.parent('li').hasClass('active')) return
@@ -2102,7 +2102,7 @@ if (typeof jQuery === 'undefined') { throw new Error('Bootstrap\'s JavaScript re
       var $spy = $(this)
       var data = $spy.data()
 
-      data.offset = data.offset || {}
+      data.offset ||= {}
 
       if (data.offsetBottom) data.offset.bottom = data.offsetBottom
       if (data.offsetTop)    data.offset.top    = data.offsetTop
diff --git a/src/usr/share/rpimonitor/web/js/rpimonitor.status.js b/src/usr/share/rpimonitor/web/js/rpimonitor.status.js
index 5dabf8a..4d3e70e 100644
--- a/src/usr/share/rpimonitor/web/js/rpimonitor.status.js
+++ b/src/usr/share/rpimonitor/web/js/rpimonitor.status.js
@@ -58,15 +58,15 @@ function UpdateStatus () {
       text = "";
       for (var jloop=0; jloop < strips[iloop].line.length; jloop++){
         var line = strips[iloop].line[jloop];
-        text = text + "<p>";
+        text += "<p>";
         try {
-            text = text + eval( line );
+            text += eval( line );
         }
         catch (e) {
-          text = text + "ERROR: " + line + " -> " + e;
+          text += "ERROR: " + line + " -> " + e;
         }
         finally {
-          text = text + "</p>";
+          text += "</p>";
         }
       }
       $("#Text"+iloop).html(text);
diff --git a/src/usr/share/rpimonitor/web/js/rpimonitor.utils.js b/src/usr/share/rpimonitor/web/js/rpimonitor.utils.js
index f30ea47..c947af3 100644
--- a/src/usr/share/rpimonitor/web/js/rpimonitor.utils.js
+++ b/src/usr/share/rpimonitor/web/js/rpimonitor.utils.js
@@ -78,8 +78,8 @@ function Percent(value,total){
 
 function ProgressBar(value, max, warning, danger){
   var percent = ((100 * value ) / max).toFixed(2)
-  var warning = warning || 0
-  var danger = danger || 0
+  var warning ||= 0
+  var danger ||= 0
   var color = ''
   if (danger > warning) {
     if (percent > warning) {
@@ -101,12 +101,12 @@ function ProgressBar(value, max, warning, danger){
 }
 
 function JustGageBar(title, label, min, value, max, width, height, levelColors, warning, critical){
-  width  = width  || 100
-  height = height || 80
-  min = min       || 0
-  max = max       || 1
-  value = value   || 0
-  levelColors = levelColors || percentColors
+  width ||= 100
+  height ||= 80
+  min ||= 0
+  max ||= 1
+  value ||= 0
+  levelColors ||= percentColors
   if (( warning != undefined ) && (critical != undefined)){
     if ( value > critical ) {
       levelColors = [levelColors[2], levelColors[2], levelColors[2]];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant