Skip to content

Commit c9fbf82

Browse files
committed
lint: use standard style
1 parent d943b44 commit c9fbf82

File tree

7 files changed

+73
-58
lines changed

7 files changed

+73
-58
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
coverage
2+
node_modules

.eslintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "standard"
3+
}

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ before_install:
1919
# Setup Node.js version-specific dependencies
2020
- "test $TRAVIS_NODE_VERSION != '0.6' || npm rm --save-dev istanbul"
2121
- "test $TRAVIS_NODE_VERSION != '0.8' || npm rm --save-dev istanbul"
22-
22+
- "test $(echo $TRAVIS_NODE_VERSION | cut -d. -f1) -ge 4 || npm rm --save-dev eslint eslint-config-standard eslint-plugin-promise eslint-plugin-standard"
2323
# Update Node.js modules
2424
- "test ! -d node_modules || npm prune"
2525
- "test ! -d node_modules || npm rebuild"

index.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module.exports = auth
2424
* @private
2525
*/
2626

27-
var credentialsRegExp = /^ *(?:[Bb][Aa][Ss][Ii][Cc]) +([A-Za-z0-9\-\._~\+\/]+=*) *$/
27+
var CREDENTIALS_REGEXP = /^ *(?:[Bb][Aa][Ss][Ii][Cc]) +([A-Za-z0-9._~+/-]+=*) *$/
2828

2929
/**
3030
* RegExp for basic auth user/pass
@@ -35,7 +35,7 @@ var credentialsRegExp = /^ *(?:[Bb][Aa][Ss][Ii][Cc]) +([A-Za-z0-9\-\._~\+\/]+=*)
3535
* @private
3636
*/
3737

38-
var userPassRegExp = /^([^:]*):(.*)$/
38+
var USER_PASS_REGEXP = /^([^:]*):(.*)$/
3939

4040
/**
4141
* Parse the Authorization header field of a request.
@@ -45,7 +45,7 @@ var userPassRegExp = /^([^:]*):(.*)$/
4545
* @public
4646
*/
4747

