diff --git a/services/web/.eslintrc b/services/web/.eslintrc index 5c95c9e4fa..0cb36f3ff3 100644 --- a/services/web/.eslintrc +++ b/services/web/.eslintrc @@ -39,7 +39,6 @@ } }, "rules": { - "dot-notation": "off", "node/no-callback-literal": "off", "node/no-deprecated-api": "off", "node/handle-callback-err": "off", diff --git a/services/web/app.js b/services/web/app.js index fd10368286..16c49d8229 100644 --- a/services/web/app.js +++ b/services/web/app.js @@ -10,10 +10,10 @@ * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md */ const metrics = require('@overleaf/metrics') -metrics.initialize(process.env['METRICS_APP_NAME'] || 'web') +metrics.initialize(process.env.METRICS_APP_NAME || 'web') const Settings = require('settings-sharelatex') const logger = require('logger-sharelatex') -logger.initialize(process.env['METRICS_APP_NAME'] || 'web') +logger.initialize(process.env.METRICS_APP_NAME || 'web') logger.logger.serializers.user = require('./app/src/infrastructure/LoggerSerializers').user logger.logger.serializers.docs = require('./app/src/infrastructure/LoggerSerializers').docs logger.logger.serializers.files = require('./app/src/infrastructure/LoggerSerializers').files @@ -41,7 +41,7 @@ if (!module.parent) { // Called directly // We want to make sure that we provided a password through the environment. - if (!process.env['WEB_API_USER'] || !process.env['WEB_API_PASSWORD']) { + if (!process.env.WEB_API_USER || !process.env.WEB_API_PASSWORD) { throw new Error('No API user and password provided') } mongodb diff --git a/services/web/app/src/Features/Authentication/AuthenticationController.js b/services/web/app/src/Features/Authentication/AuthenticationController.js index 5813b549d2..4bde56200d 100644 --- a/services/web/app/src/Features/Authentication/AuthenticationController.js +++ b/services/web/app/src/Features/Authentication/AuthenticationController.js @@ -296,7 +296,7 @@ const AuthenticationController = { return next() } - if (req.headers['authorization'] != null) { + if (req.headers.authorization != null) { AuthenticationController.httpAuth(req, res, next) } else if (AuthenticationController.isUserLoggedIn(req)) { next() diff --git a/services/web/app/src/Features/FileStore/FileStoreHandler.js b/services/web/app/src/Features/FileStore/FileStoreHandler.js index 93ec3af522..ad77f56f4d 100644 --- a/services/web/app/src/Features/FileStore/FileStoreHandler.js +++ b/services/web/app/src/Features/FileStore/FileStoreHandler.js @@ -111,8 +111,8 @@ const FileStoreHandler = { getFileStream(projectId, fileId, query, callback) { let queryString = '' - if (query != null && query['format'] != null) { - queryString = `?format=${query['format']}` + if (query != null && query.format != null) { + queryString = `?format=${query.format}` } const opts = { method: 'get', @@ -120,10 +120,10 @@ const FileStoreHandler = { timeout: FIVE_MINS_IN_MS, headers: {} } - if (query != null && query['range'] != null) { - const rangeText = query['range'] + if (query != null && query.range != null) { + const rangeText = query.range if (rangeText && rangeText.match != null && rangeText.match(/\d+-\d+/)) { - opts.headers['range'] = `bytes=${query['range']}` + opts.headers.range = `bytes=${query.range}` } } const readStream = request(opts) diff --git a/services/web/app/src/Features/Spelling/SpellingController.js b/services/web/app/src/Features/Spelling/SpellingController.js index f488f7d246..7932eae880 100644 --- a/services/web/app/src/Features/Spelling/SpellingController.js +++ b/services/web/app/src/Features/Spelling/SpellingController.js @@ -30,7 +30,7 @@ module.exports = { const userId = AuthenticationController.getLoggedInUserId(req) url = `/user/${userId}${url}` - req.headers['Host'] = Settings.apis.spelling.host + req.headers.Host = Settings.apis.spelling.host return request({ url: Settings.apis.spelling.url + url, method: req.method, diff --git a/services/web/app/src/Features/Subscription/FeaturesUpdater.js b/services/web/app/src/Features/Subscription/FeaturesUpdater.js index c062efae52..889c4ec77a 100644 --- a/services/web/app/src/Features/Subscription/FeaturesUpdater.js +++ b/services/web/app/src/Features/Subscription/FeaturesUpdater.js @@ -208,29 +208,26 @@ const FeaturesUpdater = { // Special merging logic for non-boolean features if (key === 'compileGroup') { if ( - features['compileGroup'] === 'priority' || - featuresB['compileGroup'] === 'priority' + features.compileGroup === 'priority' || + featuresB.compileGroup === 'priority' ) { - features['compileGroup'] = 'priority' + features.compileGroup = 'priority' } else { - features['compileGroup'] = 'standard' + features.compileGroup = 'standard' } } else if (key === 'collaborators') { - if ( - features['collaborators'] === -1 || - featuresB['collaborators'] === -1 - ) { - features['collaborators'] = -1 + if (features.collaborators === -1 || featuresB.collaborators === -1) { + features.collaborators = -1 } else { - features['collaborators'] = Math.max( - features['collaborators'] || 0, - featuresB['collaborators'] || 0 + features.collaborators = Math.max( + features.collaborators || 0, + featuresB.collaborators || 0 ) } } else if (key === 'compileTimeout') { - features['compileTimeout'] = Math.max( - features['compileTimeout'] || 0, - featuresB['compileTimeout'] || 0 + features.compileTimeout = Math.max( + features.compileTimeout || 0, + featuresB.compileTimeout || 0 ) } else { // Boolean keys, true is better diff --git a/services/web/app/src/Features/Subscription/RecurlyWrapper.js b/services/web/app/src/Features/Subscription/RecurlyWrapper.js index ce84c22bad..bcf0167356 100644 --- a/services/web/app/src/Features/Subscription/RecurlyWrapper.js +++ b/services/web/app/src/Features/Subscription/RecurlyWrapper.js @@ -992,18 +992,18 @@ const RecurlyWrapper = { _parseXml(xml, callback) { var convertDataTypes = function(data) { let key, value - if (data != null && data['$'] != null) { - if (data['$']['nil'] === 'nil') { + if (data != null && data.$ != null) { + if (data.$.nil === 'nil') { data = null - } else if (data['$'].href != null) { - data.url = data['$'].href - delete data['$'] - } else if (data['$']['type'] === 'integer') { - data = parseInt(data['_'], 10) - } else if (data['$']['type'] === 'datetime') { - data = new Date(data['_']) - } else if (data['$']['type'] === 'array') { - delete data['$'] + } else if (data.$.href != null) { + data.url = data.$.href + delete data.$ + } else if (data.$.type === 'integer') { + data = parseInt(data._, 10) + } else if (data.$.type === 'datetime') { + data = new Date(data._) + } else if (data.$.type === 'array') { + delete data.$ let array = [] for (key in data) { value = data[key] diff --git a/services/web/app/src/Features/User/UserEmailsConfirmationHandler.js b/services/web/app/src/Features/User/UserEmailsConfirmationHandler.js index 0b9f10342d..95578e761b 100644 --- a/services/web/app/src/Features/User/UserEmailsConfirmationHandler.js +++ b/services/web/app/src/Features/User/UserEmailsConfirmationHandler.js @@ -17,7 +17,7 @@ function sendConfirmationEmail(userId, email, emailTemplate, callback) { // when force-migrating accounts to v2 from v1, we don't want to send confirmation messages - // setting this env var allows us to turn this behaviour off - if (process.env['SHARELATEX_NO_CONFIRMATION_MESSAGES'] != null) { + if (process.env.SHARELATEX_NO_CONFIRMATION_MESSAGES != null) { return callback(null) } diff --git a/services/web/app/src/Features/User/UserUpdater.js b/services/web/app/src/Features/User/UserUpdater.js index 8cc752e01b..f3b7945925 100644 --- a/services/web/app/src/Features/User/UserUpdater.js +++ b/services/web/app/src/Features/User/UserUpdater.js @@ -189,7 +189,7 @@ async function confirmEmail(userId, email) { } if (Features.hasFeature('affiliations')) { - update['$unset'] = { + update.$unset = { 'emails.$.affiliationUnchecked': 1 } } diff --git a/services/web/app/src/Features/UserMembership/UserMembershipsHandler.js b/services/web/app/src/Features/UserMembership/UserMembershipsHandler.js index 7e3ca22f6a..73ccc4e653 100644 --- a/services/web/app/src/Features/UserMembership/UserMembershipsHandler.js +++ b/services/web/app/src/Features/UserMembership/UserMembershipsHandler.js @@ -51,7 +51,7 @@ const UserMembershipsHandler = { callback = function(error) {} } const removeOperation = { $pull: {} } - removeOperation['$pull'][entityConfig.fields.write] = userId + removeOperation.$pull[entityConfig.fields.write] = userId return EntityModels[entityConfig.modelName].updateMany( {}, removeOperation, diff --git a/services/web/frontend/js/ide/pdf/controllers/PdfController.js b/services/web/frontend/js/ide/pdf/controllers/PdfController.js index bc2aec2bb7..08df2273b3 100644 --- a/services/web/frontend/js/ide/pdf/controllers/PdfController.js +++ b/services/web/frontend/js/ide/pdf/controllers/PdfController.js @@ -270,7 +270,7 @@ App.controller('PdfController', function( const url = `/project/${$scope.project_id}/compile` const params = {} if (options.isAutoCompileOnLoad || options.isAutoCompileOnChange) { - params['auto_compile'] = true + params.auto_compile = true } // if the previous run was a check, clear the error logs if ($scope.check) { diff --git a/services/web/modules/launchpad/app/src/LaunchpadRouter.js b/services/web/modules/launchpad/app/src/LaunchpadRouter.js index b24ce3bf88..7965c72db0 100644 --- a/services/web/modules/launchpad/app/src/LaunchpadRouter.js +++ b/services/web/modules/launchpad/app/src/LaunchpadRouter.js @@ -17,7 +17,7 @@ const AuthorizationMiddleware = require('../../../../app/src/Features/Authorizat module.exports = { apply(webRouter, apiRouter) { - if (Settings.disableModule['launchpad']) { + if (Settings.disableModule.launchpad) { logger.log({}, 'Skipping Init launchpad router') return } diff --git a/services/web/scripts/helpers/batchedUpdate.js b/services/web/scripts/helpers/batchedUpdate.js index d62f7fc10c..b9f032a117 100644 --- a/services/web/scripts/helpers/batchedUpdate.js +++ b/services/web/scripts/helpers/batchedUpdate.js @@ -10,7 +10,7 @@ if (process.env.BATCH_LAST_ID) { async function getNextBatch(collection, query, maxId, projection) { maxId = maxId || BATCH_LAST_ID if (maxId) { - query['_id'] = { $gt: maxId } + query._id = { $gt: maxId } } const entries = await collection .find(query) diff --git a/services/web/scripts/recurly/resync_subscriptions.js b/services/web/scripts/recurly/resync_subscriptions.js index b08296bba0..e433315d9a 100644 --- a/services/web/scripts/recurly/resync_subscriptions.js +++ b/services/web/scripts/recurly/resync_subscriptions.js @@ -16,11 +16,11 @@ const ScriptLogger = { recordMismatch: (subscription, recurlySubscription) => { const mismatchReasons = {} if (subscription.planCode !== recurlySubscription.plan.plan_code) { - mismatchReasons['recurlyPlan'] = recurlySubscription.plan.plan_code - mismatchReasons['olPlan'] = subscription.planCode + mismatchReasons.recurlyPlan = recurlySubscription.plan.plan_code + mismatchReasons.olPlan = subscription.planCode } if (recurlySubscription.state === 'expired') { - mismatchReasons['state'] = 'expired' + mismatchReasons.state = 'expired' } if (!Object.keys(mismatchReasons).length) { diff --git a/services/web/test/acceptance/src/SecurityHeadersTests.js b/services/web/test/acceptance/src/SecurityHeadersTests.js index a6d16ff9fd..57dad1518a 100644 --- a/services/web/test/acceptance/src/SecurityHeadersTests.js +++ b/services/web/test/acceptance/src/SecurityHeadersTests.js @@ -31,16 +31,16 @@ const assert_has_cache_headers = function(response) { headers['cache-control'], 'no-store, no-cache, must-revalidate, proxy-revalidate' ) - assert.equal(headers['pragma'], 'no-cache') - return assert.equal(headers['expires'], '0') + assert.equal(headers.pragma, 'no-cache') + return assert.equal(headers.expires, '0') } const assert_has_no_cache_headers = function(response) { const { headers } = response assert.isUndefined(headers['surrogate-control']) assert.isUndefined(headers['cache-control']) - assert.isUndefined(headers['pragma']) - return assert.isUndefined(headers['expires']) + assert.isUndefined(headers.pragma) + return assert.isUndefined(headers.expires) } const assert_has_asset_caching_headers = function(response) { const { headers } = response diff --git a/services/web/test/acceptance/src/helpers/User.js b/services/web/test/acceptance/src/helpers/User.js index 7827c463fc..0401486e75 100644 --- a/services/web/test/acceptance/src/helpers/User.js +++ b/services/web/test/acceptance/src/helpers/User.js @@ -328,7 +328,7 @@ class User { name, options, response.statusCode, - response.headers['location'], + response.headers.location, body ]) ) diff --git a/services/web/test/acceptance/src/helpers/UserHelper.js b/services/web/test/acceptance/src/helpers/UserHelper.js index 45c9afe568..86d8606dd4 100644 --- a/services/web/test/acceptance/src/helpers/UserHelper.js +++ b/services/web/test/acceptance/src/helpers/UserHelper.js @@ -152,7 +152,7 @@ class UserHelper { * @returns {string} baseUrl */ static baseUrl() { - return `http://${process.env['HTTP_TEST_HOST'] || 'localhost'}:3000` + return `http://${process.env.HTTP_TEST_HOST || 'localhost'}:3000` } /* static async instantiation methods */ diff --git a/services/web/test/acceptance/src/helpers/request.js b/services/web/test/acceptance/src/helpers/request.js index 3362b1b445..b3f0dc12cc 100644 --- a/services/web/test/acceptance/src/helpers/request.js +++ b/services/web/test/acceptance/src/helpers/request.js @@ -1,6 +1,6 @@ // TODO: This file was created by bulk-decaffeinate. // Sanity-check the conversion and remove this comment. -const BASE_URL = `http://${process.env['HTTP_TEST_HOST'] || 'localhost'}:3000` +const BASE_URL = `http://${process.env.HTTP_TEST_HOST || 'localhost'}:3000` const request = require('request').defaults({ baseUrl: BASE_URL, followRedirect: false diff --git a/services/web/test/unit/src/Analytics/AnalyticsControllerTests.js b/services/web/test/unit/src/Analytics/AnalyticsControllerTests.js index d215047b0b..d1121951c8 100644 --- a/services/web/test/unit/src/Analytics/AnalyticsControllerTests.js +++ b/services/web/test/unit/src/Analytics/AnalyticsControllerTests.js @@ -87,7 +87,7 @@ describe('AnalyticsController', function() { this.AuthenticationController.getLoggedInUserId.returns('1234') this.controller.recordEvent(this.req, this.res) this.AnalyticsManager.recordEvent - .calledWith('1234', this.req.params['event'], this.req.body) + .calledWith('1234', this.req.params.event, this.req.body) .should.equal(true) done() }) @@ -95,7 +95,7 @@ describe('AnalyticsController', function() { it('should use the session id', function(done) { this.controller.recordEvent(this.req, this.res) this.AnalyticsManager.recordEvent - .calledWith(this.req.sessionID, this.req.params['event'], this.req.body) + .calledWith(this.req.sessionID, this.req.params.event, this.req.body) .should.equal(true) done() }) @@ -119,10 +119,10 @@ describe('AnalyticsController', function() { this.controller.licences(this.req, this.res) this.InstitutionsAPI.getInstitutionLicences .calledWith( - this.req.query['resource_id'], - this.req.query['start_date'], - this.req.query['end_date'], - this.req.query['lag'] + this.req.query.resource_id, + this.req.query.start_date, + this.req.query.end_date, + this.req.query.lag ) .should.equal(true) done() diff --git a/services/web/test/unit/src/Authentication/AuthenticationControllerTests.js b/services/web/test/unit/src/Authentication/AuthenticationControllerTests.js index dce6d994d2..481894e91f 100644 --- a/services/web/test/unit/src/Authentication/AuthenticationControllerTests.js +++ b/services/web/test/unit/src/Authentication/AuthenticationControllerTests.js @@ -685,7 +685,7 @@ describe('AuthenticationController', function() { describe('with http auth', function() { beforeEach(function() { - this.req.headers['authorization'] = 'Mock Basic Auth' + this.req.headers.authorization = 'Mock Basic Auth' this.AuthenticationController.requireGlobalLogin( this.req, this.res, @@ -898,12 +898,10 @@ describe('AuthenticationController', function() { }) it("should update the user's login count and last logged in date", function() { - this.UserUpdater.updateUser.args[0][1]['$set'][ - 'lastLoggedIn' - ].should.not.equal(undefined) - this.UserUpdater.updateUser.args[0][1]['$inc']['loginCount'].should.equal( - 1 + this.UserUpdater.updateUser.args[0][1].$set.lastLoggedIn.should.not.equal( + undefined ) + this.UserUpdater.updateUser.args[0][1].$inc.loginCount.should.equal(1) }) it('should call the callback', function() { diff --git a/services/web/test/unit/src/Chat/ChatControllerTests.js b/services/web/test/unit/src/Chat/ChatControllerTests.js index f1650a302f..fea1ff0ec9 100644 --- a/services/web/test/unit/src/Chat/ChatControllerTests.js +++ b/services/web/test/unit/src/Chat/ChatControllerTests.js @@ -149,7 +149,7 @@ describe('ChatController', function() { } sinon.spy(this.UserInfoManager, 'getPersonalInfo') return (this.UserInfoController.formatPersonalInfo = user => ({ - formatted: user['mock'] + formatted: user.mock })) }) diff --git a/services/web/test/unit/src/FileStore/FileStoreHandlerTests.js b/services/web/test/unit/src/FileStore/FileStoreHandlerTests.js index 7e9552a720..3356834b6d 100644 --- a/services/web/test/unit/src/FileStore/FileStoreHandlerTests.js +++ b/services/web/test/unit/src/FileStore/FileStoreHandlerTests.js @@ -363,7 +363,7 @@ describe('FileStoreHandler', function() { this.request.callCount.should.equal(1) const { headers } = this.request.firstCall.args[0] expect(headers).to.have.keys('range') - expect(headers['range']).to.equal('bytes=0-10') + expect(headers.range).to.equal('bytes=0-10') done() } ) diff --git a/services/web/test/unit/src/History/HistoryControllerTests.js b/services/web/test/unit/src/History/HistoryControllerTests.js index dbb0215fc6..7b48d29d7d 100644 --- a/services/web/test/unit/src/History/HistoryControllerTests.js +++ b/services/web/test/unit/src/History/HistoryControllerTests.js @@ -185,7 +185,7 @@ describe('HistoryController', function() { describe('with an error', function() { beforeEach(function() { this.HistoryController.proxyToHistoryApi(this.req, this.res, this.next) - return this.proxy.events['error'].call( + return this.proxy.events.error.call( this.proxy, (this.error = new Error('oops')) ) diff --git a/services/web/test/unit/src/Institutions/InstitutionsAPITests.js b/services/web/test/unit/src/Institutions/InstitutionsAPITests.js index fbea95973d..a90962a6b7 100644 --- a/services/web/test/unit/src/Institutions/InstitutionsAPITests.js +++ b/services/web/test/unit/src/Institutions/InstitutionsAPITests.js @@ -117,8 +117,8 @@ describe('InstitutionsAPI', function() { const expectedUrl = `v1.url/api/v2/institutions/${this.institutionId}/institution_licences` requestOptions.url.should.equal(expectedUrl) requestOptions.method.should.equal('GET') - requestOptions.body['start_date'].should.equal(startDate) - requestOptions.body['end_date'].should.equal(endDate) + requestOptions.body.start_date.should.equal(startDate) + requestOptions.body.end_date.should.equal(endDate) requestOptions.body.lag.should.equal('monthly') body.should.equal(responseBody) return done() diff --git a/services/web/test/unit/src/UserMembership/UserMembershipControllerTests.js b/services/web/test/unit/src/UserMembership/UserMembershipControllerTests.js index f791170ffc..6bda8eea37 100644 --- a/services/web/test/unit/src/UserMembership/UserMembershipControllerTests.js +++ b/services/web/test/unit/src/UserMembership/UserMembershipControllerTests.js @@ -343,14 +343,14 @@ describe('UserMembershipController', function() { describe('create', function() { beforeEach(function() { this.req.params.name = 'institution' - this.req.entityConfig = EntityConfigs['institution'] + this.req.entityConfig = EntityConfigs.institution return (this.req.params.id = 123) }) it('creates institution', function(done) { return this.UserMembershipController.create(this.req, { redirect: path => { - expect(path).to.eq(EntityConfigs['institution'].pathsFor(123).index) + expect(path).to.eq(EntityConfigs.institution.pathsFor(123).index) sinon.assert.calledWithMatch( this.UserMembershipHandler.createEntity, 123,