Jelajahi Sumber

Add consistent-return lint rule

Lutz Roeder 3 tahun lalu
induk
melakukan
3af474d811
15 mengubah file dengan 38 tambahan dan 18 penghapusan
  1. 1 0
      package.json
  2. 1 0
      publish/notarize.js
  3. 3 0
      source/acuity.js
  4. 2 0
      source/dagre.js
  5. 1 0
      source/json.js
  6. 1 0
      source/numpy.js
  7. 1 1
      source/onnx.js
  8. 8 4
      source/python.js
  9. 1 0
      source/pytorch.js
  10. 1 0
      source/tf.js
  11. 2 0
      source/view-grapher.js
  12. 3 0
      source/view.js
  13. 1 1
      source/weka.js
  14. 2 0
      source/xml.js
  15. 10 12
      test/models.js

+ 1 - 0
package.json

@@ -40,6 +40,7 @@
             "array-callback-return": "error",
             "array-callback-return": "error",
             "brace-style": [ "error", "stroustrup", { "allowSingleLine": true } ],
             "brace-style": [ "error", "stroustrup", { "allowSingleLine": true } ],
             "curly": "error",
             "curly": "error",
+            "consistent-return": "error",
             "default-case": "error",
             "default-case": "error",
             "default-case-last": "error",
             "default-case-last": "error",
             "indent": [ "error", 4, { "SwitchCase": 1 } ],
             "indent": [ "error", 4, { "SwitchCase": 1 } ],

+ 1 - 0
publish/notarize.js

@@ -13,4 +13,5 @@ exports.default = function (context) {
             });
             });
         }
         }
     }
     }
+    return null;
 };
 };

+ 3 - 0
source/acuity.js

@@ -472,6 +472,7 @@ acuity.Inference = class {
                 const out_h = ~~((inputs[0][1] + params.stride - 1) / params.stride);
                 const out_h = ~~((inputs[0][1] + params.stride - 1) / params.stride);
                 return [ [ inputs[0][0], out_h, params.weights ] ];
                 return [ [ inputs[0][0], out_h, params.weights ] ];
             }
             }
+            return null;
         });
         });
         operators.set('convolution', (inputs, params) => {
         operators.set('convolution', (inputs, params) => {
             if (params.padding == 'VALID') {
             if (params.padding == 'VALID') {
@@ -484,6 +485,7 @@ acuity.Inference = class {
                 const out_w = ~~((inputs[0][2] + params.stride_w - 1) / params.stride_w);
                 const out_w = ~~((inputs[0][2] + params.stride_w - 1) / params.stride_w);
                 return [ [ inputs[0][0], out_h, out_w, params.weights ] ];
                 return [ [ inputs[0][0], out_h, out_w, params.weights ] ];
             }
             }
+            return null;
         });
         });
         operators.set('deconvolution', (inputs, params) => {
         operators.set('deconvolution', (inputs, params) => {
             return [ params.output_shape.map((item, index) => item == 0 ? inputs[0][index] : item) ];
             return [ params.output_shape.map((item, index) => item == 0 ? inputs[0][index] : item) ];
@@ -540,6 +542,7 @@ acuity.Inference = class {
                 const out_w = ~~((inputs[0][2] + params.stride_w - 1) / params.stride_w);
                 const out_w = ~~((inputs[0][2] + params.stride_w - 1) / params.stride_w);
                 return [ [inputs[0][0], out_h, out_w, inputs[0][3]] ];
                 return [ [inputs[0][0], out_h, out_w, inputs[0][3]] ];
             }
             }
+            return null;
         });
         });
         operators.set('reduce', (inputs, params) => {
         operators.set('reduce', (inputs, params) => {
             const newShape = inputs[0].slice();
             const newShape = inputs[0].slice();

+ 2 - 0
source/dagre.js

@@ -2144,6 +2144,7 @@ dagre.Graph = class {
                 return parent;
                 return parent;
             }
             }
         }
         }
+        return null;
     }
     }
 
 
     children(v) {
     children(v) {
@@ -2156,6 +2157,7 @@ dagre.Graph = class {
         else if (this.hasNode(v)) {
         else if (this.hasNode(v)) {
             return [];
             return [];
         }
         }
+        return null;
     }
     }
 
 
     predecessors(v) {
     predecessors(v) {

+ 1 - 0
source/json.js

@@ -253,6 +253,7 @@ json.TextReader = class {
             case '-': return this._number();
             case '-': return this._number();
             default: this._unexpected();
             default: this._unexpected();
         }
         }
+        return null;
     }
     }
 
 
     _number() {
     _number() {

+ 1 - 0
source/numpy.js

@@ -541,6 +541,7 @@ numpy.Utility = class {
                 }
                 }
                 return weights;
                 return weights;
             }
             }
