avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject [avro] branch master updated: AVRO-2494: Introduce JSHint for linting the JavaScript bindings
Date Fri, 16 Aug 2019 19:01:19 GMT
This is an automated email from the ASF dual-hosted git repository.

dkulp pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/avro.git


The following commit(s) were added to refs/heads/master by this push:
     new 9b0c88c  AVRO-2494: Introduce JSHint for linting the JavaScript bindings
9b0c88c is described below

commit 9b0c88cc6e9a4405d5731ddeda3ed831206e486c
Author: Kengo Seki <sekikn@apache.org>
AuthorDate: Thu Aug 1 00:51:14 2019 +0900

    AVRO-2494: Introduce JSHint for linting the JavaScript bindings
---
 lang/js/build.sh         |  2 +-
 lang/js/lib/protocols.js | 33 ++++++++++++++++++++++-----------
 lang/js/lib/schemas.js   |  6 ++++--
 lang/js/lib/utils.js     |  5 ++++-
 lang/js/package.json     |  4 +++-
 5 files changed, 34 insertions(+), 16 deletions(-)

diff --git a/lang/js/build.sh b/lang/js/build.sh
index a6cdb6b..a936a04 100755
--- a/lang/js/build.sh
+++ b/lang/js/build.sh
@@ -21,7 +21,7 @@ cd `dirname "$0"`
 
 case "$1" in
   lint)
-    echo 'This is a stub where someone can provide linting.'
+    npm run lint
     ;;
   test)
     npm install
diff --git a/lang/js/lib/protocols.js b/lang/js/lib/protocols.js
index ab99172..b46bd49 100644
--- a/lang/js/lib/protocols.js
+++ b/lang/js/lib/protocols.js
@@ -444,6 +444,7 @@ StatelessEmitter.prototype._emit = function (message, req, cb) {
           }
 
           var tap = new Tap(buf);
