From 39214217be28668dc899b2e16798a32881cfb28a Mon Sep 17 00:00:00 2001 From: Eden Sun Date: Wed, 18 Jan 2017 17:14:45 +0800 Subject: [PATCH 1/4] replace jshint with eslint --- .eslintrc.js | 7 +++++++ .jshintrc | 15 --------------- package.json | 6 +++--- 3 files changed, 10 insertions(+), 18 deletions(-) create mode 100644 .eslintrc.js delete mode 100644 .jshintrc diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..c6443bf --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,7 @@ +module.exports = { + "env": { + "node": true, + "commonjs": true + }, + "extends": "eslint:recommended" +}; diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index f993d36..0000000 --- a/.jshintrc +++ /dev/null @@ -1,15 +0,0 @@ -{ - "curly": true, - "eqeqeq": true, - "forin": true, - "immed": true, - "latedef": true, - "newcap": true, - "noarg": true, - "noempty": true, - "undef": true, - "trailing": true, - "node": true, - "nomen": false, - "plusplus": false -} diff --git a/package.json b/package.json index c14b67e..8a1c46a 100644 --- a/package.json +++ b/package.json @@ -14,16 +14,16 @@ "license": "MIT", "main": "lib/snmp.js", "scripts": { - "test": "NODE_PATH=lib mocha -R spec", - "hint": "jshint *.js lib/*.js", + "test": "npm run lint && NODE_PATH=lib mocha -R spec", + "lint": "eslint lib", "doc": "docco lib/* example.js 2>/dev/null", "cov": "jscoverage lib lib-cov && EXPRESS_COV=1 NODE_PATH=lib-cov mocha -R html-cov > docs/coverage.html" }, "dependencies": {}, "devDependencies": { "docco": "~0.6.2", + "eslint": "^3.13.1", "jscoverage": "~0.3.6", - "jshint": "~1.1.0", "mocha": "~1.9.0", "should": "~1.2.2", "snmpjs": "~0.1.3" From 8a5a8dcc65f732a3c89755b4ba3eed70677cdff9 Mon Sep 17 00:00:00 2001 From: Eden Sun Date: Wed, 18 Jan 2017 17:15:03 +0800 Subject: [PATCH 2/4] fix lint error --- lib/asn1ber.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/asn1ber.js b/lib/asn1ber.js index 80dd37b..29e790a 100644 --- a/lib/asn1ber.js +++ b/lib/asn1ber.js @@ -262,7 +262,7 @@ exports.encodeSequence = function (contents) { // Encode an OctetString, which is a wrapper of type `04`. exports.encodeOctetString = function (string) { - var buf, contents; + var contents; if (typeof string === 'string') { contents = new Buffer(string); @@ -340,7 +340,7 @@ exports.encodeRequest = function (type, contents) { // Parse and return type, data length and header length. function typeAndLength(buf) { - var res, len, i; + var res, i; res = { type: buf[0], len: 0, header: 1 }; if (buf[1] < 128) { @@ -453,13 +453,12 @@ exports.parseOid = function (buf) { // This is for example an IpAddress. exports.parseArray = function (buf) { - var i, nelem, array; + var i, array; if (buf[0] !== T.IpAddress) { throw new Error('Buffer does not appear to be an array type.'); } - nelem = buf[1]; array = []; for (i = 0; i < buf[1]; i++) { From a343b81303657a718f1b10ea1005d9d4fb1dae4d Mon Sep 17 00:00:00 2001 From: Eden Sun Date: Wed, 18 Jan 2017 17:17:59 +0800 Subject: [PATCH 3/4] fix lint --- .eslintrc.js | 5 ++++- lib/snmp.js | 10 ++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index c6443bf..eb485b7 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -3,5 +3,8 @@ module.exports = { "node": true, "commonjs": true }, - "extends": "eslint:recommended" + "extends": "eslint:recommended", + "rules": { + "no-console": 0 + } }; diff --git a/lib/snmp.js b/lib/snmp.js index 9bcdd10..36f879e 100644 --- a/lib/snmp.js +++ b/lib/snmp.js @@ -85,8 +85,6 @@ function concatBuffers(buffers) { // Clear a pending packet when it times out or is successfully received. function clearRequest(reqs, reqid) { - var self = this; - var entry = reqs[reqid]; if (entry) { if (entry.timeout) { @@ -132,7 +130,7 @@ function parseOids(options) { // Update targ with attributes from _defs. // Any existing attributes on targ are untouched. -function defaults(targ, _defs) { +function defaults(targ) { [].slice.call(arguments, 1).forEach(function (def) { Object.keys(def).forEach(function (key) { if (!targ.hasOwnProperty(key)) { @@ -213,7 +211,7 @@ exports.encode = encode; // make us blow up. function parse(buf) { - var pkt, oid, bvb, vb, hdr, vbhdr; + var pkt, bvb, vb, hdr; pkt = new Packet(); @@ -571,7 +569,7 @@ Session.prototype.sendMsg = function (pkt, options, callback) { } // Send the message. - self.socket.send(buf, 0, buf.length, options.port, options.host, function (err, bytes) { + self.socket.send(buf, 0, buf.length, options.port, options.host, function (err) { var entry = self.reqs[reqid]; if (err) { @@ -659,7 +657,7 @@ Session.prototype.getAll = function (options, callback) { } function getOne(c) { - var oid, pkt, m, vb; + var pkt, m, vb; pkt = new Packet(); pkt.community = options.community; From ca85a49d2b2c5b9f7018d95c21ebbc7a7cee1a73 Mon Sep 17 00:00:00 2001 From: Eden Sun Date: Fri, 20 Jan 2017 16:05:51 +0800 Subject: [PATCH 4/4] not to lint to pass test on node 4- --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8a1c46a..f9042ab 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "license": "MIT", "main": "lib/snmp.js", "scripts": { - "test": "npm run lint && NODE_PATH=lib mocha -R spec", + "test": "NODE_PATH=lib mocha -R spec", "lint": "eslint lib", "doc": "docco lib/* example.js 2>/dev/null", "cov": "jscoverage lib lib-cov && EXPRESS_COV=1 NODE_PATH=lib-cov mocha -R html-cov > docs/coverage.html"