Browse Source

Add space-infix-ops lint rule

Lutz Roeder 1 year ago
parent
commit
90a7513936
18 changed files with 39 additions and 38 deletions
  1. 1 0
      package.json
  2. 2 2
      source/acuity.js
  3. 2 2
      source/base.js
  4. 1 1
      source/dagre.js
  5. 1 1
      source/dl4j.js
  6. 1 1
      source/hdf5.js
  7. 1 1
      source/hickle.js
  8. 2 2
      source/keras.js
  9. 1 1
      source/megengine.js
  10. 1 1
      source/onnx.js
  11. 11 11
      source/python.js
  12. 6 6
      source/pytorch.js
  13. 1 1
      source/rknn.js
  14. 1 1
      source/server.js
  15. 1 1
      source/tf.js
  16. 4 4
      source/view.js
  17. 1 1
      test/models.js
  18. 1 1
      test/worker.js

+ 1 - 0
package.json

@@ -108,6 +108,7 @@
             "semi": [ "error", "always" ],
             "space-before-blocks": "error",
             "space-in-parens": "error",
+            "space-infix-ops": "error",
             "template-curly-spacing": "error",
             "yoda": "error"
         },

+ 2 - 2
source/acuity.js

@@ -265,7 +265,7 @@ acuity.Inference = class {
         operators.set('convolution', (inputs, params) => {
             if (params.padding === 'VALID') {
                 const out_h = ~~((inputs[0][1] + params.stride_h + params.pad[0] + params.pad[1] - params.ksize_h) / params.stride_h);
-                const out_w = ~~((inputs[0][2] + params.stride_w + params.pad[2] + params.pad[3]- params.ksize_w) / params.stride_w);
+                const out_w = ~~((inputs[0][2] + params.stride_w + params.pad[2] + params.pad[3] - params.ksize_w) / params.stride_w);
                 return [[inputs[0][0], out_h, out_w, params.weights]];
             } else if (params.padding === 'SAME') {
                 const out_h = ~~((inputs[0][1] + params.stride_h - 1) / params.stride_h);
@@ -468,7 +468,7 @@ acuity.Inference = class {
             }
             let newShape = [];
             for (let i = 0; i < begin.length; i++) {
-                newShape = newShape.concat([(end[i] - begin[i])/params.slice_strides[i]]);
+                newShape = newShape.concat([(end[i] - begin[i]) / params.slice_strides[i]]);
             }
             if (params.slice_shrink_axis_mask) {
                 const len = (params.slice_shrink_axis_mask >>> 0).toString(2).length;

+ 2 - 2
source/base.js

@@ -47,8 +47,8 @@ if (!DataView.prototype.getFloat16) {
         return value & 0x8000 ? -f : f;
     };
     DataView.__float16_pow = {
-        1: 1/16384, 2: 1/8192, 3: 1/4096, 4: 1/2048, 5: 1/1024, 6: 1/512, 7: 1/256, 8: 1/128,
-        9: 1/64, 10: 1/32, 11: 1/16, 12: 1/8, 13: 1/4, 14: 1/2, 15: 1, 16: 2,
+        1: 1 / 16384, 2: 1 / 8192, 3: 1 / 4096, 4: 1 / 2048, 5: 1 / 1024, 6: 1 / 512, 7: 1 / 256, 8: 1 / 128,
+        9: 1 / 64, 10: 1 / 32, 11: 1 / 16, 12: 1 / 8, 13: 1 / 4, 14: 1 / 2, 15: 1, 16: 2,
         17: 4, 18: 8, 19: 16, 20: 32, 21: 64, 22: 128, 23: 256, 24: 512,
         25: 1024, 26: 2048, 27: 4096, 28: 8192, 29: 16384, 30: 32768, 31: 65536
     };

+ 1 - 1
source/dagre.js

@@ -1077,7 +1077,7 @@ dagre.layout = (graph, layout) => {
                 };
                 const node = g.node(v);
                 const bl = node && node.label ? node.label.borderLeft : undefined;
-                const br = node && node.label ? node.label.borderRight: undefined;
+                const br = node && node.label ? node.label.borderRight : undefined;
                 const subgraphs = {};
                 const movable = bl ? g.children(v).filter((w) => w !== bl && w !== br) : g.children(v);
                 const barycenters = barycenter(g, movable);

+ 1 - 1
source/dl4j.js

@@ -67,7 +67,7 @@ dl4j.Graph = class {
 
     constructor(metadata, configuration, coefficients) {
         this.inputs = [];
-        this.outputs =[];
+        this.outputs = [];
         this.nodes = [];
         coefficients = coefficients ? new dl4j.NDArray(coefficients) : null;
         const dataType = coefficients ? coefficients.dataType : '?';

+ 1 - 1
source/hdf5.js

@@ -374,7 +374,7 @@ hdf5.Reader = class {
         } else if (e === 0x1F) {
             return f ? NaN : ((s ? -1 : 1) * Infinity);
         }
-        return (s ? -1 : 1) * Math.pow(2, e-15) * (1 + (f / Math.pow(2, 10)));
+        return (s ? -1 : 1) * Math.pow(2, e - 15) * (1 + (f / Math.pow(2, 10)));
     }
 
     float32() {

+ 1 - 1
source/hickle.js

@@ -93,7 +93,7 @@ hickle.Value = class {
         if (typeof name !== 'string') {
             throw new hickle.Error(`Invalid value identifier '${JSON.stringify(name)}'.`);
         }
-        this.name= name;
+        this.name = name;
         this.type = !type && initializer ? initializer.type : type;
         this.initializer = initializer || null;
     }

+ 2 - 2
source/keras.js

@@ -667,7 +667,7 @@ keras.Graph = class {
                                     const [dim] = dims;
                                     for (let i = 1; i < dims.length; i++) {
                                         if (dim.length === dims[i].length) {
-                                            if (!dims[i].every((value, i) => value ===dim[i])) {
+                                            if (!dims[i].every((value, i) => value === dim[i])) {
                                                 throw new python.Error('Invalid array shape.');
                                             }
                                         }
@@ -924,7 +924,7 @@ keras.Value = class {
         if (typeof name !== 'string') {
             throw new keras.Error(`Invalid value identifier '${JSON.stringify(name)}'.`);
         }
-        this.name= name;
+        this.name = name;
         this.type = !type && initializer ? initializer.type  : type;
         this.quantization = initializer && initializer.quantization ? initializer.quantization : null;
         this.initializer = initializer || null;

+ 1 - 1
source/megengine.js

@@ -492,7 +492,7 @@ megengine.Node = class {
         if (this.type.name.length > 4 && this.type.name.startsWith('__') && this.type.name.endsWith('__')) {
             this.type.name = this.type.name.substring(2, this.type.name.length - 2);
         }
-        this.type.category = this.type.category? this.type.category: metadata.type(item.type.replace(/V(\d+)$/, '')).category;
+        this.type.category = this.type.category ? this.type.category : metadata.type(item.type.replace(/V(\d+)$/, '')).category;
         this.inputs = [];
         this.outputs = [];
         this.chain = [];

+ 1 - 1
source/onnx.js

@@ -1173,7 +1173,7 @@ onnx.Context.Graph = class {
                     } else if (attribute.g !== undefined) {
                         attribute.type = onnx.AttributeType.GRAPH;
                     } else if (attribute.sparse_tensor !== undefined) {
-                        attribute.type =onnx.AttributeType.SPARSE_TENSOR;
+                        attribute.type = onnx.AttributeType.SPARSE_TENSOR;
                     } else {
                         attribute.type = onnx.AttributeType.UNDEFINED;
                     }

+ 11 - 11
source/python.js

@@ -2849,7 +2849,7 @@ python.Execution = class {
                             stack = marker.pop();
                             break;
                         case 50: // DUP '2'
-                            stack.push(stack[stack.length-1]);
+                            stack.push(stack[stack.length - 1]);
                             break;
                         case 80: // PERSID 'P'
                             stack.push(this.persistent_load(reader.line()));
@@ -3037,7 +3037,7 @@ python.Execution = class {
                             break;
                         case 97: { // APPEND 'a'
                             const append = stack.pop();
-                            stack[stack.length-1].push(append);
+                            stack[stack.length - 1].push(append);
                             break;
                         }
                         case 101: { // APPENDS 'e'
@@ -4715,7 +4715,7 @@ python.Execution = class {
             params.weight = weight;
             params.bias = bias;
             params.stride = stride;
-            params.padding =padding;
+            params.padding = padding;
             params.dilation = dilation;
             params.groups = groups;
             return params;
@@ -4725,7 +4725,7 @@ python.Execution = class {
             params.weight = weight;
             params.bias = bias;
             params.stride = stride;
-            params.padding =padding;
+            params.padding = padding;
             params.dilation = dilation;
             params.groups = groups;
             return params;
@@ -4735,7 +4735,7 @@ python.Execution = class {
             params.weight = weight;
             params.bias = bias;
             params.stride = stride;
-            params.padding =padding;
+            params.padding = padding;
             params.dilation = dilation;
             params.groups = groups;
             return params;
@@ -4745,7 +4745,7 @@ python.Execution = class {
             params.weight = weight;
             params.bias = bias;
             params.stride = stride;
-            params.padding =padding;
+            params.padding = padding;
             params.dilation = dilation;
             params.groups = groups;
             return params;
@@ -4755,7 +4755,7 @@ python.Execution = class {
             params.weight = weight;
             params.bias = bias;
             params.stride = stride;
-            params.padding =padding;
+            params.padding = padding;
             params.output_padding = output_padding;
             params.dilation = dilation;
             params.groups = groups;
@@ -4766,7 +4766,7 @@ python.Execution = class {
             params.weight = weight;
             params.bias = bias;
             params.stride = stride;
-            params.padding =padding;
+            params.padding = padding;
             params.output_padding = output_padding;
             params.dilation = dilation;
             params.groups = groups;
@@ -6269,7 +6269,7 @@ python.Execution = class {
             }
             _set_from_file(unpickler) {
                 const buffer = unpickler.read(8);
-                const size = buffer.reverse().reduce((a, b) => (a*256)+b, 0);
+                const size = buffer.reverse().reduce((a, b) => (a * 256) + b, 0);
                 if (size !== this.size()) {
                     throw new python.Error('Storage size mismatch.');
                 }
@@ -6329,7 +6329,7 @@ python.Execution = class {
             }
             _set_from_file(unpickler) {
                 const buffer = unpickler.read(8);
-                const size = buffer.reverse().reduce((a, b) => (a*256)+b, 0);
+                const size = buffer.reverse().reduce((a, b) => (a * 256) + b, 0);
                 if (size !== this.size()) {
                     throw new python.Error('Storage size mismatch.');
                 }
@@ -6339,7 +6339,7 @@ python.Execution = class {
             }
             static _new_with_file(unpickler) {
                 const buffer = unpickler.read(8);
-                const size = buffer.reverse().reduce((a, b) => (a*256)+b, 0);
+                const size = buffer.reverse().reduce((a, b) => (a * 256) + b, 0);
                 const storage = new this(size);
                 const itemsize = storage.dtype.itemsize();
                 const data = unpickler.stream(itemsize * size);

+ 6 - 6
source/pytorch.js

@@ -2536,7 +2536,7 @@ pytorch.jit.Execution = class extends pytorch.Execution {
                         metadata.name = type;
                         metadata.inputs = [];
                         metadata.outputs = [];
-                        for (let i = 0; i< args.length; i++) {
+                        for (let i = 0; i < args.length; i++) {
                             const input = {};
                             let argument = args[i];
                             input.name = i.toString();
@@ -3901,7 +3901,7 @@ pytorch.nnapi.SerializedModel = class {
             };
         }
         for (const operand of operands) {
-            for (let i = 0; i< operand.dimensions.length; i++) {
+            for (let i = 0; i < operand.dimensions.length; i++) {
                 operand.dimensions[i] = reader.uint32();
             }
         }
@@ -3953,20 +3953,20 @@ pytorch.nnapi.SerializedModel = class {
             }
         }
         for (const operation of this.operations) {
-            for (let i = 0; i< operation.inputs.length; i++) {
+            for (let i = 0; i < operation.inputs.length; i++) {
                 const index = reader.uint32();
                 operation.inputs[i] = operands[index];
             }
-            for (let i = 0; i< operation.outputs.length; i++) {
+            for (let i = 0; i < operation.outputs.length; i++) {
                 const index = reader.uint32();
                 operation.outputs[i] = operands[index];
             }
         }
-        for (let i = 0; i< this.inputs.length; i++) {
+        for (let i = 0; i < this.inputs.length; i++) {
             const index = reader.uint32();
             this.inputs[i] = operands[index];
         }
-        for (let i = 0; i< this.outputs.length; i++) {
+        for (let i = 0; i < this.outputs.length; i++) {
             const index = reader.uint32();
             this.outputs[i] = operands[index];
         }

+ 1 - 1
source/rknn.js

@@ -274,7 +274,7 @@ rknn.Node = class {
                     const buffer = container.get('openvx');
                     const model = new openvx.Model(buffer);
                     this._type = new rknn.Graph(metadata, 'openvx', 'NBG', model, null);
-                } else if (node.op === 'RKNN_OP_NNBG'&& container && container.has('flatbuffers')) {
+                } else if (node.op === 'RKNN_OP_NNBG' && container && container.has('flatbuffers')) {
                     const buffer = container.get('flatbuffers');
                     const reader = flatbuffers.BinaryReader.open(buffer);
                     const model = rknn.schema.Model.create(reader);

+ 1 - 1
source/server.js

@@ -127,7 +127,7 @@ message.Argument = class {
 message.Value = class {
 
     constructor(data) {
-        this._name= data.name || '';
+        this._name = data.name || '';
         this._type = data.type ? new message.TensorType(data.type) : null;
         this._initializer = data.initializer ? new message.Tensor(data.initializer) : null;
     }

+ 1 - 1
source/tf.js

@@ -2229,7 +2229,7 @@ tf.JsonReader = class {
                 message.list = tf.JsonReader.decodeAttrValueListValue(json.list);
                 break;
             case 'func':
-                message[key]= value;
+                message[key] = value;
                 break;
             default:
                 throw new tf.Error(`Unsupported JSON 'tensorflow.AttrValue.${key}'.`);

+ 4 - 4
source/view.js

@@ -482,8 +482,8 @@ view.View = class {
         const touchMoveHandler = (e) => {
             if (Array.isArray(this._touchPoints) && this._touchPoints.length === 2 && e.touches.length === 2) {
                 const distance = (points) => {
-                    const dx =(points[1].clientX - points[0].clientX);
-                    const dy =(points[1].clientY - points[0].clientY);
+                    const dx = (points[1].clientX - points[0].clientX);
+                    const dy = (points[1].clientY - points[0].clientY);
                     return Math.sqrt(dx * dx + dy * dy);
                 };
                 const d1 = distance(Array.from(e.touches));
@@ -2380,7 +2380,7 @@ view.NodeSidebar = class extends view.ObjectSidebar {
             const type = node.type;
             const item = this.addProperty('type', node.type.identifier || node.type.name);
             if (type && (type.description || type.inputs || type.outputs || type.attributes)) {
-                item.action(type.nodes ? '\u0192': '?', () => {
+                item.action(type.nodes ? '\u0192' : '?', () => {
                     this.emit('show-documentation', null);
                 });
             }
@@ -5699,7 +5699,7 @@ view.ModelFactoryService = class {
                 stream.seek(0);
                 const buffer = stream.peek(Math.min(16, stream.length));
                 const bytes = Array.from(buffer).map((c) => (c < 16 ? '0' : '') + c.toString(16)).join('');
-                const content = stream.length > 268435456 ? `(${bytes}) [${stream.length}]`: `(${bytes})`;
+                const content = stream.length > 268435456 ? `(${bytes}) [${stream.length}]` : `(${bytes})`;
                 throw new view.Error(`Unsupported file content ${content} for extension '.${extension}'.`);
             }
             throw new view.Error("Unsupported file directory.");

+ 1 - 1
test/models.js

@@ -119,7 +119,7 @@ class Queue extends Array {
         for (const target of targets) {
             target.targets = target.target.split(',');
             target.name = target.type ? `${target.type}/${target.targets[0]}` : target.targets[0];
-            target.tags = target.tags? target.tags.split(',') : [];
+            target.tags = target.tags ? target.tags.split(',') : [];
         }
         if (patterns.length > 0) {
             const tags = new Set();

+ 1 - 1
test/worker.js

@@ -524,7 +524,7 @@ export class Target {
         if (this.runtime && this.model.runtime !== this.runtime) {
             throw new Error(`Invalid runtime '${this.model.runtime}'.`);
         }
-        if (this.model.metadata &&!Array.isArray(this.model.metadata) &&
+        if (this.model.metadata && !Array.isArray(this.model.metadata) &&
             this.model.metadata.every((argument) => argument.name && argument.value)) {
             throw new Error("Invalid metadata.'");
         }