+            return null;
         };
         };
         const keys = [ '', 'blobs', 'model' ];
         const keys = [ '', 'blobs', 'model' ];
         for (const key of keys) {
         for (const key of keys) {

+ 1 - 1
source/onnx.js

@@ -1631,7 +1631,7 @@ onnx.GraphContext = class {
             }
             }
             default: {
             default: {
                 // throw new onnx.Error("Unsupported tensor type '" + type.value + "'.");
                 // throw new onnx.Error("Unsupported tensor type '" + type.value + "'.");
-                break;
+                return undefined;
             }
             }
         }
         }
     }
     }

+ 8 - 4
source/python.js

@@ -2458,6 +2458,7 @@ python.Execution = class {
                 if (safe) {
                 if (safe) {
                     return null;
                     return null;
                 }
                 }
+                throw err;
             }
             }
         });
         });
         this.registerFunction('dill.dill._load_type', function(name) {
         this.registerFunction('dill.dill._load_type', function(name) {
@@ -2909,6 +2910,7 @@ python.Execution = class {
                 return value;
                 return value;
             }
             }
         }
         }
+        return undefined;
     }
     }
 
 
     statement(statement, context) {
     statement(statement, context) {
@@ -3028,6 +3030,7 @@ python.Execution = class {
                 throw new python.Error("Unsupported statement '" + statement.type + "'.");
                 throw new python.Error("Unsupported statement '" + statement.type + "'.");
             }
             }
         }
         }
+        return undefined;
     }
     }
 
 
 
 
@@ -3038,7 +3041,7 @@ python.Execution = class {
                 const target = expression.target;
                 const target = expression.target;
                 if (target.type === 'id') {
                 if (target.type === 'id') {
                     context.set(target.value, this.expression(expression.expression, context));
                     context.set(target.value, this.expression(expression.expression, context));
-                    return;
+                    return undefined;
                 }
                 }
                 else if (target.type === '[]') {
                 else if (target.type === '[]') {
                     if (target.target.type === 'id' &&
                     if (target.target.type === 'id' &&
@@ -3049,13 +3052,13 @@ python.Execution = class {
                             context.set(target.target.value, context.get(target.target.value) || {});
                             context.set(target.target.value, context.get(target.target.value) || {});
                         }
                         }
                         context.get(target.target.value)[index] = this.expression(expression.expression, context);
                         context.get(target.target.value)[index] = this.expression(expression.expression, context);
-                        return;
+                        return undefined;
                     }
                     }
                 }
                 }
                 else if (target.type === '.' &&
                 else if (target.type === '.' &&
                     target.member.type === 'id') {
                     target.member.type === 'id') {
                     this.expression(target.target, context)[target.member.value] = this.expression(expression.expression, context);
                     this.expression(target.target, context)[target.member.value] = this.expression(expression.expression, context);
-                    return;
+                    return undefined;
                 }
                 }
                 else if (target.type === 'tuple') {
                 else if (target.type === 'tuple') {
                     context.target.push(target.value);
                     context.target.push(target.value);
@@ -3071,7 +3074,7 @@ python.Execution = class {
                         for (let i = 0; i < value.length; i++) {
                         for (let i = 0; i < value.length; i++) {
                             context.set(target.value[i].value, value[i]);
                             context.set(target.value[i].value, value[i]);
                         }
                         }
-                        return;
+                        return undefined;
                     }
                     }
                 }
                 }
                 break;
                 break;
@@ -3178,6 +3181,7 @@ python.Execution = class {
                 throw new python.Error("Unsupported expression '" + expression.type + "'.");
                 throw new python.Error("Unsupported expression '" + expression.type + "'.");
             }
             }
         }
         }
+        return undefined;
     }
     }
 
 
     _target(expression, context) {
     _target(expression, context) {

+ 1 - 0
source/pytorch.js

@@ -3472,6 +3472,7 @@ pytorch.Container.Zip.Execution = class extends pytorch.Execution {
                 return value;
                 return value;
             }
             }
         }
         }
