Decaf cleanup: simplify null checks

This commit is contained in:
Eric Mc Sween
2020-09-03 14:56:27 -04:00
parent f2734c86ca
commit 2a31f8c8d7

View File

@@ -4,13 +4,6 @@
no-return-assign, no-return-assign,
no-unused-vars, no-unused-vars,
*/ */
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
let DockerRunner, oneHour let DockerRunner, oneHour
const Settings = require('settings-sharelatex') const Settings = require('settings-sharelatex')
const logger = require('logger-sharelatex') const logger = require('logger-sharelatex')
@@ -286,10 +279,7 @@ module.exports = DockerRunner = {
} }
} }
if ( if (Settings.path != null && Settings.path.synctexBinHostPath != null) {
(Settings.path != null ? Settings.path.synctexBinHostPath : undefined) !=
null
) {
options.HostConfig.Binds.push( options.HostConfig.Binds.push(
`${Settings.path.synctexBinHostPath}:/opt/synctex:ro` `${Settings.path.synctexBinHostPath}:/opt/synctex:ro`
) )
@@ -367,7 +357,7 @@ module.exports = DockerRunner = {
if (err != null) { if (err != null) {
return cb(err) return cb(err)
} }
if (!(stats != null ? stats.isDirectory() : undefined)) { if (!stats.isDirectory()) {
return cb(DockerRunner.ERR_NOT_DIRECTORY) return cb(DockerRunner.ERR_NOT_DIRECTORY)
} }
cb() cb()
@@ -402,20 +392,17 @@ module.exports = DockerRunner = {
return callback(error) return callback(error)
} }
container.start(function (error) { container.start(function (error) {
if ( if (error != null && error.statusCode !== 304) {
error != null &&
(error != null ? error.statusCode : undefined) !== 304
) {
// already running
callback(error) callback(error)
} else { } else {
// already running
callback() callback()
} }
}) })
} }
) )
container.inspect(function (error, stats) { container.inspect(function (error, stats) {
if ((error != null ? error.statusCode : undefined) === 404) { if (error != null && error.statusCode === 404) {
createAndStartContainer() createAndStartContainer()
} else if (error != null) { } else if (error != null) {
logger.err( logger.err(
@@ -562,10 +549,7 @@ module.exports = DockerRunner = {
logger.log({ container_id: containerId }, 'destroying docker container') logger.log({ container_id: containerId }, 'destroying docker container')
const container = dockerode.getContainer(containerId) const container = dockerode.getContainer(containerId)
container.remove({ force: shouldForce === true }, function (error) { container.remove({ force: shouldForce === true }, function (error) {
if ( if (error != null && error.statusCode === 404) {
error != null &&
(error != null ? error.statusCode : undefined) === 404
) {
logger.warn( logger.warn(
{ err: error, container_id: containerId }, { err: error, container_id: containerId },
'container not found, continuing' 'container not found, continuing'
@@ -590,9 +574,7 @@ module.exports = DockerRunner = {
Settings.clsi.docker.maxContainerAge || (oneHour = 60 * 60 * 1000), Settings.clsi.docker.maxContainerAge || (oneHour = 60 * 60 * 1000),
examineOldContainer(container, callback) { examineOldContainer(container, callback) {
const name = const name = container.Name || (container.Names && container.Names[0])
container.Name ||
(container.Names != null ? container.Names[0] : undefined)
const created = container.Created * 1000 // creation time is returned in seconds const created = container.Created * 1000 // creation time is returned in seconds
const now = Date.now() const now = Date.now()
const age = now - created const age = now - created