+          var args;
           try {
             var info = self._finalizeHandshake(tap, handshakeReq);
             serverHashString = info.serverHashString;
@@ -452,7 +453,7 @@ StatelessEmitter.prototype._emit = function (message, req, cb) {
               return;
             }
             self._idType._read(tap); // Skip metadata.
-            var args = self._decodeArguments(tap, serverHashString, message);
+            args = self._decodeArguments(tap, serverHashString, message);
           } catch (err) {
             done(err);
             return;
@@ -547,8 +548,9 @@ function StatefulEmitter(ptcl, readable, writable, opts) {
 
   function onHandshakeData(buf) {
     var tap = new Tap(buf);
+    var info;
     try {
-      var info = self._finalizeHandshake(tap, handshakeReq);
+      info = self._finalizeHandshake(tap, handshakeReq);
     } catch (err) {
       self.emit('error', err);
       self.destroy(); // This isn't a recoverable error.
@@ -568,8 +570,9 @@ function StatefulEmitter(ptcl, readable, writable, opts) {
 
   function onMessageData(buf) {
     var tap = new Tap(buf);
+    var id;
     try {
-      var id = self._idType._read(tap);
+      id = self._idType._read(tap);
       if (!id) {
         throw new Error('missing ID');
       }
@@ -584,8 +587,9 @@ function StatefulEmitter(ptcl, readable, writable, opts) {
       return;
     }
 
+    var args;
     try {
-      var args = self._decodeArguments(
+      args = self._decodeArguments(
         tap,
         self._serverHashString,
         info.message
@@ -701,9 +705,11 @@ MessageListener.prototype._validateHandshake = function (reqTap, resTap)
{
   // occurs when parsing the request, a response with match NONE will be sent.
   // Also emits 'handshake' event with both the request and the response.
   var validationErr = null;
+  var handshakeReq;
+  var serverHashString;
   try {
-    var handshakeReq = HANDSHAKE_REQUEST_TYPE._read(reqTap);
-    var serverHashString = handshakeReq.serverHash.toString('binary');
+    handshakeReq = HANDSHAKE_REQUEST_TYPE._read(reqTap);
+    serverHashString = handshakeReq.serverHash.toString('binary');
   } catch (err) {
     validationErr = err;
   }
@@ -827,14 +833,16 @@ function StatelessListener(ptcl, readableFactory, opts) {
       return;
     }
 
+    var name;
+    var req;
     try {
       self._idType._read(reqTap); // Skip metadata.
-      var name = STRING_TYPE._read(reqTap);
+      name = STRING_TYPE._read(reqTap);
       self._message = self._ptcl._messages[name];
       if (!self._message) {
         throw new Error(f('unknown message: %s', name));
       }
-      var req = self._decodeRequest(reqTap, self._message);
+      req = self._decodeRequest(reqTap, self._message);
     } catch (err) {
       onResponse(err);
       return;
@@ -908,13 +916,16 @@ function StatefulListener(ptcl, readable, writable, opts) {
     }
 
     self._pending++;
+    var name;
+    var message;
+    var req;
     try {
-      var name = STRING_TYPE._read(reqTap);
-      var message = self._ptcl._messages[name];
+      name = STRING_TYPE._read(reqTap);
+      message = self._ptcl._messages[name];
       if (!message) {
         throw new Error('unknown message: ' + name);
       }
-      var req = self._decodeRequest(reqTap, message);
+      req = self._decodeRequest(reqTap, message);
     } catch (err) {
       onResponse(err);
       return;
diff --git a/lang/js/lib/schemas.js b/lang/js/lib/schemas.js
index a681826..2a3e5e5 100644
--- a/lang/js/lib/schemas.js
+++ b/lang/js/lib/schemas.js
@@ -93,7 +93,8 @@ function createType(attrs, opts) {
       // Reference to a primitive type. These are also defined names by default
       // so we create the appropriate type and it to the registry for future
       // reference.
-      return opts.registry[attrs] = createType({type: attrs}, opts);
+      type = opts.registry[attrs] = createType({type: attrs}, opts);
+      return type;
     }
     throw new Error(f('undefined type name: %s', attrs));
   }
@@ -1789,8 +1790,9 @@ LogicalType.prototype._write = function (tap, any) {
 };
 
 LogicalType.prototype._check = function (any, cb) {
+  var val;
   try {
-    var val = this._toValue(any);
+    val = this._toValue(any);
   } catch (err) {
     if (cb) {
       cb(PATH.slice(), any, this);
diff --git a/lang/js/lib/utils.js b/lang/js/lib/utils.js
index ab1bcdc..0d42b07 100644
--- a/lang/js/lib/utils.js
+++ b/lang/js/lib/utils.js
@@ -140,7 +140,10 @@ function Lcg(seed) {
   var state = Math.floor(seed || Math.random() * (m - 1));
 
   this._max = m;
-  this._nextInt = function () { return state = (a * state + c) % m; };
+  this._nextInt = function () {
+    state = (a * state + c) % m;
+    return state;
+  };
 }
 
 Lcg.prototype.nextBoolean = function () {
diff --git a/lang/js/package.json b/lang/js/package.json
index 1eb0a07..e63781a 100644
--- a/lang/js/package.json
+++ b/lang/js/package.json
@@ -36,7 +36,8 @@
   "scripts": {
     "cover": "istanbul cover _mocha",
     "test": "mocha",
-    "clean": "rm -rf coverage node_modules"
+    "clean": "rm -rf coverage node_modules",
+    "lint": "jshint lib test"
   },
   "dependencies": {
     "underscore": "*"
@@ -44,6 +45,7 @@
   "devDependencies": {
     "coveralls": "^2.11.4",
     "istanbul": "^0.3.19",
+    "jshint": "^2.10.2",
     "mocha": "^2.3.2",
     "tmp": "^0.0.28"
   },


Mime
View raw message