+        return undefined;
     }
     }
 
 
     push(node) {
     push(node) {

+ 1 - 0
source/tf.js

@@ -1959,6 +1959,7 @@ tf.EventFileReader = class {
             this._stream.skip(4); // masked crc of data
             this._stream.skip(4); // masked crc of data
             return event;
             return event;
         }
         }
+        return null;
     }
     }
 };
 };
 
 

+ 2 - 0
source/view-grapher.js

@@ -86,6 +86,7 @@ grapher.Graph = class {
                 return parent;
                 return parent;
             }
             }
         }
         }
+        return null;
     }
     }
 
 
     children(key) {
     children(key) {
@@ -102,6 +103,7 @@ grapher.Graph = class {
         else if (this.hasNode(key)) {
         else if (this.hasNode(key)) {
             return [];
             return [];
         }
         }
+        return null;
     }
     }
 
 
     build(document, origin) {
     build(document, origin) {

+ 3 - 0
source/view.js

@@ -518,6 +518,7 @@ view.View = class {
             this._sidebar.close();
             this._sidebar.close();
             return this._updateGraph(this._model, this._graphs.slice(1));
             return this._updateGraph(this._model, this._graphs.slice(1));
         }
         }
+        return null;
     }
     }
 
 
     renderGraph(model, graph) {
     renderGraph(model, graph) {
@@ -1612,6 +1613,7 @@ view.ModelFactoryService = class {
             }
             }
 
 
             const modelContext = new view.ModelContext(context, containers);
             const modelContext = new view.ModelContext(context, containers);
+            /* eslint-disable consistent-return */
             return this._openContext(modelContext).then((model) => {
             return this._openContext(modelContext).then((model) => {
                 if (model) {
                 if (model) {
                     return model;
                     return model;
@@ -1626,6 +1628,7 @@ view.ModelFactoryService = class {
                 }
                 }
                 this._unsupported(modelContext);
                 this._unsupported(modelContext);
             });
             });
+            /* eslint-enable consistent-return */
         });
         });
     }
     }
 
 

+ 1 - 1
source/weka.js

@@ -133,7 +133,7 @@ java.io.InputObjectStream = class {
                 return classDesc;
                 return classDesc;
             }
             }
             case 0x7D: // TC_PROXYCLASSDESC
             case 0x7D: // TC_PROXYCLASSDESC
-                break;
+                return null;
             default:
             default:
                 throw new java.io.Error("Unsupported code '" + code + "'.");
                 throw new java.io.Error("Unsupported code '" + code + "'.");
         }
         }

+ 2 - 0
source/xml.js

@@ -935,6 +935,7 @@ xml.TextReader = class {
         }
         }
     }
     }
 
 
+    /* eslint-disable consistent-return */
     _entityReference() {
     _entityReference() {
         if (this._char === '&') {
         if (this._char === '&') {
             const position = this._position;
             const position = this._position;
@@ -982,6 +983,7 @@ xml.TextReader = class {
         }
         }
         this._unexpected();
         this._unexpected();
     }
     }
+    /* eslint-enable consistent-return */
 
 
     _comment() {
     _comment() {
         const data = this._terminal('--');
         const data = this._terminal('--');

+ 10 - 12
test/models.js

@@ -523,7 +523,7 @@ const download = (folder, targets, sources) => {
         if (sources.length > 0) {
         if (sources.length > 0) {
             return download(folder, targets, sources);
             return download(folder, targets, sources);
         }
         }
-        return;
+        return null;
     });
     });
 };
 };
 
 
@@ -755,24 +755,22 @@ const next = () => {
     clearLine();
     clearLine();
 
 
     const sources = item.source;
     const sources = item.source;
-    return download(folder, targets, sources).then(() => {
+    download(folder, targets, sources).then(() => {
         return loadModel(folder + '/' + target, item).then((model) => {
         return loadModel(folder + '/' + target, item).then((model) => {
             return renderModel(model, item).then(() => {
             return renderModel(model, item).then(() => {
-                if (item.error) {
-                    console.error('Expected error.');
-                }
-                else {
-                    return next();
+                if (!item.error) {
+                    next();
+                    return;
                 }
                 }
+                console.error('Expected error.');
             });
             });
         });
         });
     }).catch((error) => {
     }).catch((error) => {
-        if (!item.error || item.error != error.message) {
-            console.error(error.message);
-        }
-        else {
-            return next();
+        if (item.error && item.error == error.message) {
+            next();
+            return;
         }
         }
+        console.error(error.message);
     });
     });
 };
 };