48-
function auth(req) {
48+
function auth (req) {
4949
if (!req) {
5050
throw new TypeError('argument req is required')
5151
}
@@ -58,14 +58,14 @@ function auth(req) {
5858
var header = getAuthorization(req.req || req)
5959

6060
// parse header
61-
var match = credentialsRegExp.exec(header || '')
61+
var match = CREDENTIALS_REGEXP.exec(header || '')
6262

6363
if (!match) {
6464
return
6565
}
6666

6767
// decode user pass
68-
var userPass = userPassRegExp.exec(decodeBase64(match[1]))
68+
var userPass = USER_PASS_REGEXP.exec(decodeBase64(match[1]))
6969

7070
if (!userPass) {
7171
return
@@ -80,7 +80,7 @@ function auth(req) {
8080
* @private
8181
*/
8282

83-
function decodeBase64(str) {
83+
function decodeBase64 (str) {
8484
return new Buffer(str, 'base64').toString()
8585
}
8686

@@ -89,7 +89,7 @@ function decodeBase64(str) {
8989
* @private
9090
*/
9191

92-
function getAuthorization(req) {
92+
function getAuthorization (req) {
9393
if (!req.headers || typeof req.headers !== 'object') {
9494
throw new TypeError('argument req is required to have headers property')
9595
}
@@ -102,7 +102,7 @@ function getAuthorization(req) {
102102
* @private
103103
*/
104104

105-
function Credentials(name, pass) {
105+
function Credentials (name, pass) {
106106
this.name = name
107107
this.pass = pass
108108
}

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
],
1212
"repository": "jshttp/basic-auth",
1313
"devDependencies": {
14+
"eslint": "3.10.2",
15+
"eslint-config-standard": "6.2.1",
16+
"eslint-plugin-promise": "3.4.0",
17+
"eslint-plugin-standard": "2.0.1",
1418
"istanbul": "0.4.5",
1519
"mocha": "1.21.5"
1620
},
@@ -23,6 +27,7 @@
2327
"node": ">= 0.6"
2428
},
2529
"scripts": {
30+
"lint": "eslint .",
2631
"test": "mocha --check-leaks --reporter spec --bail",
2732
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/",
2833
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/"

test/.eslintrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"env": {
3+
"mocha": true
4+
}
5+
}

test/basic-auth.js

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
var assert = require('assert');
2-
var auth = require('..');
1+
var assert = require('assert')
2+
var auth = require('..')
33

4-
function request(authorization) {
4+
function request (authorization) {
55
return {
66
headers: {
77
authorization: authorization
@@ -44,76 +44,76 @@ describe('auth(req)', function () {
4444
})
4545
})
4646

47-
describe('with no Authorization field', function(){
48-
it('should return null', function(){
49-
var req = request();
50-
assert(null == auth(req));
47+
describe('with no Authorization field', function () {
48+
it('should return null', function () {
49+
var req = request()
50+
assert(auth(req) == null)
5151
})
5252
})
5353

54-
describe('with malformed Authorization field', function(){
55-
it('should return null', function(){
56-
var req = request('Something');
57-
assert(null == auth(req));
54+
describe('with malformed Authorization field', function () {
55+
it('should return null', function () {
56+
var req = request('Something')
57+
assert(auth(req) == null)
5858
})
5959
})
6060

61-
describe('with malformed Authorization scheme', function(){
62-
it('should return null', function(){
63-
var req = request('basic_Zm9vOmJhcg==');
64-
assert(null == auth(req));
61+
describe('with malformed Authorization scheme', function () {
62+
it('should return null', function () {
63+
var req = request('basic_Zm9vOmJhcg==')
64+
assert(auth(req) == null)
6565
})
6666
})
6767

68-
describe('with malformed credentials', function(){
69-
it('should return null', function(){
70-
var req = request('basic Zm9vcgo=');
71-
assert(null == auth(req));
68+
describe('with malformed credentials', function () {
69+
it('should return null', function () {
70+
var req = request('basic Zm9vcgo=')
71+
assert(auth(req) == null)
7272
})
7373
})
7474

75-
describe('with valid credentials', function(){
76-
it('should return .name and .pass', function(){
77-
var req = request('basic Zm9vOmJhcg==');
78-
var creds = auth(req);
79-
assert.equal(creds.name, 'foo');
80-
assert.equal(creds.pass, 'bar');
75+
describe('with valid credentials', function () {
76+
it('should return .name and .pass', function () {
77+
var req = request('basic Zm9vOmJhcg==')
78+
var creds = auth(req)
79+
assert.equal(creds.name, 'foo')
80+
assert.equal(creds.pass, 'bar')
8181
})
8282
})
8383

84-
describe('with empty password', function(){
85-
it('should return .name and .pass', function(){
86-
var req = request('basic Zm9vOg==');
87-
var creds = auth(req);
88-
assert.equal(creds.name, 'foo');
89-
assert.equal(creds.pass, '');
84+
describe('with empty password', function () {
85+
it('should return .name and .pass', function () {
86+
var req = request('basic Zm9vOg==')
87+
var creds = auth(req)
88+
assert.equal(creds.name, 'foo')
89+
assert.equal(creds.pass, '')
9090
})
9191
})
9292

93-
describe('with empty userid', function(){
94-
it('should return .name and .pass', function(){
95-
var req = request('basic OnBhc3M=');
96-
var creds = auth(req);
97-
assert.equal(creds.name, '');
98-
assert.equal(creds.pass, 'pass');
93+
describe('with empty userid', function () {
94+
it('should return .name and .pass', function () {
95+
var req = request('basic OnBhc3M=')
96+
var creds = auth(req)
97+
assert.equal(creds.name, '')
98+
assert.equal(creds.pass, 'pass')
9999
})
100100
})
101101

102-
describe('with empty userid and pass', function(){
103-
it('should return .name and .pass', function(){
104-
var req = request('basic Og==');
105-
var creds = auth(req);
106-
assert.equal(creds.name, '');
107-
assert.equal(creds.pass, '');
102+
describe('with empty userid and pass', function () {
103+
it('should return .name and .pass', function () {
104+
var req = request('basic Og==')
105+
var creds = auth(req)
106+
assert.equal(creds.name, '')
107+
assert.equal(creds.pass, '')
108108
})
109109
})
110110

111-
describe('with colon in pass', function(){
112-
it('should return .name and .pass', function(){
113-
var req = request('basic Zm9vOnBhc3M6d29yZA==');
114-
var creds = auth(req);
115-
assert.equal(creds.name, 'foo');
116-
assert.equal(creds.pass, 'pass:word');
111+
describe('with colon in pass', function () {
112+
it('should return .name and .pass', function () {
113+
var req = request('basic Zm9vOnBhc3M6d29yZA==')
114+
var creds = auth(req)
115+
assert.equal(creds.name, 'foo')
116+
assert.equal(creds.pass, 'pass:word')
117117
})
118118
})
119119
})

0 commit comments

Comments
 (0)