Skip to content

Commit 7dff468

Browse files
committed
- Breaking change: Require Node 8
- Refactoring: Use ES6 classes - Travis: Add Node 11 and 12 - Linting: Add eslint-config-ash-nazg (and remove jshint) to JS, Markdown, HTML - npm: Add `package-lock.json` - npm: Add recommended fields (contributors, homepage) - npm: Change deprecated `licenses` with `license` - npm: Add `lint` and `lintfix` scripts - npm: Update link from http to https - npm: Update chai, mocha
1 parent 6db4356 commit 7dff468

File tree

15 files changed

+3457
-89
lines changed

15 files changed

+3457
-89
lines changed

.eslintignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.git
2+
coverage/
3+
node_modules/
4+
var/

.eslintrc.js

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
module.exports = {
2+
env: {
3+
node: true,
4+
browser: false
5+
},
6+
extends: [
7+
'ash-nazg/sauron-node',
8+
// Override ash-nazg's current preference for ESM
9+
'plugin:node/recommended-script'
10+
],
11+
settings: {
12+
polyfills: [
13+
]
14+
},
15+
overrides: [
16+
{
17+
files: ['test/*'],
18+
env: {
19+
mocha: true
20+
},
21+
globals: {
22+
expect: 'readonly'
23+
},
24+
rules: {
25+
'func-names': 0
26+
}
27+
},
28+
{
29+
files: ['**/*.md'],
30+
rules: {
31+
'eol-last': 'off',
32+
'no-console': 'off',
33+
'no-undef': 'off',
34+
'no-unused-vars': 'warn',
35+
'padded-blocks': 'off',
36+
'import/unambiguous': 'off',
37+
'import/no-unresolved': 'off',
38+
'node/no-missing-import': 'off',
39+
'node/no-missing-require': 'off',
40+
'func-names': 'off',
41+
'import/newline-after-import': 'off',
42+
'no-unused-vars': ['error', {varsIgnorePattern: 'CustomStrategy'}],
43+
strict: 'off',
44+
// Disable until eslint-plugin-jsdoc may fix: https://github.com/gajus/eslint-plugin-jsdoc/issues/211
45+
indent: 'off'
46+
}
47+
}
48+
],
49+
globals: {
50+
// By some ESLint bug, config overrides not working with globals
51+
require: 'readonly',
52+
module: 'readonly',
53+
exports: 'writable'
54+
},
55+
rules: {
56+
'comma-dangle': 0,
57+
'no-underscore-dangle': 0,
58+
'no-param-reassign': 0,
59+
60+
// Disable current preferences of ash-nazg
61+
'import/no-commonjs': 0,
62+
'node/exports-style': 0,
63+
64+
// Browser only
65+
'compat/compat': 0,
66+
67+
// add back different or stricter rules from airbnb
68+
'object-curly-spacing': ['error', 'always'],
69+
'func-names': 'warn',
70+
'max-len': ['error', 100, 2, {
71+
ignoreUrls: true,
72+
ignoreComments: false,
73+
ignoreRegExpLiterals: true,
74+
ignoreStrings: true,
75+
ignoreTemplateLiterals: true,
76+
}],
77+
'space-before-function-paren': ['error', {
78+
anonymous: 'always',
79+
named: 'never',
80+
asyncArrow: 'always'
81+
}],
82+
'no-multiple-empty-lines': ['error', { max: 2, maxEOF: 0 }],
83+
'arrow-parens': ['error', 'as-needed', {
84+
requireForBlockBody: true,
85+
}],
86+
'no-empty-function': ['error', {
87+
allow: [
88+
'arrowFunctions',
89+
'functions',
90+
'methods',
91+
]
92+
}],
93+
'no-unused-vars': ['error', { vars: 'all', args: 'after-used', ignoreRestSiblings: true }],
94+
'no-multi-assign': ['error'],
95+
'no-unused-expressions': ['error', {
96+
allowShortCircuit: false,
97+
allowTernary: false,
98+
allowTaggedTemplates: false,
99+
}]
100+
}
101+
};

.jshintrc

Lines changed: 0 additions & 18 deletions
This file was deleted.

.npmignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,5 @@ npm-debug.log
1919
.git*
2020

2121
# Utilities
22-
.jshintrc
2322
.travis.yml
2423
.gitlab-ci.yml

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
language: "node_js"
22
node_js:
3-
- "6"
43
- "8"
54
- "10"
5+
- "11"
6+
- "12"
67

