Browse Source

Add operator-assignment lint rule

Lutz Roeder 1 year ago
parent
commit
642296d265
10 changed files with 22 additions and 22 deletions
  1. 1 1
      publish/eslint.config.js
  2. 2 2
      source/base.js
  3. 1 1
      source/browser.js
  4. 1 1
      source/coreml.js
  5. 1 1
      source/grapher.js
  6. 1 1
      source/kmodel.js
  7. 5 5
      source/protobuf.js
  8. 3 3
      source/python.js
  9. 5 5
      source/tf.js
  10. 2 2
      source/view.js

+ 1 - 1
publish/eslint.config.js

@@ -192,7 +192,7 @@ export default [
             'object-curly-spacing': ['error', 'always'],
             'object-shorthand': 'error',
             // 'one-var': 'error',
-            // 'operator-assignment': 'error',
+            'operator-assignment': 'error',
             'prefer-arrow-callback': 'error',
             'prefer-const': 'error',
             'prefer-destructuring': ['error', { 'array': true }],

+ 2 - 2
source/base.js

@@ -199,7 +199,7 @@ DataView.prototype.getFloat8e5m2 = function(byteOffset, fn, uz) {
 };
 
 DataView.prototype.getIntBits = DataView.prototype.getUintBits || function(offset, bits, littleEndian) {
-    offset = offset * bits;
+    offset *= bits;
     const position = Math.floor(offset / 8);
     const remainder = offset % 8;
     let value = 0;
@@ -216,7 +216,7 @@ DataView.prototype.getIntBits = DataView.prototype.getUintBits || function(offse
 };
 
 DataView.prototype.getUintBits = DataView.prototype.getUintBits || function(offset, bits, littleEndian) {
-    offset = offset * bits;
+    offset *= bits;
     const position = Math.floor(offset / 8);
     const remainder = offset % 8;
     let value = 0;

+ 1 - 1
source/browser.js

@@ -753,7 +753,7 @@ host.BrowserHost.FileStream = class {
 
     _read(buffer, offset) {
         let index = Math.floor(offset / this._size);
-        offset = offset - (index * this._size);
+        offset -= index * this._size;
         const chunk = this._chunks[index++];
         let destination = Math.min(chunk.length - offset, buffer.length);
         buffer.set(chunk.subarray(offset, offset + destination), 0);

+ 1 - 1
source/coreml.js

@@ -800,7 +800,7 @@ coreml.Context = class {
     }
 
     model(model, group, description) {
-        this.groups = this.groups | (group.length > 0 ? true : false);
+        this.groups |= group.length > 0;
         const shortDescription = model && model.description && model.description.metadata && model.description.metadata.shortDescription ? model.description.metadata.shortDescription : '';
         switch (model.Type) {
             case 'neuralNetworkClassifier': {

+ 1 - 1
source/grapher.js

@@ -253,7 +253,7 @@ grapher.Node = class {
         this.height = 0;
         for (const block of this._blocks) {
             block.measure();
-            this.height = this.height + block.height;
+            this.height += block.height;
         }
         this.width = Math.max(...this._blocks.map((block) => block.width));
         for (const block of this._blocks) {

+ 1 - 1
source/kmodel.js

@@ -1093,7 +1093,7 @@ kmodel.BinaryReader = class {
                 const offset = (position / 8) >> 0;
                 const start = (position & 7);
                 const count = Math.min((offset + 1) * 8, end) - position;
-                value = value | ((buffer[offset] >>> start) & ((1 << count) - 1)) << (position - fields[i][1]);
+                value |= ((buffer[offset] >>> start) & ((1 << count) - 1)) << (position - fields[i][1]);
                 position += count;
             }
             obj[key] = value;

+ 5 - 5
source/protobuf.js

@@ -223,7 +223,7 @@ protobuf.BinaryReader = class {
             return value;
         }
         c = this.byte();
-        value = value + ((c & 127) * 0x10000000);
+        value += (c & 127) * 0x10000000;
         if (c < 128) {
             return value;
         }
@@ -260,7 +260,7 @@ protobuf.BinaryReader = class {
                         }
                         if (this._position < this._length) {
                             c = this.byte();
-                            value = value + ((c & 127) * 0x10000000);
+                            value += (c & 127) * 0x10000000;
                             if (c < 128) {
                                 return value;
                             }
@@ -1219,11 +1219,11 @@ protobuf.TextReader = class {
                                     }
                                     c = c.charCodeAt(0);
                                     if (c >= 65 && c <= 70) {
-                                        c = c - 55;
+                                        c -= 55;
                                     } else if (c >= 97 && c <= 102) {
-                                        c = c - 87;
+                                        c -= 87;
                                     } else if (c >= 48 && c <= 57) {
-                                        c = c - 48;
+                                        c -= 48;
                                     } else {
                                         c = -1;
                                     }

+ 3 - 3
source/python.js

@@ -2473,11 +2473,11 @@ python.Execution = class {
                                     }
                                     let c = token.charCodeAt(i++);
                                     if (c >= 65 && c <= 70) {
-                                        c = c - 55;
+                                        c -= 55;
                                     } else if (c >= 97 && c <= 102) {
-                                        c = c - 87;
+                                        c -= 87;
                                     } else if (c >= 48 && c <= 57) {
-                                        c = c - 48;
+                                        c -= 48;
                                     } else {
                                         c = -1;
                                     }

+ 5 - 5
source/tf.js

@@ -1462,7 +1462,7 @@ tf.TensorBundle.Table.Block = class {
                     break;
                 }
                 key = key.substring(0, sharedSize);
-                key = key + decoder.decode(reader.read(nonSharedSize));
+                key += decoder.decode(reader.read(nonSharedSize));
                 const value = reader.read(valueSize);
                 this.entries.set(key, value);
             }
@@ -1594,12 +1594,12 @@ tf.EventFileReader = class {
                 crc = crc & 1 ? (crc >>> 1) ^ poly : crc >>> 1;
                 crc = crc & 1 ? (crc >>> 1) ^ poly : crc >>> 1;
                 crc = crc & 1 ? (crc >>> 1) ^ poly : crc >>> 1;
-                crc = crc >>> 0;
+                crc >>>= 0;
             }
-            crc = crc ^ 0xffffffff;
-            crc = crc >>> 0;
+            crc ^= 0xffffffff;
+            crc >>>= 0;
             crc = ((crc >> 15) | (crc << 17)) + 0xa282ead8;
-            crc = crc >>> 0;
+            crc >>>= 0;
             return crc;
         };
         const buffer = stream.peek(12);

+ 2 - 2
source/view.js

@@ -568,8 +568,8 @@ view.View = class {
                 x += rect.left + (rect.width / 2);
                 y += rect.top + (rect.height / 2);
             }
-            x = x / selection.length;
-            y = y / selection.length;
+            x /= selection.length;
+            y /= selection.length;
             const rect = container.getBoundingClientRect();
             const left = (container.scrollLeft + x - rect.left) - (rect.width / 2);
             const top = (container.scrollTop + y - rect.top) - (rect.height / 2);