Skip to content

Commit bc076db

Browse files
committed
- Linting (eslint-config-ash-nazg) (including overcoming an issue in the
`authenticate.js` middleware when switching to strict mode with errors upon setting a property on a boolean ) - npm: No need for full path within package.json scripts
1 parent 01948cb commit bc076db

38 files changed

+1186
-188
lines changed

.eslintrc.js

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
module.exports = {
22
env: {
33
node: true,
4+
browser: false
45
},
56
extends: [
6-
'airbnb-base',
7+
'ash-nazg/sauron-node',
8+
// Override ash-nazg's current preference for ESM
9+
'plugin:node/recommended-script'
710
],
11+
settings: {
12+
jsdoc: {
13+
// For `jsdoc/check-examples` in `ash-nazg`
14+
matchingFileName: 'dummy.md',
15+
rejectExampleCodeRegex: '^`',
16+
}
17+
},
818
overrides: [
919
{
1020
files: ['test/**'],
@@ -22,15 +32,84 @@ module.exports = {
2232
// 'jest/prefer-to-have-length': [2],
2333
// 'jest/valid-expect': [2],
2434
}
35+
},
36+
{
37+
files: ['**/*.md'],
38+
rules: {
39+
'eol-last': 'off',
40+
'no-console': 'off',
41+
'no-undef': 'off',
42+
'no-unused-vars': 'warn',
43+
'padded-blocks': 'off',
44+
'import/unambiguous': 'off',
45+
'import/no-unresolved': 'off',
46+
'node/no-missing-import': 'off',
47+
'node/no-missing-require': 'off',
48+
'func-names': 'off',
49+
'import/newline-after-import': 'off',
50+
strict: 'off',
51+
// Disable until eslint-plugin-jsdoc may fix: https://github.com/gajus/eslint-plugin-jsdoc/issues/211
52+
indent: 'off'
53+
}
2554
}
2655
],
56+
globals: {
57+
// By some ESLint bug, config overrides not working with globals
58+
require: 'readonly',
59+
module: 'readonly',
60+
exports: 'writable'
61+
},
2762
plugins: [
2863
// 'jest'
2964
],
3065
rules: {
3166
'comma-dangle': 0,
3267
'no-underscore-dangle': 0,
3368
'no-param-reassign': 0,
34-
'prefer-destructuring': 0,
69+
70+
// Disable until implementing promises and Node version supporting
71+
'promise/prefer-await-to-callbacks': 0,
72+
'promise/prefer-await-to-then': 0,
73+
74+
// Disable until ready to tackle
75+
'require-jsdoc': 0,
76+
77+
// Disable current preferences of ash-nazg
78+
'import/no-commonjs': 0,
79+
'node/exports-style': 0,
80+
81+
// add back different or stricter rules from airbnb
82+
'object-curly-spacing': ['error', 'always'],
83+
'func-names': 'warn',
84+
'max-len': ['error', 100, 2, {
85+
ignoreUrls: true,
86+
ignoreComments: false,
87+
ignoreRegExpLiterals: true,
88+
ignoreStrings: true,
89+
ignoreTemplateLiterals: true,
90+
}],
91+
'space-before-function-paren': ['error', {
92+
anonymous: 'always',
93+
named: 'never',
94+
asyncArrow: 'always'
95+
}],
96+
'no-multiple-empty-lines': ['error', { max: 2, maxEOF: 0 }],
97+
'arrow-parens': ['error', 'as-needed', {
98+
requireForBlockBody: true,
99+
}],
100+
'no-empty-function': ['error', {
101+
allow: [
102+
'arrowFunctions',
103+
'functions',
104+
'methods',
105+
]
106+
}],
107+
'no-unused-vars': ['error', { vars: 'all', args: 'after-used', ignoreRestSiblings: true }],
108+
'no-multi-assign': ['error'],
109+
'no-unused-expressions': ['error', {
110+
allowShortCircuit: false,
111+
allowTernary: false,
112+
allowTaggedTemplates: false,
113+
}]
35114
}
36115
};

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Contributing
22

3-
Pull Requests are welcome for any issues, if you have any questions please
3+
Pull Requests are welcome for any issues, if you have any questions please
44
[raise an issue](https://github.com/passport-next/passport/issues).
55

66
If you discover a security issue please create an issue stating you've discovered a security

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ application must be configured.
6262

6363
```javascript
6464
passport.use(new LocalStrategy(
65-
function(username, password, done) {
65+
function (username, password, done) {
6666
User.findOne({ username }, function (err, user) {
6767
if (err) { return done(err); }
6868
if (!user) { return done(null, false); }
@@ -88,11 +88,11 @@ as simple as serializing the user ID, and finding the user by ID when
8888
deserializing.
8989

9090
```javascript
91-
passport.serializeUser(function(user, done) {
91+
passport.serializeUser(function (user, done) {
9292
done(null, user.id);
9393
});
9494

95-
passport.deserializeUser(function(id, done) {
95+
passport.deserializeUser(function (id, done) {
9696
User.findById(id, function (err, user) {
9797
done(err, user);
9898
});
@@ -109,7 +109,7 @@ middleware must also be used.
109109

110110
```javascript
111111
const app = express();
112-
app.use(require('serve-static')(__dirname + '/../../public'));
112+
app.use(require('serve-static')(path.join(__dirname, '/../../public')));
113113
app.use(require('cookie-parser')());
114114
app.use(require('body-parser').urlencoded({ extended: true }));
115115
app.use(require('express-session')({ secret: 'keyboard cat', resave: true, saveUninitialized: true }));
@@ -125,7 +125,7 @@ middleware to authenticate requests.
125125
```javascript
126126
app.post('/login',
127127
passport.authenticate('local', { failureRedirect: '/login' }),
128-
function(req, res) {
128+
function (req, res) {
129129
res.redirect('/');
130130
});
131131
```
@@ -138,12 +138,12 @@ session.
138138

139139
```javascript
140140
app.post('/some/protected/route',
141-
function(req, res, next) {
142-
if(req.isAuthenticated()){
141+
function (req, res, next) {
142+
if (req.isAuthenticated()) {
143143
next();
144-
} else {
145-
next(new Error('Unauthorized'));
144+
return;
146145
}
146+
next(new Error('Unauthorized'));
147147
});
148148
```
149149

0 commit comments

Comments
 (0)