78
before_install:
89
- "npm install istanbul -g"

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@
44
* Updated travis to use node 6, 8 and 10 @rwky
55
* Updated dev deps @rwky
66
* Updated README.md and package.json for passport-next org
7-

README.md

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ API.
1111

1212
## Install
1313

14-
$ npm install passport-strategy
14+
```
15+
npm install passport-strategy
16+
```
1517

1618
## Usage
1719

@@ -25,14 +27,14 @@ middleware for authentication.
2527
Create a new `CustomStrategy` constructor which inherits from `Strategy`:
2628

2729
```javascript
28-
var util = require('util')
29-
, Strategy = require('@passport-next/passport-strategy');
30+
const Strategy = require('@passport-next/passport-strategy');
3031

31-
function CustomStrategy(...) {
32-
Strategy.call(this);
32+
class CustomStrategy extends Strategy {
33+
constructor(/* ... */) {
34+
super();
35+
doSomething();
36+
}
3337
}
34-
35-
util.inherits(CustomStrategy, Strategy);
3638
```
3739

3840
#### Implement Authentication
@@ -41,8 +43,12 @@ Implement `autheticate()`, performing the necessary operations required by the
4143
authentication scheme or protocol being implemented.
4244

4345
```javascript
44-
CustomStrategy.prototype.authenticate = function(req, options) {
45-
// TODO: authenticate request
46+
class CustomStrategy {
47+
// ...
48+
authenticate(req, options) {
49+
// TODO: authenticate request
50+
this._authenticateRequest(req, options);
51+
}
4652
}
4753
```
4854

@@ -75,8 +81,8 @@ details.
7581

7682
| Param | Type |
7783
| --- | --- |
78-
| user | Object |
79-
| info | Object |
84+
| user | Object |
85+
| info | Object |
8086

8187

8288
##### strategy.fail(challenge, status)
@@ -90,8 +96,8 @@ Strategies should call this function to fail an authentication attempt.
9096

9197
| Param | Type |
9298
| --- | --- |
93-
| challenge | String |
94-
| status | Number |
99+
| challenge | String |
100+
| status | Number |
95101

96102

97103

@@ -106,8 +112,8 @@ user agent) to a third-party website for authentication.
106112

107113
| Param | Type |
108114
| --- | --- |
109-
| url | String |
110-
| status | Number |
115+
| url | String |
116+
| status | Number |
111117

112118

113119
##### strategy.pass()
@@ -132,7 +138,7 @@ user directory is not available.
132138

133139
| Param | Type |
134140
| --- | --- |
135-
| err | Error |
141+
| err | Error |
136142

137143

138144

@@ -144,4 +150,3 @@ user directory is not available.
144150

145151
$ npm install
146152
$ npm test
147-

lib/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
'use strict';
12
/**
23
* Module dependencies.
34
*/
4-
var Strategy = require('./strategy');
5+
const Strategy = require('./strategy');
56

67

78
/**
89
* Expose `Strategy` directly from package.
910
*/
11+
// eslint-disable-next-line no-multi-assign
1012
exports = module.exports = Strategy;
1113

1214
/**

lib/strategy.js

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
1+
'use strict';
12
/**
23
* Creates an instance of `Strategy`.
34
*
4-
* @constructor
5-
* @api public
5+
* @public
66
*/
7-
function Strategy() {
7+
class Strategy {
8+
/**
9+
* Authenticate request.
10+
*
11+
* This function must be overridden by subclasses. In abstract form, it always
12+
* throws an exception.
13+
*
14+
* @param {Object} req The request to authenticate.
15+
* @param {Object} [options] Strategy-specific options.
16+
* @public
17+
* @returns {void}
18+
*/
19+
authenticate(req, options) { // eslint-disable-line no-unused-vars, class-methods-use-this
20+
throw new Error('Strategy#authenticate must be overridden by subclass');
21+
}
822
}
923

10-
/**
11-
* Authenticate request.
12-
*
13-
* This function must be overridden by subclasses. In abstract form, it always
14-
* throws an exception.
15-
*
16-
* @param {Object} req The request to authenticate.
17-
* @param {Object} [options] Strategy-specific options.
18-
* @api public
19-
*/
20-
Strategy.prototype.authenticate = function(req, options) {
21-
throw new Error('Strategy#authenticate must be overridden by subclass');
22-
};
23-
24-
2524
/**
2625
* Expose `Strategy`.
2726
*/

0 commit comments

Comments
 (0)