Complete ESLint conversion and cleanup (#490)

* Add extension to ESLint config file

The .eslintrc file without an extension was deprecated a few years ago,
so this change renames the file to add the required extension.

See: https://github.com/eslint/eslint/commit/c9a8883d450d63a8d044a9e66d275f5b1973a3ba

* Add ESLint to package.json

This change adds ESLint as a dev-dependency and adds a lint script that
will run ESLint.

* Complete switch from JSHint to ESLint

Convert all the JSHint rules to the ESLint equivalents where possible.
The no-undef rule in ESLint caught a few cases of undefined usages in
the tests, so they were also fixed.

* Add a .eslintignore file

The HTML coverage report is currently being linted, which causes a lot
if invalid linting errors. This change adds a ignore file to ensure these
files are properly skipped during linting.
This commit is contained in:
Tim Oram
2018-06-25 19:54:04 +02:00
committed by Eduardo Diaz
parent cc61447047
commit c86e573d16
13 changed files with 44 additions and 45 deletions
+2
View File
@@ -0,0 +1,2 @@
.nyc_output/
coverage/
-8
View File
@@ -1,8 +0,0 @@
{
"env": {
"es6": true
},
"rules": {
"indent": [2,2]
}
}
+23
View File
@@ -0,0 +1,23 @@
{
"root": true,
"parserOptions": {
"ecmaVersion": 6
},
"env": {
"es6": true,
"node": true
},
"rules": {
"comma-style": "error",
"dot-notation": "error",
"indent": ["error", 2],
"no-control-regex": "error",
"no-div-regex": "error",
"no-eval": "error",
"no-implied-eval": "error",
"no-invalid-regexp": "error",
"no-trailing-spaces": "error",
"no-undef": "error",
"no-unused-vars": "error"
}
}
-22
View File
@@ -1,22 +0,0 @@
{
"evil": true,
"regexdash": true,
"browser": true,
"wsh": true,
"trailing": true,
"sub": true,
"unused": true,
"undef": true,
"laxcomma": true,
"node": true,
"browser": false,
"esnext": true,
"globals": {
"describe": true,
"it": true,
"require": true,
"atob": false,
"escape": true,
"before": true
}
}
+3 -1
View File
@@ -4,7 +4,8 @@
"description": "JSON Web Token implementation (symmetric and asymmetric)",
"main": "index.js",
"scripts": {
"test": "nyc --reporter=html --reporter=text mocha && nsp check && cost-of-modules"
"lint": "eslint .",
"test": "npm run lint && nyc --reporter=html --reporter=text mocha && nsp check && cost-of-modules"
},
"repository": {
"type": "git",
@@ -34,6 +35,7 @@
"chai": "^1.10.0",
"conventional-changelog": "~1.1.0",
"cost-of-modules": "^1.0.1",
"eslint": "^4.19.1",
"mocha": "^2.1.0",
"nsp": "^2.6.2",
"nyc": "^11.8.0",
+5
View File
@@ -0,0 +1,5 @@
{
"env": {
"mocha": true
}
}
+2 -2
View File
@@ -19,14 +19,14 @@ describe('signing a token asynchronously', function() {
});
it('should work with empty options', function (done) {
jwt.sign({abc: 1}, "secret", {}, function (err, res) {
jwt.sign({abc: 1}, "secret", {}, function (err) {
expect(err).to.be.null();
done();
});
});
it('should work without options object at all', function (done) {
jwt.sign({abc: 1}, "secret", function (err, res) {
jwt.sign({abc: 1}, "secret", function (err) {
expect(err).to.be.null();
done();
});
-1
View File
@@ -1,6 +1,5 @@
var jwt = require('../index');
var expect = require('chai').expect;
var atob = require('atob');
describe('decoding', function() {
+1 -2
View File
@@ -1,13 +1,12 @@
var jwt = require('../index');
var expect = require('chai').expect;
var assert = require('chai').assert;
describe('invalid expiration', function() {
it('should fail with string', function (done) {
var broken_token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOiIxMjMiLCJmb28iOiJhZGFzIn0.cDa81le-pnwJMcJi3o3PBwB7cTJMiXCkizIhxbXAKRg';
jwt.verify(broken_token, '123', function (err, decoded) {
jwt.verify(broken_token, '123', function (err) {
expect(err.name).to.equal('JsonWebTokenError');
done();
});
+5 -5
View File
@@ -4,35 +4,35 @@ var expect = require('chai').expect;
describe('issue 304 - verifying values other than strings', function() {
it('should fail with numbers', function (done) {
jwt.verify(123, 'foo', function (err, decoded) {
jwt.verify(123, 'foo', function (err) {
expect(err.name).to.equal('JsonWebTokenError');
done();
});
});
it('should fail with objects', function (done) {
jwt.verify({ foo: 'bar' }, 'biz', function (err, decoded) {
jwt.verify({ foo: 'bar' }, 'biz', function (err) {
expect(err.name).to.equal('JsonWebTokenError');
done();
});
});
it('should fail with arrays', function (done) {
jwt.verify(['foo'], 'bar', function (err, decoded) {
jwt.verify(['foo'], 'bar', function (err) {
expect(err.name).to.equal('JsonWebTokenError');
done();
});
});
it('should fail with functions', function (done) {
jwt.verify(function() {}, 'foo', function (err, decoded) {
jwt.verify(function() {}, 'foo', function (err) {
expect(err.name).to.equal('JsonWebTokenError');
done();
});
});
it('should fail with booleans', function (done) {
jwt.verify(true, 'foo', function (err, decoded) {
jwt.verify(true, 'foo', function (err) {
expect(err.name).to.equal('JsonWebTokenError');
done();
});
+1 -1
View File
@@ -102,7 +102,7 @@ describe('HS256', function() {
it('should return the "invalid token" error', function(done) {
var malformedToken = token + ' '; // corrupt the token by adding a space
jwt.verify(malformedToken, secret, { algorithm: 'HS256', ignoreExpiration: true }, function(err, decoded) {
jwt.verify(malformedToken, secret, { algorithm: 'HS256', ignoreExpiration: true }, function(err) {
assert.isNotNull(err);
assert.equal('JsonWebTokenError', err.name);
assert.equal('invalid token', err.message);
@@ -1,4 +1,3 @@
var fs = require('fs');
var jwt = require('../index');
var JsonWebTokenError = require('../lib/JsonWebTokenError');
var expect = require('chai').expect;
+2 -2
View File
@@ -308,7 +308,7 @@ describe('verify', function() {
var clockTimestamp = 1000000000;
it('should verify unexpired token relative to user-provided clockTimestamp', function (done) {
var token = jwt.sign({foo: 'bar', iat: clockTimestamp, exp: clockTimestamp + 1}, key);
jwt.verify(token, key, {clockTimestamp: clockTimestamp}, function (err, p) {
jwt.verify(token, key, {clockTimestamp: clockTimestamp}, function (err) {
assert.isNull(err);
done();
});
@@ -340,7 +340,7 @@ describe('verify', function() {
nbf: clockTimestamp + 1,
exp: clockTimestamp + 2
}, key);
jwt.verify(token, key, {clockTimestamp: clockTimestamp + 1}, function (err, p) {
jwt.verify(token, key, {clockTimestamp: clockTimestamp + 1}, function (err) {
assert.isNull(err);
done();
});