Merge pull request #3495 from overleaf/ae-prettier-2

Upgrade Prettier to v2

GitOrigin-RevId: 85aa3fa1acb6332c4f58c46165a43d1a51471f33
This commit is contained in:
Alf Eaton
2021-04-15 02:05:22 +00:00
committed by Copybot
parent 930d7ba028
commit 1ebc8a79cb
582 changed files with 20382 additions and 20374 deletions
+2 -2
View File
@@ -1,12 +1,12 @@
const crypto = require('crypto')
module.exports = function({
module.exports = function ({
reportUri,
reportOnly = false,
exclude = [],
percentage
}) {
return function(req, res, next) {
return function (req, res, next) {
const originalRender = res.render
res.render = (...args) => {
+1 -1
View File
@@ -69,7 +69,7 @@ class Csrf {
static validateRequest(req, cb) {
// run a dummy csrf check to see if it returns an error
if (cb == null) {
cb = function(valid) {}
cb = function (valid) {}
}
return csrf(req, null, err => cb(err))
}
@@ -26,19 +26,19 @@ if (!IS_DEV_ENV) {
const I18N_HTML_INJECTIONS = new Set()
module.exports = function(webRouter, privateApiRouter, publicApiRouter) {
webRouter.use(function(req, res, next) {
module.exports = function (webRouter, privateApiRouter, publicApiRouter) {
webRouter.use(function (req, res, next) {
res.locals.session = req.session
next()
})
webRouter.use(function(req, res, next) {
webRouter.use(function (req, res, next) {
res.locals.isIE = /\b(msie|trident)\b/i.test(req.headers['user-agent'])
next()
})
function addSetContentDisposition(req, res, next) {
res.setContentDisposition = function(type, opts) {
res.setContentDisposition = function (type, opts) {
const directives = _.map(
opts,
(v, k) => `${k}="${encodeURIComponent(v)}"`
@@ -52,7 +52,7 @@ module.exports = function(webRouter, privateApiRouter, publicApiRouter) {
privateApiRouter.use(addSetContentDisposition)
publicApiRouter.use(addSetContentDisposition)
webRouter.use(function(req, res, next) {
webRouter.use(function (req, res, next) {
req.externalAuthenticationSystemUsed =
Features.externalAuthenticationSystemUsed
res.locals.externalAuthenticationSystemUsed =
@@ -61,7 +61,7 @@ module.exports = function(webRouter, privateApiRouter, publicApiRouter) {
next()
})
webRouter.use(function(req, res, next) {
webRouter.use(function (req, res, next) {
let staticFilesBase
const cdnAvailable =
@@ -83,13 +83,13 @@ module.exports = function(webRouter, privateApiRouter, publicApiRouter) {
staticFilesBase = ''
}
res.locals.buildBaseAssetPath = function() {
res.locals.buildBaseAssetPath = function () {
// Return the base asset path (including the CDN url) so that webpack can
// use this to dynamically fetch scripts (e.g. PDFjs worker)
return Url.resolve(staticFilesBase, '/')
}
res.locals.buildJsPath = function(jsFile) {
res.locals.buildJsPath = function (jsFile) {
let path
if (IS_DEV_ENV) {
// In dev: resolve path within JS asset directory
@@ -108,7 +108,7 @@ module.exports = function(webRouter, privateApiRouter, publicApiRouter) {
// Temporary hack while jQuery/Angular dependencies are *not* bundled,
// instead copied into output directory
res.locals.buildCopiedJsAssetPath = function(jsFile) {
res.locals.buildCopiedJsAssetPath = function (jsFile) {
let path
if (IS_DEV_ENV) {
// In dev: resolve path to root directory
@@ -141,7 +141,7 @@ module.exports = function(webRouter, privateApiRouter, publicApiRouter) {
(brandVariation != null ? brandVariation.brand_id : undefined) ===
IEEE_BRAND_ID
res.locals.getCssThemeModifier = function(userSettings, brandVariation) {
res.locals.getCssThemeModifier = function (userSettings, brandVariation) {
// Themes only exist in OL v2
if (Settings.overleaf != null) {
// The IEEE theme takes precedence over the user personal setting, i.e. a user with
@@ -154,7 +154,7 @@ module.exports = function(webRouter, privateApiRouter, publicApiRouter) {
}
}
res.locals.buildStylesheetPath = function(cssFileName) {
res.locals.buildStylesheetPath = function (cssFileName) {
let path
if (IS_DEV_ENV) {
// In dev: resolve path within CSS asset directory
@@ -171,11 +171,11 @@ module.exports = function(webRouter, privateApiRouter, publicApiRouter) {
return Url.resolve(staticFilesBase, path)
}
res.locals.buildCssPath = function(themeModifier = '') {
res.locals.buildCssPath = function (themeModifier = '') {
return res.locals.buildStylesheetPath(`${themeModifier}style.css`)
}
res.locals.buildImgPath = function(imgFile) {
res.locals.buildImgPath = function (imgFile) {
const path = Path.join('/img/', imgFile)
return Url.resolve(staticFilesBase, path)
}
@@ -183,8 +183,8 @@ module.exports = function(webRouter, privateApiRouter, publicApiRouter) {
next()
})
webRouter.use(function(req, res, next) {
res.locals.translate = function(key, vars, components) {
webRouter.use(function (req, res, next) {
res.locals.translate = function (key, vars, components) {
vars = vars || {}
if (Settings.i18n.checkForHTMLInVars) {
@@ -216,7 +216,7 @@ module.exports = function(webRouter, privateApiRouter, publicApiRouter) {
const parsedOriginalUrl = Url.parse(req.originalUrl)
res.locals.currentUrl = parsedOriginalUrl.pathname
res.locals.currentUrlWithQueryParams = parsedOriginalUrl.path
res.locals.capitalize = function(string) {
res.locals.capitalize = function (string) {
if (string.length === 0) {
return ''
}
@@ -225,8 +225,8 @@ module.exports = function(webRouter, privateApiRouter, publicApiRouter) {
next()
})
webRouter.use(function(req, res, next) {
res.locals.getUserEmail = function() {
webRouter.use(function (req, res, next) {
res.locals.getUserEmail = function () {
const user = AuthenticationController.getSessionUser(req)
const email = (user != null ? user.email : undefined) || ''
return email
@@ -234,13 +234,13 @@ module.exports = function(webRouter, privateApiRouter, publicApiRouter) {
next()
})
webRouter.use(function(req, res, next) {
webRouter.use(function (req, res, next) {
res.locals.StringHelper = require('../Features/Helpers/StringHelper')
next()
})
webRouter.use(function(req, res, next) {
res.locals.buildReferalUrl = function(referalMedium) {
webRouter.use(function (req, res, next) {
res.locals.buildReferalUrl = function (referalMedium) {
let url = Settings.siteUrl
const currentUser = AuthenticationController.getSessionUser(req)
if (
@@ -251,7 +251,7 @@ module.exports = function(webRouter, privateApiRouter, publicApiRouter) {
}
return url
}
res.locals.getReferalId = function() {
res.locals.getReferalId = function () {
const currentUser = AuthenticationController.getSessionUser(req)
if (
currentUser != null &&
@@ -263,25 +263,25 @@ module.exports = function(webRouter, privateApiRouter, publicApiRouter) {
next()
})
webRouter.use(function(req, res, next) {
webRouter.use(function (req, res, next) {
res.locals.csrfToken = req != null ? req.csrfToken() : undefined
next()
})
webRouter.use(function(req, res, next) {
webRouter.use(function (req, res, next) {
res.locals.gaToken =
Settings.analytics && Settings.analytics.ga && Settings.analytics.ga.token
res.locals.gaOptimizeId = _.get(Settings, ['analytics', 'gaOptimize', 'id'])
next()
})
webRouter.use(function(req, res, next) {
webRouter.use(function (req, res, next) {
res.locals.getReqQueryParam = field =>
req.query != null ? req.query[field] : undefined
next()
})
webRouter.use(function(req, res, next) {
webRouter.use(function (req, res, next) {
const currentUser = AuthenticationController.getSessionUser(req)
if (currentUser != null) {
res.locals.user = {
@@ -293,7 +293,7 @@ module.exports = function(webRouter, privateApiRouter, publicApiRouter) {
next()
})
webRouter.use(function(req, res, next) {
webRouter.use(function (req, res, next) {
res.locals.getLoggedInUserId = () =>
AuthenticationController.getLoggedInUserId(req)
res.locals.getSessionUser = () =>
@@ -301,7 +301,7 @@ module.exports = function(webRouter, privateApiRouter, publicApiRouter) {
next()
})
webRouter.use(function(req, res, next) {
webRouter.use(function (req, res, next) {
// Clone the nav settings so they can be modified for each request
res.locals.nav = {}
for (let key in Settings.nav) {
@@ -311,7 +311,7 @@ module.exports = function(webRouter, privateApiRouter, publicApiRouter) {
next()
})
webRouter.use(function(req, res, next) {
webRouter.use(function (req, res, next) {
if (Settings.reloadModuleViewsOnEachRequest) {
Modules.loadViewIncludes()
}
@@ -320,7 +320,7 @@ module.exports = function(webRouter, privateApiRouter, publicApiRouter) {
next()
})
webRouter.use(function(req, res, next) {
webRouter.use(function (req, res, next) {
// TODO
if (Settings.overleaf != null) {
res.locals.overallThemes = [
@@ -339,12 +339,12 @@ module.exports = function(webRouter, privateApiRouter, publicApiRouter) {
next()
})
webRouter.use(function(req, res, next) {
webRouter.use(function (req, res, next) {
res.locals.settings = Settings
next()
})
webRouter.use(function(req, res, next) {
webRouter.use(function (req, res, next) {
res.locals.ExposedSettings = {
isOverleaf: Settings.overleaf != null,
appName: Settings.appName,
@@ -59,9 +59,9 @@ class SizeLimitedStream extends Transform {
const FileWriter = {
ensureDumpFolderExists(callback) {
if (callback == null) {
callback = function(error) {}
callback = function (error) {}
}
return fs.mkdir(Settings.path.dumpFolder, function(error) {
return fs.mkdir(Settings.path.dumpFolder, function (error) {
if (error != null && error.code !== 'EEXIST') {
// Ignore error about already existing
return callback(error)
@@ -72,22 +72,22 @@ const FileWriter = {
writeLinesToDisk(identifier, lines, callback) {
if (callback == null) {
callback = function(error, fsPath) {}
callback = function (error, fsPath) {}
}
return FileWriter.writeContentToDisk(identifier, lines.join('\n'), callback)
},
writeContentToDisk(identifier, content, callback) {
if (callback == null) {
callback = function(error, fsPath) {}
callback = function (error, fsPath) {}
}
callback = _.once(callback)
const fsPath = `${Settings.path.dumpFolder}/${identifier}_${uuid.v4()}`
return FileWriter.ensureDumpFolderExists(function(error) {
return FileWriter.ensureDumpFolderExists(function (error) {
if (error != null) {
return callback(error)
}
return fs.writeFile(fsPath, content, function(error) {
return fs.writeFile(fsPath, content, function (error) {
if (error != null) {
return callback(error)
}
@@ -102,7 +102,7 @@ const FileWriter = {
options = {}
}
if (callback == null) {
callback = function(error, fsPath) {}
callback = function (error, fsPath) {}
}
options = options || {}
@@ -110,7 +110,7 @@ const FileWriter = {
stream.pause()
FileWriter.ensureDumpFolderExists(function(error) {
FileWriter.ensureDumpFolderExists(function (error) {
const writeStream = fs.createWriteStream(fsPath)
if (error != null) {
@@ -124,13 +124,13 @@ const FileWriter = {
// if writing fails, we want to consume the bytes from the source, to avoid leaks
for (const evt of ['error', 'close']) {
writeStream.on(evt, function() {
writeStream.on(evt, function () {
passThrough.unpipe(writeStream)
passThrough.resume()
})
}
pipeline(stream, passThrough, writeStream, function(err) {
pipeline(stream, passThrough, writeStream, function (err) {
if (
options.maxSizeBytes &&
passThrough.bytes >= options.maxSizeBytes &&
@@ -168,20 +168,20 @@ const FileWriter = {
options = {}
}
if (callback == null) {
callback = function(error, fsPath) {}
callback = function (error, fsPath) {}
}
options = options || {}
callback = _.once(callback)
const stream = request.get(url)
stream.on('error', function(err) {
stream.on('error', function (err) {
logger.warn(
{ err, identifier, url },
'[writeUrlToDisk] something went wrong with writing to disk'
)
callback(err)
})
stream.on('response', function(response) {
stream.on('response', function (response) {
if (response.statusCode >= 200 && response.statusCode < 300) {
FileWriter.writeStreamToDisk(identifier, stream, options, callback)
} else {
@@ -74,7 +74,7 @@ module.exports = GeoIpLookup = {
json: true
}
logger.log({ ip, opts }, 'getting geo ip details')
return request.get(opts, function(err, res, ipDetails) {
return request.get(opts, function (err, res, ipDetails) {
if (err != null) {
logger.warn({ err, ip }, 'error getting ip details')
}
@@ -83,7 +83,7 @@ module.exports = GeoIpLookup = {
},
getCurrencyCode(ip, callback) {
return GeoIpLookup.getDetails(ip, function(err, ipDetails) {
return GeoIpLookup.getDetails(ip, function (err, ipDetails) {
if (err != null || ipDetails == null) {
logger.err(
{ err, ip },
@@ -122,7 +122,7 @@ function fireHook(name, ...rest) {
const callback = rest[adjustedLength - 1]
const methods = _hooks[name] || []
const callMethods = methods.map(method => cb => method(...args, cb))
async.series(callMethods, function(error, results) {
async.series(callMethods, function (error, results) {
if (error) {
return callback(error)
}
@@ -23,7 +23,7 @@ module.exports = ProxyManager = {
for (var proxyUrl in settings.proxyUrls) {
const target = settings.proxyUrls[proxyUrl]
result.push(
(function(target) {
(function (target) {
const method =
(target.options != null ? target.options.method : undefined) ||
'get'
@@ -39,7 +39,7 @@ module.exports = ProxyManager = {
},
createProxy(target) {
return function(req, res, next) {
return function (req, res, next) {
const targetUrl = makeTargetUrl(target, req)
logger.log({ targetUrl, reqUrl: req.url }, 'proxying url')
@@ -67,7 +67,7 @@ module.exports = ProxyManager = {
// make a URL from a proxy target.
// if the query is specified, set/replace the target's query with the given query
var makeTargetUrl = function(target, req) {
var makeTargetUrl = function (target, req) {
const targetUrl = URL.parse(parseSettingUrl(target, req))
if (req.query != null && Object.keys(req.query).length > 0) {
targetUrl.query = req.query
@@ -76,7 +76,7 @@ var makeTargetUrl = function(target, req) {
return targetUrl.format()
}
var parseSettingUrl = function(target, { params }) {
var parseSettingUrl = function (target, { params }) {
let path
if (typeof target === 'string') {
return target
@@ -11,7 +11,7 @@
let trackOpenSockets
const _ = require('underscore')
const metrics = require('@overleaf/metrics')
;(trackOpenSockets = function() {
;(trackOpenSockets = function () {
metrics.gauge(
'http.open-sockets',
_.size(require('http').globalAgent.sockets.length),
@@ -11,7 +11,7 @@ const RateLimiter = {
return callback(null, true)
}
if (callback == null) {
callback = function() {}
callback = function () {}
}
const namespace = `RateLimit:${opts.endpointName}:`
const k = `{${opts.subjectName}}`
@@ -21,7 +21,7 @@ const RateLimiter = {
interval: opts.timeInterval * 1000,
maxInInterval: opts.throttle
})
limiter(k, function(err, timeLeft, actionsLeft) {
limiter(k, function (err, timeLeft, actionsLeft) {
if (err) {
return callback(err)
}
@@ -38,7 +38,7 @@ module.exports = RedirectManager = {
},
createRedirect(target) {
return function(req, res, next) {
return function (req, res, next) {
let url
if (
(req.headers != null ? req.headers['x-skip-redirects'] : undefined) !=
@@ -75,7 +75,7 @@ module.exports = RedirectManager = {
// Naively get the query params string. Stringifying the req.query object may
// have differences between Express and Rails, so safer to just pass the raw
// string
var getQueryString = function(req) {
var getQueryString = function (req) {
const { search } = URL.parse(req.url)
if (search) {
return search
@@ -141,7 +141,7 @@ passport.use(
passport.serializeUser(AuthenticationController.serializeUser)
passport.deserializeUser(AuthenticationController.deserializeUser)
Modules.hooks.fire('passportSetup', passport, function(err) {
Modules.hooks.fire('passportSetup', passport, function (err) {
if (err != null) {
logger.err({ err }, 'error setting up passport in modules')
}
@@ -155,7 +155,7 @@ webRouter.use(translations.i18nMiddleware)
webRouter.use(translations.setLangBasedOnDomainMiddleware)
// Measure expiry from last request, not last login
webRouter.use(function(req, res, next) {
webRouter.use(function (req, res, next) {
if (!req.session.noSessionCallback) {
req.session.touch()
if (AuthenticationController.isUserLoggedIn(req)) {
@@ -177,7 +177,7 @@ expressLocals(webRouter, privateApiRouter, publicApiRouter)
webRouter.use(SessionAutostartMiddleware.invokeCallbackMiddleware)
webRouter.use(function(req, res, next) {
webRouter.use(function (req, res, next) {
if (Settings.siteIsOpen) {
next()
} else if (
@@ -190,7 +190,7 @@ webRouter.use(function(req, res, next) {
}
})
webRouter.use(function(req, res, next) {
webRouter.use(function (req, res, next) {
if (Settings.editorIsOpen) {
next()
} else if (req.url.indexOf('/admin') === 0) {
@@ -204,7 +204,7 @@ webRouter.use(AuthenticationController.validateAdmin)
// add security headers using Helmet
const noCacheMiddleware = require('nocache')()
webRouter.use(function(req, res, next) {
webRouter.use(function (req, res, next) {
const isLoggedIn = AuthenticationController.isUserLoggedIn(req)
const isProjectPage = !!req.path.match('^/project/[a-f0-9]{24}$')
if (isLoggedIn || isProjectPage) {
@@ -40,7 +40,7 @@ module.exports = {
enableValidationToken(sessionStore) {
// generate an identifier from the sessionID for every new session
const originalGenerate = sessionStore.generate
sessionStore.generate = function(req) {
sessionStore.generate = function (req) {
originalGenerate(req)
// add the validation token as a property that cannot be overwritten
Object.defineProperty(req.session, 'validationToken', {
@@ -9,7 +9,7 @@ const fallbackLanguageCode = Settings.i18n.defaultLng || 'en'
const availableLanguageCodes = []
const availableHosts = new Map()
const subdomainConfigs = new Map()
Object.values(Settings.i18n.subdomainLang || {}).forEach(function(spec) {
Object.values(Settings.i18n.subdomainLang || {}).forEach(function (spec) {
availableLanguageCodes.push(spec.lngCode)
// prebuild a host->lngCode mapping for the usage at runtime in the
// middleware