Merge pull request #3496 from overleaf/ae-eslint-dot-notation

Enable the eslint dot-notation rule

GitOrigin-RevId: e11cbad3e8a77a4a60590d3674fbf34feccc5bc9
This commit is contained in:
Alasdair Smith 2020-12-16 10:37:00 +00:00 committed by Copybot
parent 2ff1cf43d6
commit 7cbf2cdd9e
25 changed files with 66 additions and 72 deletions

View file

@ -39,7 +39,6 @@
}
},
"rules": {
"dot-notation": "off",
"node/no-callback-literal": "off",
"node/no-deprecated-api": "off",
"node/handle-callback-err": "off",

View file

@ -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

View file

@ -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()

View file

@ -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)

View file

@ -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,

View file

@ -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

View file

@ -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]

View file

@ -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)
}

View file

@ -189,7 +189,7 @@ async function confirmEmail(userId, email) {
}
if (Features.hasFeature('affiliations')) {
update['$unset'] = {
update.$unset = {
'emails.$.affiliationUnchecked': 1
}
}

View file

@ -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,

View file

@ -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) {

View file

@ -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
}

View file

@ -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)

View file

@ -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) {

View file

@ -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

View file

@ -328,7 +328,7 @@ class User {
name,
options,
response.statusCode,
response.headers['location'],
response.headers.location,
body
])
)

View file

@ -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 */

View file

@ -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

View file

@ -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()

View file

@ -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() {

View file

@ -149,7 +149,7 @@ describe('ChatController', function() {
}
sinon.spy(this.UserInfoManager, 'getPersonalInfo')
return (this.UserInfoController.formatPersonalInfo = user => ({
formatted: user['mock']
formatted: user.mock
}))
})

View file

@ -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()
}
)

View file

@ -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'))
)

View file

@ -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()

View file

@ -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,