Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete ESLint conversion and cleanup #490

Merged
merged 4 commits into from
Jun 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.nyc_output/
coverage/
8 changes: 0 additions & 8 deletions .eslintrc

This file was deleted.

23 changes: 23 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this could be ignored in tests, where you usually don't use all the variables from a function. For now it is fine since you fixed them. Let's keep that in mind now that you will play a lot with tests.

}
}
22 changes: 0 additions & 22 deletions .jshintrc

This file was deleted.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions test/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"env": {
"mocha": true
}
}
4 changes: 2 additions & 2 deletions test/async_sign.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
1 change: 0 additions & 1 deletion test/decoding.tests.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
var jwt = require('../index');
var expect = require('chai').expect;
var atob = require('atob');

describe('decoding', function() {

Expand Down
3 changes: 1 addition & 2 deletions test/invalid_exp.tests.js
Original file line number Diff line number Diff line change
@@ -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();
});
Expand Down
10 changes: 5 additions & 5 deletions test/issue_304.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
2 changes: 1 addition & 1 deletion test/jwt.hs.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion test/undefined_secretOrPublickey.tests.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
var fs = require('fs');
var jwt = require('../index');
var JsonWebTokenError = require('../lib/JsonWebTokenError');
var expect = require('chai').expect;
Expand Down
4 changes: 2 additions & 2 deletions test/verify.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down Expand Up @@ -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();
});
Expand Down