Skip to content

Commit

Permalink
- Linting (eslint-config-ash-nazg) (including overcoming an issue in the
Browse files Browse the repository at this point in the history
    `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
  • Loading branch information
brettz9 committed May 9, 2019
1 parent 1a65165 commit 8dbc1b0
Show file tree
Hide file tree
Showing 38 changed files with 1,177 additions and 182 deletions.
83 changes: 81 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
module.exports = {
env: {
node: true,
browser: false
},
extends: [
'airbnb-base',
'ash-nazg/sauron-node',
// Override ash-nazg's current preference for ESM
'plugin:node/recommended-script'
],
settings: {
jsdoc: {
// For `jsdoc/check-examples` in `ash-nazg`
matchingFileName: 'dummy.md',
rejectExampleCodeRegex: '^`',
}
},
overrides: [
{
files: ['test/**'],
Expand All @@ -22,15 +32,84 @@ module.exports = {
// 'jest/prefer-to-have-length': [2],
// 'jest/valid-expect': [2],
}
},
{
files: ['**/*.md'],
rules: {
'eol-last': 'off',
'no-console': 'off',
'no-undef': 'off',
'no-unused-vars': 'warn',
'padded-blocks': 'off',
'import/unambiguous': 'off',
'import/no-unresolved': 'off',
'node/no-missing-import': 'off',
'node/no-missing-require': 'off',
'func-names': 'off',
'import/newline-after-import': 'off',
strict: 'off',
// Disable until eslint-plugin-jsdoc may fix: https://github.com/gajus/eslint-plugin-jsdoc/issues/211
indent: 'off'
}
}
],
globals: {
// By some ESLint bug, config overrides not working with globals
require: 'readonly',
module: 'readonly',
exports: 'writable'
},
plugins: [
// 'jest'
],
rules: {
'comma-dangle': 0,
'no-underscore-dangle': 0,
'no-param-reassign': 0,
'prefer-destructuring': 0,

// Disable until implementing promises and Node version supporting
'promise/prefer-await-to-callbacks': 0,
'promise/prefer-await-to-then': 0,

// Disable until ready to tackle
'require-jsdoc': 0,

// Disable current preferences of ash-nazg
'import/no-commonjs': 0,
'node/exports-style': 0,

// add back different or stricter rules from airbnb
'object-curly-spacing': ['error', 'always'],
'func-names': 'warn',
'max-len': ['error', 100, 2, {
ignoreUrls: true,
ignoreComments: false,
ignoreRegExpLiterals: true,
ignoreStrings: true,
ignoreTemplateLiterals: true,
}],
'space-before-function-paren': ['error', {
anonymous: 'always',
named: 'never',
asyncArrow: 'always'
}],
'no-multiple-empty-lines': ['error', { max: 2, maxEOF: 0 }],
'arrow-parens': ['error', 'as-needed', {
requireForBlockBody: true,
}],
'no-empty-function': ['error', {
allow: [
'arrowFunctions',
'functions',
'methods',
]
}],
'no-unused-vars': ['error', { vars: 'all', args: 'after-used', ignoreRestSiblings: true }],
'no-multi-assign': ['error'],
'no-unused-expressions': ['error', {
allowShortCircuit: false,
allowTernary: false,
allowTaggedTemplates: false,
}]
}
};
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Contributing

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

If you discover a security issue please create an issue stating you've discovered a security
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ application must be configured.

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

```javascript
passport.serializeUser(function(user, done) {
passport.serializeUser(function (user, done) {
done(null, user.id);
});

passport.deserializeUser(function(id, done) {
passport.deserializeUser(function (id, done) {
User.findById(id, function (err, user) {
done(err, user);
});
Expand All @@ -109,7 +109,7 @@ middleware must also be used.

```javascript
const app = express();
app.use(require('serve-static')(__dirname + '/../../public'));
app.use(require('serve-static')(path.join(__dirname, '/../../public')));
app.use(require('cookie-parser')());
app.use(require('body-parser').urlencoded({ extended: true }));
app.use(require('express-session')({ secret: 'keyboard cat', resave: true, saveUninitialized: true }));
Expand All @@ -125,7 +125,7 @@ middleware to authenticate requests.
```javascript
app.post('/login',
passport.authenticate('local', { failureRedirect: '/login' }),
function(req, res) {
function (req, res) {
res.redirect('/');
});
```
Expand All @@ -138,12 +138,12 @@ session.

```javascript
app.post('/some/protected/route',
function(req, res, next) {
if(req.isAuthenticated()){
function (req, res, next) {
if (req.isAuthenticated()) {
next();
} else {
next(new Error('Unauthorized'));
return;
}
next(new Error('Unauthorized'));
});
```

Expand Down
Loading

0 comments on commit 8dbc1b0

Please sign in to comment.