Skip to content

Commit

Permalink
chore: eslint no-var, vars-on-top
Browse files Browse the repository at this point in the history
  • Loading branch information
pitaj authored and julianlam committed Feb 8, 2021
1 parent b56d9e1 commit dab3b23
Show file tree
Hide file tree
Showing 255 changed files with 2,010 additions and 2,017 deletions.
2 changes: 0 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@
// WORKING ON
"prefer-rest-params": "off",
"prefer-spread": "off",
"no-var": "off",
"vars-on-top": "off",

// TODO
"consistent-return": "off",
Expand Down
10 changes: 5 additions & 5 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const winston = require('winston');
const fork = require('child_process').fork;

const env = process.env;
var worker;
let worker;

env.NODE_ENV = env.NODE_ENV || 'development';

Expand All @@ -19,10 +19,10 @@ const prestart = require('./src/prestart');

prestart.loadConfig(configFile);

var db = require('./src/database');
const db = require('./src/database');

module.exports = function (grunt) {
var args = [];
const args = [];

if (!grunt.option('verbose')) {
args.push('--log-level=info');
Expand All @@ -39,7 +39,7 @@ module.exports = function (grunt) {
grunt.registerTask('default', ['watch']);

grunt.registerTask('init', async function () {
var done = this.async();
const done = this.async();
let plugins = [];
if (!process.argv.includes('--core')) {
await db.init();
Expand Down Expand Up @@ -165,7 +165,7 @@ module.exports = function (grunt) {

grunt.event.removeAllListeners('watch');
grunt.event.on('watch', (action, filepath, target) => {
var compiling;
let compiling;
if (target === 'styleUpdated_Client') {
compiling = 'clientCSS';
} else if (target === 'styleUpdated_Admin') {
Expand Down
2 changes: 1 addition & 1 deletion install/databases.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function saveDatabaseConfig(config, databaseConfig) {
}

const allQuestions = questions.redis.concat(questions.mongo).concat(questions.postgres);
for (var x = 0; x < allQuestions.length; x += 1) {
for (let x = 0; x < allQuestions.length; x += 1) {
delete config[allQuestions[x].name];
}

Expand Down
20 changes: 10 additions & 10 deletions install/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const formats = [
];

const timestampFormat = winston.format((info) => {
var dateString = `${new Date().toISOString()} [${global.process.pid}]`;
const dateString = `${new Date().toISOString()} [${global.process.pid}]`;
info.level = `${dateString} - ${info.level}`;
return info;
});
Expand Down Expand Up @@ -117,17 +117,17 @@ function ping(req, res) {
}

function welcome(req, res) {
var dbs = ['redis', 'mongo', 'postgres'];
var databases = dbs.map((databaseName) => {
var questions = require(`../src/database/${databaseName}`).questions.filter(question => question && !question.hideOnWebInstall);
const dbs = ['redis', 'mongo', 'postgres'];
const databases = dbs.map((databaseName) => {
const questions = require(`../src/database/${databaseName}`).questions.filter(question => question && !question.hideOnWebInstall);

return {
name: databaseName,
questions: questions,
};
});

var defaults = require('./data/defaults');
const defaults = require('./data/defaults');

res.render('install/index', {
url: nconf.get('url') || (`${req.protocol}://${req.get('host')}`),
Expand All @@ -150,8 +150,8 @@ function install(req, res) {
}
req.setTimeout(0);
installing = true;
var setupEnvVars = nconf.get();
for (var i in req.body) {
const setupEnvVars = nconf.get();
for (const i in req.body) {
if (req.body.hasOwnProperty(i) && !process.env.hasOwnProperty(i)) {
setupEnvVars[i.replace(':', '__')] = req.body[i];
}
Expand All @@ -161,7 +161,7 @@ function install(req, res) {
const pushToRoot = function (parentKey, key) {
setupEnvVars[`${parentKey}__${key}`] = setupEnvVars[parentKey][key];
};
for (var j in setupEnvVars) {
for (const j in setupEnvVars) {
if (setupEnvVars.hasOwnProperty(j) && typeof setupEnvVars[j] === 'object' && setupEnvVars[j] !== null && !Array.isArray(setupEnvVars[j])) {
Object.keys(setupEnvVars[j]).forEach(pushToRoot.bind(null, j));
delete setupEnvVars[j];
Expand All @@ -174,7 +174,7 @@ function install(req, res) {
winston.info(setupEnvVars);
launchUrl = setupEnvVars.url;

var child = require('child_process').fork('app', ['--setup'], {
const child = require('child_process').fork('app', ['--setup'], {
env: setupEnvVars,
});

Expand All @@ -192,7 +192,7 @@ async function launch(req, res) {
res.json({});
server.close();
req.setTimeout(0);
var child;
let child;

if (!nconf.get('launchCmd')) {
child = childProcess.spawn('node', ['loader.js'], {
Expand Down
62 changes: 31 additions & 31 deletions loader.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
'use strict';

var nconf = require('nconf');
var fs = require('fs');
var url = require('url');
var path = require('path');
var fork = require('child_process').fork;
var async = require('async');
var logrotate = require('logrotate-stream');
var mkdirp = require('mkdirp');
const nconf = require('nconf');
const fs = require('fs');
const url = require('url');
const path = require('path');
const fork = require('child_process').fork;
const async = require('async');
const logrotate = require('logrotate-stream');
const mkdirp = require('mkdirp');

var file = require('./src/file');
var pkg = require('./package.json');
const file = require('./src/file');
const pkg = require('./package.json');

var pathToConfig = path.resolve(__dirname, process.env.CONFIG || 'config.json');
const pathToConfig = path.resolve(__dirname, process.env.CONFIG || 'config.json');

nconf.argv().env().file({
file: pathToConfig,
});

var pidFilePath = path.join(__dirname, 'pidfile');
const pidFilePath = path.join(__dirname, 'pidfile');

var outputLogFilePath = path.join(__dirname, nconf.get('logFile') || 'logs/output.log');
const outputLogFilePath = path.join(__dirname, nconf.get('logFile') || 'logs/output.log');

var logDir = path.dirname(outputLogFilePath);
const logDir = path.dirname(outputLogFilePath);
if (!fs.existsSync(logDir)) {
mkdirp.sync(path.dirname(outputLogFilePath));
}

var output = logrotate({ file: outputLogFilePath, size: '1m', keep: 3, compress: true });
var silent = nconf.get('silent') === 'false' ? false : nconf.get('silent') !== false;
var numProcs;
var workers = [];
var Loader = {
const output = logrotate({ file: outputLogFilePath, size: '1m', keep: 3, compress: true });
const silent = nconf.get('silent') === 'false' ? false : nconf.get('silent') !== false;
let numProcs;
const workers = [];
const Loader = {
timesStarted: 0,
};
var appPath = path.join(__dirname, 'app.js');
const appPath = path.join(__dirname, 'app.js');

Loader.init = function (callback) {
if (silent) {
console.log = function () {
var args = Array.prototype.slice.call(arguments);
const args = Array.prototype.slice.call(arguments);
output.write(`${args.join(' ')}\n`);
};
}
Expand Down Expand Up @@ -112,7 +112,7 @@ Loader.start = function (callback) {
numProcs = getPorts().length;
console.log(`Clustering enabled: Spinning up ${numProcs} process(es).\n`);

for (var x = 0; x < numProcs; x += 1) {
for (let x = 0; x < numProcs; x += 1) {
forkWorker(x, x === 0);
}

Expand All @@ -122,8 +122,8 @@ Loader.start = function (callback) {
};

function forkWorker(index, isPrimary) {
var ports = getPorts();
var args = [];
const ports = getPorts();
const args = [];

if (!ports[index]) {
return console.log(`[cluster] invalid port for worker : ${index} ports: ${ports.length}`);
Expand All @@ -133,7 +133,7 @@ function forkWorker(index, isPrimary) {
process.env.isCluster = nconf.get('isCluster') || ports.length > 1;
process.env.port = ports[index];

var worker = fork(appPath, args, {
const worker = fork(appPath, args, {
silent: silent,
env: process.env,
});
Expand All @@ -146,20 +146,20 @@ function forkWorker(index, isPrimary) {
Loader.addWorkerEvents(worker);

if (silent) {
var output = logrotate({ file: outputLogFilePath, size: '1m', keep: 3, compress: true });
const output = logrotate({ file: outputLogFilePath, size: '1m', keep: 3, compress: true });
worker.stdout.pipe(output);
worker.stderr.pipe(output);
}
}

function getPorts() {
var _url = nconf.get('url');
const _url = nconf.get('url');
if (!_url) {
console.log('[cluster] url is undefined, please check your config.json');
process.exit();
}
var urlObject = url.parse(_url);
var port = nconf.get('PORT') || nconf.get('port') || urlObject.port || 4567;
const urlObject = url.parse(_url);
let port = nconf.get('PORT') || nconf.get('port') || urlObject.port || 4567;
if (!Array.isArray(port)) {
port = [port];
}
Expand All @@ -178,7 +178,7 @@ Loader.restart = function () {
throw err;
}

var conf = JSON.parse(configFile);
const conf = JSON.parse(configFile);

nconf.stores.env.readOnly = false;
nconf.set('url', conf.url);
Expand Down Expand Up @@ -217,7 +217,7 @@ fs.open(pathToConfig, 'r', (err) => {
if (nconf.get('daemon') !== 'false' && nconf.get('daemon') !== false) {
if (file.existsSync(pidFilePath)) {
try {
var pid = fs.readFileSync(pidFilePath, { encoding: 'utf-8' });
const pid = fs.readFileSync(pidFilePath, { encoding: 'utf-8' });
process.kill(pid, 0);
process.exit();
} catch (e) {
Expand Down
4 changes: 2 additions & 2 deletions src/admin/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ const fallbackCache = {};
async function initFallback(namespace) {
const template = await fs.promises.readFile(path.resolve(nconf.get('views_dir'), `${namespace}.tpl`), 'utf8');

var title = nsToTitle(namespace);
var translations = sanitize(template);
const title = nsToTitle(namespace);
let translations = sanitize(template);
translations = Translator.removePatterns(translations);
translations = simplify(translations);
translations += `\n${title}`;
Expand Down
2 changes: 1 addition & 1 deletion src/api/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ exports.doTopicAction = async function (action, event, caller, { tids }) {

async function logTopicAction(action, req, tid, title) {
// Only log certain actions to system event log
var actionsToLog = ['delete', 'restore', 'purge'];
const actionsToLog = ['delete', 'restore', 'purge'];
if (!actionsToLog.includes(action)) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/api/topics.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ topicsAPI.create = async function (caller, data) {
};

topicsAPI.reply = async function (caller, data) {
var payload = {
const payload = {
tid: data.tid,
uid: caller.uid,
req: apiHelpers.buildReqObject(caller), // For IP recording
Expand Down
16 changes: 8 additions & 8 deletions src/categories/delete.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'use strict';

var async = require('async');
var db = require('../database');
var batch = require('../batch');
var plugins = require('../plugins');
var topics = require('../topics');
var groups = require('../groups');
var privileges = require('../privileges');
var cache = require('../cache');
const async = require('async');
const db = require('../database');
const batch = require('../batch');
const plugins = require('../plugins');
const topics = require('../topics');
const groups = require('../groups');
const privileges = require('../privileges');
const cache = require('../cache');

module.exports = function (Categories) {
Categories.purge = async function (cid, uid) {
Expand Down
1 change: 0 additions & 1 deletion src/categories/recentreplies.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ module.exports = function (Categories) {
if (category.posts.length) {
return;
}

const posts = [];
getPostsRecursive(category, posts);

Expand Down
4 changes: 2 additions & 2 deletions src/categories/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ module.exports = function (Categories) {
const result = await plugins.hooks.fire('filter:category.update', { cid: cid, category: modifiedFields });

const category = result.category;
var fields = Object.keys(category);
const fields = Object.keys(category);
// move parent to front, so its updated first
var parentCidIndex = fields.indexOf('parentCid');
const parentCidIndex = fields.indexOf('parentCid');
if (parentCidIndex !== -1 && fields.length > 1) {
fields.splice(0, 0, fields.splice(parentCidIndex, 1)[0]);
}
Expand Down
Loading

0 comments on commit dab3b23

Please sign in to comment.