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

Refactoring/Linting #19

Merged
merged 6 commits into from
Jun 25, 2019
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
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.git
coverage/
node_modules/
node_modules/
var/
111 changes: 98 additions & 13 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,109 @@
module.exports = {
env: {
// jest: true,
mocha: true,
node: true,
browser: false
},
extends: [
'airbnb-base',
'ash-nazg/sauron-node',
// Override ash-nazg's current preference for ESM
'plugin:node/recommended-script'
],
overrides: [
{
files: ['test/**'],
env: {
// jest: true,
mocha: true
},
globals: {
expect: 'readonly'
},
rules: {
'jsdoc/require-jsdoc': 'off'
// 'jest/no-disabled-tests': [2],
// 'jest/no-focused-tests': [2],
// 'jest/no-identical-title': [2],
// '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,
// 'jest/no-disabled-tests': [2],
// 'jest/no-focused-tests': [2],
// 'jest/no-identical-title': [2],
// 'jest/prefer-to-have-length': [2],
// 'jest/valid-expect': [2],
'comma-dangle': 0,
'no-underscore-dangle': 0,
'no-param-reassign': 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,
}]
}
};
};
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
docs/
reports/
var/

# Mac OS X
.DS_Store
Expand Down
18 changes: 0 additions & 18 deletions .jshintrc

This file was deleted.

2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ docs/
examples/
reports/
test/
var/

.github/
.jshintrc
.travis.yml
.gitlab-ci.yml
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ view-docs:
open ./docs/index.html

view-cov:
open ./reports/coverage/lcov-report/index.html
open ./var/cov/index.html

clean: clean-docs clean-cov
-rm -r $(REPORTSDIR)
Expand Down
52 changes: 26 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Passport Next aims to:
* Follow [Semantic Versioning](https://semver.org/)
* Keep an up to date CHANGELOG.md

**Passport Next does not aim to be backwards compatible with the upstream repositories.
**Passport Next does not aim to be backwards compatible with the upstream repositories.
The changes required to keep up to date and functioning prohibit that so if you're migrating
from the upstream modules please test your code thouroughly!**

Expand All @@ -62,8 +62,8 @@ application must be configured.

```javascript
passport.use(new LocalStrategy(
function(username, password, done) {
User.findOne({ username: username }, function (err, user) {
function (username, password, done) {
User.findOne({ username }, function (err, user) {
if (err) { return done(err); }
if (!user) { return done(null, false); }
if (!user.verifyPassword(password)) { 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 @@ -108,8 +108,8 @@ persistent login sessions (recommended, but not required), `passport.session()`
middleware must also be used.

```javascript
var app = express();
app.use(require('serve-static')(__dirname + '/../../public'));
const app = express();
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 @@ -123,31 +123,31 @@ Passport provides an `authenticate()` function, which is used as route
middleware to authenticate requests.

```javascript
app.post('/login',
app.post('/login',
passport.authenticate('local', { failureRedirect: '/login' }),
function(req, res) {
function (req, res) {
res.redirect('/');
});
```

#### Protect Routes When Using Sessions

Passport provides an `isAuthenticated()` function on the request object, which
is used to determine if the user has been authenticated and stored in the
Passport provides an `isAuthenticated()` function on the request object, which
is used to determine if the user has been authenticated and stored in the
session.

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

For a more complete solution to handling unauthenticated users, see
For a more complete solution to handling unauthenticated users, see
[connect-ensure-login](https://github.com/jaredhanson/connect-ensure-login), a
middleware to ensure login sessions.

Expand All @@ -162,16 +162,16 @@ There is a **Strategy Search** at [passportjs.org](http://passportjs.org)

The following table lists commonly used strategies:

|Strategy | Protocol |Developer |
|Strategy | Protocol |Developer |
|---------------------------------------------------------------|--------------------------|------------------------------------------------|
|[Local](https://github.com/jaredhanson/passport-local) | HTML form |[Jared Hanson](https://github.com/jaredhanson) |
|[OpenID](https://github.com/jaredhanson/passport-openid) | OpenID |[Jared Hanson](https://github.com/jaredhanson) |
|[BrowserID](https://github.com/jaredhanson/passport-browserid) | BrowserID |[Jared Hanson](https://github.com/jaredhanson) |
|[Facebook](https://github.com/jaredhanson/passport-facebook) | OAuth 2.0 |[Jared Hanson](https://github.com/jaredhanson) |
|[Google](https://github.com/jaredhanson/passport-google) | OpenID |[Jared Hanson](https://github.com/jaredhanson) |
|[Google](https://github.com/jaredhanson/passport-google-oauth) | OAuth / OAuth 2.0 |[Jared Hanson](https://github.com/jaredhanson) |
|[Twitter](https://github.com/jaredhanson/passport-twitter) | OAuth |[Jared Hanson](https://github.com/jaredhanson) |
|[Azure Active Directory](https://github.com/AzureAD/passport-azure-ad) | OAuth 2.0 / OpenID / SAML |[Azure](https://github.com/azuread) |
|[Local](https://github.com/jaredhanson/passport-local) | HTML form |[Jared Hanson](https://github.com/jaredhanson)|
|[OpenID](https://github.com/jaredhanson/passport-openid) | OpenID |[Jared Hanson](https://github.com/jaredhanson)|
|[BrowserID](https://github.com/jaredhanson/passport-browserid) | BrowserID |[Jared Hanson](https://github.com/jaredhanson)|
|[Facebook](https://github.com/jaredhanson/passport-facebook) | OAuth 2.0 |[Jared Hanson](https://github.com/jaredhanson)|
|[Google](https://github.com/jaredhanson/passport-google) | OpenID |[Jared Hanson](https://github.com/jaredhanson)|
|[Google](https://github.com/jaredhanson/passport-google-oauth) | OAuth / OAuth 2.0 |[Jared Hanson](https://github.com/jaredhanson)|
|[Twitter](https://github.com/jaredhanson/passport-twitter) | OAuth |[Jared Hanson](https://github.com/jaredhanson)|
|[Azure Active Directory](https://github.com/AzureAD/passport-azure-ad)|OAuth 2.0 / OpenID / SAML|[Azure](https://github.com/azuread) |

## Examples

Expand Down
Loading