diff --git a/api-server/common/models/User-Identity.js b/api-server/common/models/User-Identity.js index d271b78da4..bff8f3e6a5 100644 --- a/api-server/common/models/User-Identity.js +++ b/api-server/common/models/User-Identity.js @@ -115,10 +115,10 @@ export default function(UserIdent) { return identity ? Observable.of(identity.user()) : User.findOne$({ where: { email } }).flatMap(user => { - return user - ? Observable.of(user) - : User.create$({ email }).toPromise(); - }); + return user + ? Observable.of(user) + : User.create$({ email }).toPromise(); + }); }) .flatMap(user => { const createToken = observeQuery(AccessToken, 'create', { diff --git a/api-server/common/models/block.js b/api-server/common/models/block.js index fb8498cd53..888082e7c1 100644 --- a/api-server/common/models/block.js +++ b/api-server/common/models/block.js @@ -2,11 +2,8 @@ import { Observable } from 'rx'; export default function(Block) { Block.on('dataSourceAttached', () => { - Block.findOne$ = - Observable.fromNodeCallback(Block.findOne, Block); - Block.findById$ = - Observable.fromNodeCallback(Block.findById, Block); - Block.find$ = - Observable.fromNodeCallback(Block.find, Block); + Block.findOne$ = Observable.fromNodeCallback(Block.findOne, Block); + Block.findById$ = Observable.fromNodeCallback(Block.findById, Block); + Block.find$ = Observable.fromNodeCallback(Block.find, Block); }); } diff --git a/api-server/common/utils/flash.js b/api-server/common/utils/flash.js index b965b3680e..b1ece41452 100644 --- a/api-server/common/utils/flash.js +++ b/api-server/common/utils/flash.js @@ -1,10 +1,8 @@ import _ from 'lodash'; -export const alertTypes = _.keyBy([ - 'success', - 'info', - 'warning', - 'danger' -], _.identity); +export const alertTypes = _.keyBy( + ['success', 'info', 'warning', 'danger'], + _.identity +); export const normalizeAlertType = alertType => alertTypes[alertType] || 'info'; diff --git a/api-server/common/utils/map.js b/api-server/common/utils/map.js index 9ce2e1b8ff..92eda2ea01 100644 --- a/api-server/common/utils/map.js +++ b/api-server/common/utils/map.js @@ -1,15 +1,9 @@ import emptyProtector from './empty-protector'; -export function checkMapData( - { - entities: { - challenge, - block, - superBlock - }, - result: { superBlocks } - } -) { +export function checkMapData({ + entities: { challenge, block, superBlock }, + result: { superBlocks } +}) { if ( !challenge || !block || @@ -17,9 +11,7 @@ export function checkMapData( !superBlocks || !superBlocks.length ) { - throw new Error( - 'entities not found, db may not be properly seeded' - ); + throw new Error('entities not found, db may not be properly seeded'); } } // getFirstChallenge( @@ -33,11 +25,8 @@ export function getFirstChallenge({ result: { superBlocks } }) { return challenge[ - emptyProtector(block[ - emptyProtector(superBlock[ - superBlocks[0] - ]).blocks[0] - ]).challenges[0] + emptyProtector(block[emptyProtector(superBlock[superBlocks[0]]).blocks[0]]) + .challenges[0] ]; } @@ -52,12 +41,10 @@ export function getFirstChallenge({ // }; export function createNameIdMap({ challenge }) { return { - challengeIdToName: Object.keys(challenge) - .reduce((map, challengeName) => { - map[challenge[challengeName].id] = - challenge[challengeName].dashedName; - return map; - }, {}) + challengeIdToName: Object.keys(challenge).reduce((map, challengeName) => { + map[challenge[challengeName].id] = challenge[challengeName].dashedName; + return map; + }, {}) }; } // addNameIdMap( diff --git a/api-server/common/utils/polyvinyl.js b/api-server/common/utils/polyvinyl.js index ed3faf53aa..790f8bd508 100644 --- a/api-server/common/utils/polyvinyl.js +++ b/api-server/common/utils/polyvinyl.js @@ -3,14 +3,11 @@ import invariant from 'invariant'; import { Observable } from 'rx'; import castToObservable from '../../server/utils/cast-to-observable'; - // createFileStream( // files: [...PolyVinyl] // ) => Observable[...Observable[...PolyVinyl]] export function createFileStream(files = []) { - return Observable.of( - Observable.from(files) - ); + return Observable.of(Observable.from(files)); } // Observable::pipe( @@ -20,8 +17,8 @@ export function createFileStream(files = []) { // ) => Observable[...Observable[...PolyVinyl]] export function pipe(project) { const source = this; - return source.map( - files => files.flatMap(file => castToObservable(project(file))) + return source.map(files => + files.flatMap(file => castToObservable(project(file))) ); } @@ -44,24 +41,10 @@ export function pipe(project) { // contents: String, // history?: [...String], // }) => PolyVinyl, throws -export function createPoly({ - name, - ext, - contents, - history, - ...rest -} = {}) { - invariant( - typeof name === 'string', - 'name must be a string but got %s', - name - ); +export function createPoly({ name, ext, contents, history, ...rest } = {}) { + invariant(typeof name === 'string', 'name must be a string but got %s', name); - invariant( - typeof ext === 'string', - 'ext must be a string, but was %s', - ext - ); + invariant(typeof ext === 'string', 'ext must be a string, but was %s', ext); invariant( typeof contents === 'string', @@ -71,7 +54,7 @@ export function createPoly({ return { ...rest, - history: Array.isArray(history) ? history : [ name + ext ], + history: Array.isArray(history) ? history : [name + ext], name, ext, path: name + '.' + ext, @@ -83,11 +66,13 @@ export function createPoly({ // isPoly(poly: Any) => Boolean export function isPoly(poly) { - return poly && + return ( + poly && typeof poly.contents === 'string' && typeof poly.name === 'string' && typeof poly.ext === 'string' && - Array.isArray(poly.history); + Array.isArray(poly.history) + ); } // checkPoly(poly: Any) => Void, throws @@ -125,7 +110,7 @@ export function setExt(ext, poly) { path: poly.name + '.' + ext, key: poly.name + ext }; - newPoly.history = [ ...poly.history, newPoly.path ]; + newPoly.history = [...poly.history, newPoly.path]; return newPoly; } @@ -138,7 +123,7 @@ export function setName(name, poly) { path: name + '.' + poly.ext, key: name + poly.ext }; - newPoly.history = [ ...poly.history, newPoly.path ]; + newPoly.history = [...poly.history, newPoly.path]; return newPoly; } @@ -177,10 +162,12 @@ export function appendToTail(tail, poly) { // compileHeadTail(padding: String, poly: PolyVinyl) => PolyVinyl export function compileHeadTail(padding = '', poly) { - return clearHeadTail(transformContents( - () => [ poly.head, poly.contents, poly.tail ].join(padding), - poly - )); + return clearHeadTail( + transformContents( + () => [poly.head, poly.contents, poly.tail].join(padding), + poly + ) + ); } // transformContents( @@ -192,10 +179,7 @@ export function compileHeadTail(padding = '', poly) { // already contains a source, this version will continue as // the source property export function transformContents(wrap, poly) { - const newPoly = setContent( - wrap(poly.contents), - poly - ); + const newPoly = setContent(wrap(poly.contents), poly); // if no source exist, set the original contents as source newPoly.source = poly.source || poly.contents; return newPoly; @@ -207,10 +191,7 @@ export function transformContents(wrap, poly) { // ) => PolyVinyl export function transformHeadTailAndContents(wrap, poly) { return { - ...transformContents( - wrap, - poly - ), + ...transformContents(wrap, poly), head: wrap(poly.head), tail: wrap(poly.tail) }; diff --git a/api-server/common/utils/themes.js b/api-server/common/utils/themes.js index 0f96929894..97947e6c36 100644 --- a/api-server/common/utils/themes.js +++ b/api-server/common/utils/themes.js @@ -3,8 +3,7 @@ export const themes = { default: 'default' }; -export const invertTheme = currentTheme => ( - !currentTheme || currentTheme === themes.default ? - themes.night : - themes.default -); +export const invertTheme = currentTheme => + !currentTheme || currentTheme === themes.default + ? themes.night + : themes.default; diff --git a/api-server/jest.config.js b/api-server/jest.config.js index b1cbc422f5..24956b05cf 100644 --- a/api-server/jest.config.js +++ b/api-server/jest.config.js @@ -16,7 +16,5 @@ module.exports = { transform: { '^.+\\.js$': 'babel-jest' }, - transformIgnorePatterns: [ - 'node_modules/(?!(gatsby)/)' - ] + transformIgnorePatterns: ['node_modules/(?!(gatsby)/)'] }; diff --git a/api-server/server/boot/certificate.js b/api-server/server/boot/certificate.js index df9f84000f..a8f01ae7c8 100644 --- a/api-server/server/boot/certificate.js +++ b/api-server/server/boot/certificate.js @@ -350,9 +350,8 @@ function createShowCert(app) { messages: [ { type: 'info', - message: `We could not find a user with the username "${ - username - }"` + message: + 'We could not find a user with the username "' + username + '"' } ] }); diff --git a/api-server/server/boot/challenge.js b/api-server/server/boot/challenge.js index 8f18aa0878..7eb5f61cf4 100644 --- a/api-server/server/boot/challenge.js +++ b/api-server/server/boot/challenge.js @@ -321,7 +321,7 @@ export default async function bootChallenge(app, done) { ) { req.flash( 'danger', - 'You haven\'t supplied the necessary URLs for us to inspect your work.' + "You haven't supplied the necessary URLs for us to inspect your work." ); return res.sendStatus(403); } diff --git a/api-server/server/boot/commit.js b/api-server/server/boot/commit.js index 8eb32c16e4..782b474bb8 100644 --- a/api-server/server/boot/commit.js +++ b/api-server/server/boot/commit.js @@ -6,23 +6,13 @@ import dedent from 'dedent'; import { homeLocation } from '../../../config/env'; import nonprofits from '../utils/commit.json'; -import { - commitGoals, - completeCommitment$ -} from '../utils/commit'; +import { commitGoals, completeCommitment$ } from '../utils/commit'; -import { - unDasherize -} from '../utils'; +import { unDasherize } from '../utils'; -import { - observeQuery, - saveInstance -} from '../utils/rx'; +import { observeQuery, saveInstance } from '../utils/rx'; -import { - ifNoUserRedirectTo -} from '../utils/middleware'; +import { ifNoUserRedirectTo } from '../utils/middleware'; const sendNonUserToSignIn = ifNoUserRedirectTo( `${homeLocation}/signin`, @@ -41,12 +31,12 @@ const debug = debugFactory('fcc:commit'); function findNonprofit(name) { let nonprofit; if (name) { - nonprofit = _.find(nonprofits, (nonprofit) => { + nonprofit = _.find(nonprofits, nonprofit => { return name === nonprofit.name; }); } - nonprofit = nonprofit || nonprofits[ _.random(0, nonprofits.length - 1) ]; + nonprofit = nonprofit || nonprofits[_.random(0, nonprofits.length - 1)]; return nonprofit; } @@ -55,33 +45,15 @@ export default function commit(app) { const api = app.loopback.Router(); const { Pledge } = app.models; - router.get( - '/commit', - commitToNonprofit - ); + router.get('/commit', commitToNonprofit); - router.get( - '/commit/pledge', - sendNonUserToSignIn, - pledge - ); + router.get('/commit/pledge', sendNonUserToSignIn, pledge); - router.get( - '/commit/directory', - renderDirectory - ); + router.get('/commit/directory', renderDirectory); - api.post( - '/commit/stop-commitment', - sendNonUserToCommit, - stopCommit - ); + api.post('/commit/stop-commitment', sendNonUserToCommit, stopCommit); - api.post( - '/commit/complete-goal', - sendNonUserToCommit, - completeCommitment - ); + api.post('/commit/complete-goal', sendNonUserToCommit, completeCommitment); app.use(api); app.use(router); @@ -101,33 +73,26 @@ export default function commit(app) { } return Observable.just(); }) - .subscribe( - pledge => { - if (pledge) { - debug('found previous pledge'); - req.flash( - 'info', - dedent` + .subscribe(pledge => { + if (pledge) { + debug('found previous pledge'); + req.flash( + 'info', + dedent` Looks like you already have a pledge to ${pledge.displayName}. Clicking "Commit" here will replace your old commitment. If you do change your commitment, please remember to cancel your previous recurring donation directly with ${pledge.displayName}. ` - ); - } - res.render( - 'commit/', - { - title: 'Commit to a nonprofit. Commit to your goal.', - pledge, - ...commitGoals, - ...nonprofit - } ); - }, - next - ); - + } + res.render('commit/', { + title: 'Commit to a nonprofit. Commit to your goal.', + pledge, + ...commitGoals, + ...nonprofit + }); + }, next); } function pledge(req, res, next) { @@ -143,14 +108,12 @@ export default function commit(app) { observeQuery(user, 'pledge') .flatMap(oldPledge => { // create new pledge for user - const pledge = Pledge( - { - amount, - goal, - userId: user.id, - ...nonprofit - } - ); + const pledge = Pledge({ + amount, + goal, + userId: user.id, + ...nonprofit + }); if (oldPledge) { debug('user already has pledge, creating a new one'); @@ -159,28 +122,24 @@ export default function commit(app) { oldPledge.formerUser = user.id; oldPledge.endDate = new Date(); oldPledge.isOrphaned = true; - return saveInstance(oldPledge) - .flatMap(() => { - return saveInstance(pledge); - }); + return saveInstance(oldPledge).flatMap(() => { + return saveInstance(pledge); + }); } return saveInstance(pledge); }) - .subscribe( - ({ displayName, goal, amount }) => { - req.flash( - 'success', - dedent` + .subscribe(({ displayName, goal, amount }) => { + req.flash( + 'success', + dedent` Congratulations, you have committed to giving ${displayName} $${amount} each month until you have completed your ${goal}. Please remember to cancel your pledge directly with ${displayName} once you finish. ` - ); - res.redirect('/' + user.username); - }, - next - ); + ); + res.redirect('/' + user.username); + }, next); } function renderDirectory(req, res) { @@ -193,16 +152,12 @@ export default function commit(app) { function completeCommitment(req, res, next) { const { user } = req; - return completeCommitment$(user) - .subscribe( - msgOrPledge => { - if (typeof msgOrPledge === 'string') { - return res.send(msgOrPledge); - } - return res.send(true); - }, - next - ); + return completeCommitment$(user).subscribe(msgOrPledge => { + if (typeof msgOrPledge === 'string') { + return res.send(msgOrPledge); + } + return res.send(true); + }, next); } function stopCommit(req, res, next) { @@ -220,23 +175,20 @@ export default function commit(app) { pledge.dateEnded = new Date(); return saveInstance(pledge); }) - .subscribe( - pledge => { - let msg = dedent` + .subscribe(pledge => { + let msg = dedent` You have successfully stopped your pledge. Please remember to cancel your recurring donation directly with the nonprofit if you haven't already done so. `; - if (!pledge) { - msg = dedent` + if (!pledge) { + msg = dedent` It doesn't look like you had an active pledge, so there's no pledge to stop. `; - } - req.flash('info', msg); - return res.redirect(`/${user.username}`); - }, - next - ); + } + req.flash('info', msg); + return res.redirect(`/${user.username}`); + }, next); } } diff --git a/api-server/server/boot/donate.js b/api-server/server/boot/donate.js index 1feec901f6..0fb604ac66 100644 --- a/api-server/server/boot/donate.js +++ b/api-server/server/boot/donate.js @@ -6,7 +6,6 @@ import keys from '../../../config/secrets'; const log = debug('fcc:boot:donate'); export default function donateBoot(app, done) { - let stripe = false; const { User } = app.models; const api = app.loopback.Router(); @@ -25,7 +24,8 @@ export default function donateBoot(app, done) { currency: 'usd', id: `monthly-donation-${current}` } - }), {} + }), + {} ); function connectToStripe() { @@ -70,23 +70,26 @@ export default function donateBoot(app, done) { return res.status(400).send({ error: 'Amount Required' }); } - const { amount, token: {email, id} } = body; + const { + amount, + token: { email, id } + } = body; - const fccUser = user ? - Promise.resolve(user) : - new Promise((resolve, reject) => - User.findOrCreate( - { where: { email }}, - { email }, - (err, instance, isNew) => { - log('is new user instance: ', isNew); - if (err) { - return reject(err); - } - return resolve(instance); - } - ) - ); + const fccUser = user + ? Promise.resolve(user) + : new Promise((resolve, reject) => + User.findOrCreate( + { where: { email } }, + { email }, + (err, instance, isNew) => { + log('is new user instance: ', isNew); + if (err) { + return reject(err); + } + return resolve(instance); + } + ) + ); let donatingUser = {}; let donation = { @@ -96,14 +99,13 @@ export default function donateBoot(app, done) { startDate: new Date(Date.now()).toISOString() }; - return fccUser.then( - user => { + return fccUser + .then(user => { donatingUser = user; - return stripe.customers - .create({ - email, - card: id - }); + return stripe.customers.create({ + email, + card: id + }); }) .then(customer => { donation.customerId = customer.id; @@ -121,7 +123,9 @@ export default function donateBoot(app, done) { return res.send(subscription); }) .then(() => { - donatingUser.createDonation(donation).toPromise() + donatingUser + .createDonation(donation) + .toPromise() .catch(err => { throw new Error(err); }); diff --git a/api-server/server/boot/explorer.js b/api-server/server/boot/explorer.js index d5abb9e8c5..18b35142be 100644 --- a/api-server/server/boot/explorer.js +++ b/api-server/server/boot/explorer.js @@ -15,7 +15,7 @@ module.exports = function mountLoopBackExplorer(app) { app.once('started', function() { log( 'Run `npm install loopback-component-explorer` to enable ' + - 'the LoopBack explorer' + 'the LoopBack explorer' ); }); return; diff --git a/api-server/server/boot/news.js b/api-server/server/boot/news.js index c720929a66..a8c22e60f5 100644 --- a/api-server/server/boot/news.js +++ b/api-server/server/boot/news.js @@ -32,9 +32,7 @@ function createShortLinkHandler(app) { if (!article) { return res.redirect('/news'); } - const { - slugPart - } = article; + const { slugPart } = article; const slug = `/news/${slugPart}`; return res.redirect(slug); } diff --git a/api-server/server/boot/randomAPIs.js b/api-server/server/boot/randomAPIs.js index 5d00439b32..4990728ff5 100644 --- a/api-server/server/boot/randomAPIs.js +++ b/api-server/server/boot/randomAPIs.js @@ -88,7 +88,7 @@ module.exports = function(app) { .then(() => { req.flash( 'success', - 'We\'ve successfully updated your email preferences.' + "We've successfully updated your email preferences." ); return res.redirectWithFlash( `${homeLocation}/unsubscribed/${unsubscribeId}` @@ -144,7 +144,7 @@ module.exports = function(app) { .then(() => { req.flash( 'success', - 'We\'ve successfully updated your email preferences. Thank you ' + + "We've successfully updated your email preferences. Thank you " + 'for resubscribing.' ); return res.redirectWithFlash(homeLocation); @@ -175,7 +175,7 @@ module.exports = function(app) { } pulls = pulls ? Object.keys(JSON.parse(pulls)).length - : 'Can\'t connect to github'; + : "Can't connect to github"; return request( [ @@ -193,7 +193,7 @@ module.exports = function(app) { issues = pulls === parseInt(pulls, 10) && issues ? Object.keys(JSON.parse(issues)).length - pulls - : 'Can\'t connect to GitHub'; + : "Can't connect to GitHub"; return res.send({ issues: issues, pulls: pulls diff --git a/api-server/server/boot/status.js b/api-server/server/boot/status.js index c49bd7ea15..6ac058c621 100644 --- a/api-server/server/boot/status.js +++ b/api-server/server/boot/status.js @@ -1,6 +1,6 @@ export default function bootStatus(app) { const api = app.loopback.Router(); - api.get('/status/ping', (req, res) => res.json({msg: 'pong'})); + api.get('/status/ping', (req, res) => res.json({ msg: 'pong' })); app.use(api); } diff --git a/api-server/server/boot/t-wiki.js b/api-server/server/boot/t-wiki.js index 23e972abc0..55f9981734 100644 --- a/api-server/server/boot/t-wiki.js +++ b/api-server/server/boot/t-wiki.js @@ -5,8 +5,6 @@ module.exports = function(app) { app.use(router); function showForum(req, res) { - res.redirect( - 'http://forum.freecodecamp.org/' - ); + res.redirect('http://forum.freecodecamp.org/'); } }; diff --git a/api-server/server/boot/user.js b/api-server/server/boot/user.js index e1ee041be1..c768511607 100644 --- a/api-server/server/boot/user.js +++ b/api-server/server/boot/user.js @@ -219,8 +219,7 @@ function createPostReportUserProfile(app) { if (!username || !report || report === '') { return res.json({ type: 'danger', - message: - 'Oops, something is not right please re-check your submission.' + message: 'Oops, something is not right please re-check your submission.' }); } return Email.send$( diff --git a/api-server/server/component-passport.js b/api-server/server/component-passport.js index 73ec5b66bc..8f40c01ebb 100644 --- a/api-server/server/component-passport.js +++ b/api-server/server/component-passport.js @@ -1,5 +1,7 @@ import passport from 'passport'; +// eslint-disable-next-line import { + // prettier ignore PassportConfigurator } from '@freecodecamp/loopback-component-passport'; import url from 'url'; @@ -132,9 +134,7 @@ export function setupPassport(app) { } export const saveResponseAuthCookies = () => { - return (req, res, next) => { - const user = req.user; if (!user) { @@ -157,7 +157,6 @@ export const saveResponseAuthCookies = () => { }; export const loginRedirect = () => { - return (req, res) => { const successRedirect = req => { if (!!req && req.session && req.session.returnTo) { diff --git a/api-server/server/middlewares/add-return-to.js b/api-server/server/middlewares/add-return-to.js index 00935140f9..f43c0c5d61 100644 --- a/api-server/server/middlewares/add-return-to.js +++ b/api-server/server/middlewares/add-return-to.js @@ -11,11 +11,7 @@ const pathsOfNoReturn = [ 'css' ]; -const pathsWhiteList = [ - 'challenges', - 'map', - 'commit' -]; +const pathsWhiteList = ['challenges', 'map', 'commit']; const pathsOfNoReturnRegex = new RegExp(pathsOfNoReturn.join('|'), 'i'); const whiteListRegex = new RegExp(pathsWhiteList.join('|'), 'i'); @@ -33,9 +29,9 @@ export default function addReturnToUrl() { ) { return next(); } - req.session.returnTo = req.originalUrl.includes('/map') ? - '/' : - req.originalUrl; + req.session.returnTo = req.originalUrl.includes('/map') + ? '/' + : req.originalUrl; return next(); }; } diff --git a/api-server/server/middlewares/constant-headers.js b/api-server/server/middlewares/constant-headers.js index 28a1ad32bd..7677bba84c 100644 --- a/api-server/server/middlewares/constant-headers.js +++ b/api-server/server/middlewares/constant-headers.js @@ -1,7 +1,8 @@ export default function constantHeaders() { return function(req, res, next) { res.header('Access-Control-Allow-Origin', '*'); - res.header('Access-Control-Allow-Headers', + res.header( + 'Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept' ); next(); diff --git a/api-server/server/middlewares/csp.js b/api-server/server/middlewares/csp.js index 07b41137c9..335d9aa894 100644 --- a/api-server/server/middlewares/csp.js +++ b/api-server/server/middlewares/csp.js @@ -3,7 +3,7 @@ import helmet from 'helmet'; import { homeLocation } from '../../../config/env'; let trusted = [ - '\'self\'', + "'self'", 'https://search.freecodecamp.org', homeLocation, 'https://' + process.env.AUTH0_DOMAIN @@ -31,8 +31,8 @@ export default function csp() { 'https://*.algolia.net' ]), scriptSrc: [ - '\'unsafe-eval\'', - '\'unsafe-inline\'', + "'unsafe-eval'", + "'unsafe-inline'", '*.google-analytics.com', '*.gstatic.com', 'https://*.cloudflare.com', @@ -48,7 +48,7 @@ export default function csp() { '*.ytimg.com' ].concat(trusted), styleSrc: [ - '\'unsafe-inline\'', + "'unsafe-inline'", '*.gstatic.com', '*.googleapis.com', '*.bootstrapcdn.com', diff --git a/api-server/server/middlewares/csurf.js b/api-server/server/middlewares/csurf.js index 5366bb39dc..b28e39e781 100644 --- a/api-server/server/middlewares/csurf.js +++ b/api-server/server/middlewares/csurf.js @@ -1,15 +1,12 @@ import csurf from 'csurf'; export default function() { - const protection = csurf( - { - cookie: { - domain: process.env.COOKIE_DOMAIN || 'localhost' - } + const protection = csurf({ + cookie: { + domain: process.env.COOKIE_DOMAIN || 'localhost' } - ); + }); return function csrf(req, res, next) { - const path = req.path.split('/')[1]; if ((/(^api$|^unauthenticated$|^internal$|^p$)/).test(path)) { return next(); diff --git a/api-server/server/middlewares/flash-cheaters.js b/api-server/server/middlewares/flash-cheaters.js index cb76259c95..f156ee9195 100644 --- a/api-server/server/middlewares/flash-cheaters.js +++ b/api-server/server/middlewares/flash-cheaters.js @@ -14,7 +14,9 @@ export default function flashCheaters() { if ( ALLOWED_METHODS.indexOf(req.method) !== -1 && EXCLUDED_PATHS.indexOf(req.path) === -1 && - req.user && req.url !== '/' && req.user.isCheater + req.user && + req.url !== '/' && + req.user.isCheater ) { req.flash( 'danger', diff --git a/api-server/server/middlewares/validator.js b/api-server/server/middlewares/validator.js index f3961bae55..84bdefd7f5 100644 --- a/api-server/server/middlewares/validator.js +++ b/api-server/server/middlewares/validator.js @@ -20,11 +20,13 @@ export default function() { return false; } const keys = Object.keys(value); - return !!keys.length && + return ( + !!keys.length && // every key is a file keys.every(key => isObject(value[key])) && // every file has contents - keys.map(key => value[key]).every(file => isPoly(file)); + keys.map(key => value[key]).every(file => isPoly(file)) + ); } }, customSanitizers: { @@ -32,16 +34,20 @@ export default function() { trimTags(value) { const tagBody = '(?:[^"\'>]|"[^"]*"|\'[^\']*\')*'; const tagOrComment = new RegExp( - '<(?:' - // Comment body. - + '!--(?:(?:-*[^->])*--+|-?)' - // Special "raw text" elements whose content should be elided. - + '|script\\b' + tagBody + '>[\\s\\S]*?[\\s\\S]*?', + '<(?:' + + // Comment body. + '!--(?:(?:-*[^->])*--+|-?)' + + // Special "raw text" elements whose content should be elided. + '|script\\b' + + tagBody + + '>[\\s\\S]*?[\\s\\S]*?', 'gi' ); let rawValue; diff --git a/api-server/server/models/about.js b/api-server/server/models/about.js index 1ea5037709..0ac115dedb 100644 --- a/api-server/server/models/about.js +++ b/api-server/server/models/about.js @@ -1,6 +1,5 @@ import { createActiveUsers } from '../utils/about.js'; - module.exports = function(About) { const activeUsers = createActiveUsers(); let activeUsersForRendering = 0; @@ -14,17 +13,14 @@ module.exports = function(About) { About.getActiveUsersForRendering = () => activeUsersForRendering; - About.remoteMethod( - 'getActiveUsers', - { - http: { - path: '/get-active-users', - verb: 'get' - }, - returns: { - type: 'number', - arg: 'activeUsers' - } + About.remoteMethod('getActiveUsers', { + http: { + path: '/get-active-users', + verb: 'get' + }, + returns: { + type: 'number', + arg: 'activeUsers' } - ); + }); }; diff --git a/api-server/server/production-start.js b/api-server/server/production-start.js index 4dd934ba47..a1d27e974c 100644 --- a/api-server/server/production-start.js +++ b/api-server/server/production-start.js @@ -11,7 +11,6 @@ log.enabled = true; // this is where server starts booting up const app = require('./server'); - let timeoutHandler; let killTime = 15; diff --git a/api-server/server/rss/index.js b/api-server/server/rss/index.js index 9d41ac776f..a80a2419ab 100644 --- a/api-server/server/rss/index.js +++ b/api-server/server/rss/index.js @@ -11,7 +11,6 @@ const fiveMinutes = 1000 * 60 * 5; class NewsFeed { constructor() { - this.state = { readyState: false, mediumFeed: [], @@ -27,26 +26,23 @@ class NewsFeed { const newState = stateUpdater(this.state); this.state = _.merge({}, this.state, newState); return; - } + }; refreshFeeds = () => { const currentFeed = this.state.combinedFeed.slice(0); log('grabbing feeds'); - return Promise.all([ - getMediumFeed(), - getLybsynFeed() - ]).then( - ([mediumFeed, lybsynFeed]) => this.setState( - state => ({ + return Promise.all([getMediumFeed(), getLybsynFeed()]) + .then(([mediumFeed, lybsynFeed]) => + this.setState(state => ({ ...state, mediumFeed, lybsynFeed - }) - )) + })) + ) .then(() => { log('crossing the streams'); - const { mediumFeed, lybsynFeed} = this.state; - const combinedFeed = [ ...mediumFeed, ...lybsynFeed ].sort((a, b) => { + const { mediumFeed, lybsynFeed } = this.state; + const combinedFeed = [...mediumFeed, ...lybsynFeed].sort((a, b) => { return compareDesc(a.isoDate, b.isoDate); }); this.setState(state => ({ @@ -62,25 +58,24 @@ class NewsFeed { combinedFeed: currentFeed })); }); - } + }; - - getFeed = () => new Promise((resolve) => { + getFeed = () => + new Promise(resolve => { let notReadyCount = 0; function waitForReady() { log('notReadyCount', notReadyCount); notReadyCount++; - return this.state.readyState || notReadyCount === 5 ? - resolve(this.state.combinedFeed) : - setTimeout(waitForReady, 100); + return this.state.readyState || notReadyCount === 5 + ? resolve(this.state.combinedFeed) + : setTimeout(waitForReady, 100); } log('are we ready?', this.state.readyState); - return this.state.readyState ? - resolve(this.state.combinedFeed) : - setTimeout(waitForReady, 100); - }) - + return this.state.readyState + ? resolve(this.state.combinedFeed) + : setTimeout(waitForReady, 100); + }); } export default NewsFeed; diff --git a/api-server/server/rss/medium.js b/api-server/server/rss/medium.js index cb3e083fdc..88c87da2b6 100644 --- a/api-server/server/rss/medium.js +++ b/api-server/server/rss/medium.js @@ -9,7 +9,6 @@ function getExtract(str) { return str.slice(0, str.indexOf('
') + 4); } - function addResponsiveClass(str) { return str.replace(/- Thank you for supporting the freeCodeCamp.org community. -
- )} - {error && ( -- {error} -
+Thank you for supporting the freeCodeCamp.org community.
)} + {error &&{error}
}{error && ( diff --git a/client/src/components/Donation/components/DonateModal.js b/client/src/components/Donation/components/DonateModal.js index 59ca18179a..7c4f304074 100644 --- a/client/src/components/Donation/components/DonateModal.js +++ b/client/src/components/Donation/components/DonateModal.js @@ -20,10 +20,9 @@ import DonateText from './DonateText'; import '../Donation.css'; -const mapStateToProps = createSelector( - isDonationModalOpenSelector, - show => ({ show }) -); +const mapStateToProps = createSelector(isDonationModalOpenSelector, show => ({ + show +})); const mapDispatchToProps = dispatch => bindActionCreators( @@ -73,7 +72,9 @@ class DonateModal extends Component { }; return (
- freeCodeCamp.org is a tiny nonprofit that's helping millions of - people learn to code for free. + freeCodeCamp.org is a tiny nonprofit that's helping millions of people + learn to code for free.
Join {donationsLocale} supporters.
- Your $5 / month donation will help keep tech education free and - open. + Your $5 / month donation will help keep tech education free and open.