lint: Run eslint --fix on src/

This commit is contained in:
Richard Hansen 2020-11-23 13:24:19 -05:00 committed by John McLear
parent b8d07a42eb
commit 8e5fd19db2
109 changed files with 9061 additions and 10572 deletions

View file

@ -26,17 +26,17 @@
* limitations under the License.
*/
var absolutePaths = require('./AbsolutePaths');
var fs = require("fs");
var os = require("os");
var path = require('path');
var argv = require('./Cli').argv;
var npm = require("npm/lib/npm.js");
var jsonminify = require("jsonminify");
var log4js = require("log4js");
var randomString = require("./randomstring");
var suppressDisableMsg = " -- To suppress these warning messages change suppressErrorsInPadText to true in your settings.json\n";
var _ = require("underscore");
const absolutePaths = require('./AbsolutePaths');
const fs = require('fs');
const os = require('os');
const path = require('path');
const argv = require('./Cli').argv;
const npm = require('npm/lib/npm.js');
const jsonminify = require('jsonminify');
const log4js = require('log4js');
const randomString = require('./randomstring');
const suppressDisableMsg = ' -- To suppress these warning messages change suppressErrorsInPadText to true in your settings.json\n';
const _ = require('underscore');
/* Root path of the installation */
exports.root = absolutePaths.findEtherpadRoot();
@ -59,14 +59,14 @@ console.log(`Random string used for versioning assets: ${exports.randomVersionSt
/**
* The app title, visible e.g. in the browser window
*/
exports.title = "Etherpad";
exports.title = 'Etherpad';
/**
* The app favicon fully specified url, visible e.g. in the browser window
*/
exports.favicon = "favicon.ico";
exports.faviconPad = "../" + exports.favicon;
exports.faviconTimeslider = "../../" + exports.favicon;
exports.favicon = 'favicon.ico';
exports.faviconPad = `../${exports.favicon}`;
exports.faviconTimeslider = `../../${exports.favicon}`;
/*
* Skin name.
@ -76,12 +76,12 @@ exports.faviconTimeslider = "../../" + exports.favicon;
*/
exports.skinName = null;
exports.skinVariants = "super-light-toolbar super-light-editor light-background";
exports.skinVariants = 'super-light-toolbar super-light-editor light-background';
/**
* The IP ep-lite should listen to
*/
exports.ip = "0.0.0.0";
exports.ip = '0.0.0.0';
/**
* The Port ep-lite should listen to
@ -107,60 +107,60 @@ exports.socketTransportProtocols = ['xhr-polling', 'jsonp-polling', 'htmlfile'];
/*
* The Type of the database
*/
exports.dbType = "dirty";
exports.dbType = 'dirty';
/**
* This setting is passed with dbType to ueberDB to set up the database
*/
exports.dbSettings = { "filename" : path.join(exports.root, "var/dirty.db") };
exports.dbSettings = {filename: path.join(exports.root, 'var/dirty.db')};
/**
* The default Text of a new pad
*/
exports.defaultPadText = "Welcome to Etherpad!\n\nThis pad text is synchronized as you type, so that everyone viewing this page sees the same text. This allows you to collaborate seamlessly on documents!\n\nEtherpad on Github: https:\/\/github.com\/ether\/etherpad-lite\n";
exports.defaultPadText = 'Welcome to Etherpad!\n\nThis pad text is synchronized as you type, so that everyone viewing this page sees the same text. This allows you to collaborate seamlessly on documents!\n\nEtherpad on Github: https:\/\/github.com\/ether\/etherpad-lite\n';
/**
* The default Pad Settings for a user (Can be overridden by changing the setting
*/
exports.padOptions = {
"noColors": false,
"showControls": true,
"showChat": true,
"showLineNumbers": true,
"useMonospaceFont": false,
"userName": false,
"userColor": false,
"rtl": false,
"alwaysShowChat": false,
"chatAndUsers": false,
"lang": "en-gb"
noColors: false,
showControls: true,
showChat: true,
showLineNumbers: true,
useMonospaceFont: false,
userName: false,
userColor: false,
rtl: false,
alwaysShowChat: false,
chatAndUsers: false,
lang: 'en-gb',
},
/**
* Whether certain shortcut keys are enabled for a user in the pad
*/
exports.padShortcutEnabled = {
"altF9" : true,
"altC" : true,
"delete" : true,
"cmdShift2" : true,
"return" : true,
"esc" : true,
"cmdS" : true,
"tab" : true,
"cmdZ" : true,
"cmdY" : true,
"cmdB" : true,
"cmdI" : true,
"cmdU" : true,
"cmd5" : true,
"cmdShiftL" : true,
"cmdShiftN" : true,
"cmdShift1" : true,
"cmdShiftC" : true,
"cmdH" : true,
"ctrlHome" : true,
"pageUp" : true,
"pageDown" : true,
altF9: true,
altC: true,
delete: true,
cmdShift2: true,
return: true,
esc: true,
cmdS: true,
tab: true,
cmdZ: true,
cmdY: true,
cmdB: true,
cmdI: true,
cmdU: true,
cmd5: true,
cmdShiftL: true,
cmdShiftN: true,
cmdShift1: true,
cmdShiftC: true,
cmdH: true,
ctrlHome: true,
pageUp: true,
pageDown: true,
},
/**
@ -168,20 +168,20 @@ exports.padShortcutEnabled = {
*/
exports.toolbar = {
left: [
["bold", "italic", "underline", "strikethrough"],
["orderedlist", "unorderedlist", "indent", "outdent"],
["undo", "redo"],
["clearauthorship"]
['bold', 'italic', 'underline', 'strikethrough'],
['orderedlist', 'unorderedlist', 'indent', 'outdent'],
['undo', 'redo'],
['clearauthorship'],
],
right: [
["importexport", "timeslider", "savedrevision"],
["settings", "embed"],
["showusers"]
['importexport', 'timeslider', 'savedrevision'],
['settings', 'embed'],
['showusers'],
],
timeslider: [
["timeslider_export", "timeslider_settings", "timeslider_returnToPad"]
]
}
['timeslider_export', 'timeslider_settings', 'timeslider_returnToPad'],
],
};
/**
* A flag that requires any user to have a valid session (via the api) before accessing a pad
@ -196,7 +196,7 @@ exports.editOnly = false;
/**
* Max age that responses will have (affects caching layer).
*/
exports.maxAge = 1000*60*60*6; // 6 hours
exports.maxAge = 1000 * 60 * 60 * 6; // 6 hours
/**
* A flag that shows if minification is enabled or not
@ -226,7 +226,7 @@ exports.allowUnknownFileEnds = true;
/**
* The log level of log4js
*/
exports.loglevel = "INFO";
exports.loglevel = 'INFO';
/**
* Disable IP logging
@ -251,7 +251,7 @@ exports.indentationOnNewLine = true;
/*
* log4js appender configuration
*/
exports.logconfig = { appenders: [{ type: "console" }]};
exports.logconfig = {appenders: [{type: 'console'}]};
/*
* Session Key, do not sure this.
@ -303,28 +303,28 @@ exports.scrollWhenFocusLineIsOutOfViewport = {
/*
* Percentage of viewport height to be additionally scrolled.
*/
"percentage": {
"editionAboveViewport": 0,
"editionBelowViewport": 0
percentage: {
editionAboveViewport: 0,
editionBelowViewport: 0,
},
/*
* Time (in milliseconds) used to animate the scroll transition. Set to 0 to
* disable animation
*/
"duration": 0,
duration: 0,
/*
* Percentage of viewport height to be additionally scrolled when user presses arrow up
* in the line of the top of the viewport.
*/
"percentageToScrollWhenUserPressesArrowUp": 0,
percentageToScrollWhenUserPressesArrowUp: 0,
/*
* Flag to control if it should scroll when user places the caret in the last
* line of the viewport
*/
"scrollWhenCaretIsInTheLastLineOfViewport": false
scrollWhenCaretIsInTheLastLineOfViewport: false,
};
/*
@ -350,10 +350,10 @@ exports.customLocaleStrings = {};
*/
exports.importExportRateLimiting = {
// duration of the rate limit window (milliseconds)
"windowMs": 90000,
windowMs: 90000,
// maximum number of requests per IP to allow during the rate limit window
"max": 10
max: 10,
};
/*
@ -366,10 +366,10 @@ exports.importExportRateLimiting = {
*/
exports.commitRateLimiting = {
// duration of the rate limit window (seconds)
"duration": 1,
duration: 1,
// maximum number of chanes per IP to allow during the rate limit window
"points": 10
points: 10,
};
/*
@ -381,64 +381,64 @@ exports.commitRateLimiting = {
exports.importMaxFileSize = 50 * 1024 * 1024;
// checks if abiword is avaiable
exports.abiwordAvailable = function() {
exports.abiwordAvailable = function () {
if (exports.abiword != null) {
return os.type().indexOf("Windows") != -1 ? "withoutPDF" : "yes";
return os.type().indexOf('Windows') != -1 ? 'withoutPDF' : 'yes';
} else {
return "no";
return 'no';
}
};
exports.sofficeAvailable = function() {
exports.sofficeAvailable = function () {
if (exports.soffice != null) {
return os.type().indexOf("Windows") != -1 ? "withoutPDF": "yes";
return os.type().indexOf('Windows') != -1 ? 'withoutPDF' : 'yes';
} else {
return "no";
return 'no';
}
};
exports.exportAvailable = function() {
var abiword = exports.abiwordAvailable();
var soffice = exports.sofficeAvailable();
exports.exportAvailable = function () {
const abiword = exports.abiwordAvailable();
const soffice = exports.sofficeAvailable();
if (abiword == "no" && soffice == "no") {
return "no";
} else if ((abiword == "withoutPDF" && soffice == "no") || (abiword == "no" && soffice == "withoutPDF")) {
return "withoutPDF";
if (abiword == 'no' && soffice == 'no') {
return 'no';
} else if ((abiword == 'withoutPDF' && soffice == 'no') || (abiword == 'no' && soffice == 'withoutPDF')) {
return 'withoutPDF';
} else {
return "yes";
return 'yes';
}
};
// Provide git version if available
exports.getGitCommit = function() {
var version = "";
exports.getGitCommit = function () {
let version = '';
try {
var rootPath = exports.root;
if (fs.lstatSync(rootPath + '/.git').isFile()) {
rootPath = fs.readFileSync(rootPath + '/.git', "utf8");
let rootPath = exports.root;
if (fs.lstatSync(`${rootPath}/.git`).isFile()) {
rootPath = fs.readFileSync(`${rootPath}/.git`, 'utf8');
rootPath = rootPath.split(' ').pop().trim();
} else {
rootPath += '/.git';
}
var ref = fs.readFileSync(rootPath + "/HEAD", "utf-8");
if (ref.startsWith("ref: ")) {
var refPath = rootPath + "/" + ref.substring(5, ref.indexOf("\n"));
version = fs.readFileSync(refPath, "utf-8");
const ref = fs.readFileSync(`${rootPath}/HEAD`, 'utf-8');
if (ref.startsWith('ref: ')) {
const refPath = `${rootPath}/${ref.substring(5, ref.indexOf('\n'))}`;
version = fs.readFileSync(refPath, 'utf-8');
} else {
version = ref;
}
version = version.substring(0, 7);
} catch(e) {
console.warn("Can't get git version for server header\n" + e.message)
} catch (e) {
console.warn(`Can't get git version for server header\n${e.message}`);
}
return version;
}
};
// Return etherpad version from package.json
exports.getEpVersion = function() {
exports.getEpVersion = function () {
return require('ep_etherpad-lite/package.json').version;
}
};
/**
* Receives a settingsObj and, if the property name is a valid configuration
@ -448,9 +448,9 @@ exports.getEpVersion = function() {
* both "settings.json" and "credentials.json".
*/
function storeSettings(settingsObj) {
for (var i in settingsObj) {
for (const i in settingsObj) {
// test if the setting starts with a lowercase character
if (i.charAt(0).search("[a-z]") !== 0) {
if (i.charAt(0).search('[a-z]') !== 0) {
console.warn(`Settings should start with a lowercase character: '${i}'`);
}
@ -482,26 +482,26 @@ function storeSettings(settingsObj) {
* in the literal string "null", instead.
*/
function coerceValue(stringValue) {
// cooked from https://stackoverflow.com/questions/175739/built-in-way-in-javascript-to-check-if-a-string-is-a-valid-number
const isNumeric = !isNaN(stringValue) && !isNaN(parseFloat(stringValue) && isFinite(stringValue));
// cooked from https://stackoverflow.com/questions/175739/built-in-way-in-javascript-to-check-if-a-string-is-a-valid-number
const isNumeric = !isNaN(stringValue) && !isNaN(parseFloat(stringValue) && isFinite(stringValue));
if (isNumeric) {
// detected numeric string. Coerce to a number
if (isNumeric) {
// detected numeric string. Coerce to a number
return +stringValue;
}
return +stringValue;
}
// the boolean literal case is easy.
if (stringValue === "true" ) {
return true;
}
// the boolean literal case is easy.
if (stringValue === 'true') {
return true;
}
if (stringValue === "false") {
return false;
}
if (stringValue === 'false') {
return false;
}
// otherwise, return this value as-is
return stringValue;
// otherwise, return this value as-is
return stringValue;
}
/**
@ -624,24 +624,24 @@ function lookupEnvironmentVariables(obj) {
* The isSettings variable only controls the error logging.
*/
function parseSettings(settingsFilename, isSettings) {
let settingsStr = "";
let settingsStr = '';
let settingsType, notFoundMessage, notFoundFunction;
if (isSettings) {
settingsType = "settings";
notFoundMessage = "Continuing using defaults!";
settingsType = 'settings';
notFoundMessage = 'Continuing using defaults!';
notFoundFunction = console.warn;
} else {
settingsType = "credentials";
notFoundMessage = "Ignoring.";
settingsType = 'credentials';
notFoundMessage = 'Ignoring.';
notFoundFunction = console.info;
}
try {
//read the settings file
// read the settings file
settingsStr = fs.readFileSync(settingsFilename).toString();
} catch(e) {
} catch (e) {
notFoundFunction(`No ${settingsType} file found in ${settingsFilename}. ${notFoundMessage}`);
// or maybe undefined!
@ -649,7 +649,7 @@ function parseSettings(settingsFilename, isSettings) {
}
try {
settingsStr = jsonminify(settingsStr).replace(",]","]").replace(",}","}");
settingsStr = jsonminify(settingsStr).replace(',]', ']').replace(',}', '}');
const settings = JSON.parse(settingsStr);
@ -658,7 +658,7 @@ function parseSettings(settingsFilename, isSettings) {
const replacedSettings = lookupEnvironmentVariables(settings);
return replacedSettings;
} catch(e) {
} catch (e) {
console.error(`There was an error processing your ${settingsType} file from ${settingsFilename}: ${e.message}`);
process.exit(1);
@ -667,55 +667,55 @@ function parseSettings(settingsFilename, isSettings) {
exports.reloadSettings = function reloadSettings() {
// Discover where the settings file lives
var settingsFilename = absolutePaths.makeAbsolute(argv.settings || "settings.json");
const settingsFilename = absolutePaths.makeAbsolute(argv.settings || 'settings.json');
// Discover if a credential file exists
var credentialsFilename = absolutePaths.makeAbsolute(argv.credentials || "credentials.json");
const credentialsFilename = absolutePaths.makeAbsolute(argv.credentials || 'credentials.json');
// try to parse the settings
var settings = parseSettings(settingsFilename, true);
const settings = parseSettings(settingsFilename, true);
// try to parse the credentials
var credentials = parseSettings(credentialsFilename, false);
const credentials = parseSettings(credentialsFilename, false);
storeSettings(settings);
storeSettings(credentials);
log4js.configure(exports.logconfig);//Configure the logging appenders
log4js.setGlobalLogLevel(exports.loglevel);//set loglevel
process.env['DEBUG'] = 'socket.io:' + exports.loglevel; // Used by SocketIO for Debug
log4js.configure(exports.logconfig);// Configure the logging appenders
log4js.setGlobalLogLevel(exports.loglevel);// set loglevel
process.env.DEBUG = `socket.io:${exports.loglevel}`; // Used by SocketIO for Debug
log4js.replaceConsole();
if (!exports.skinName) {
console.warn(`No "skinName" parameter found. Please check out settings.json.template and update your settings.json. Falling back to the default "colibris".`);
exports.skinName = "colibris";
console.warn('No "skinName" parameter found. Please check out settings.json.template and update your settings.json. Falling back to the default "colibris".');
exports.skinName = 'colibris';
}
// checks if skinName has an acceptable value, otherwise falls back to "colibris"
if (exports.skinName) {
const skinBasePath = path.join(exports.root, "src", "static", "skins");
const skinBasePath = path.join(exports.root, 'src', 'static', 'skins');
const countPieces = exports.skinName.split(path.sep).length;
if (countPieces != 1) {
console.error(`skinName must be the name of a directory under "${skinBasePath}". This is not valid: "${exports.skinName}". Falling back to the default "colibris".`);
exports.skinName = "colibris";
exports.skinName = 'colibris';
}
// informative variable, just for the log messages
var skinPath = path.normalize(path.join(skinBasePath, exports.skinName));
let skinPath = path.normalize(path.join(skinBasePath, exports.skinName));
// what if someone sets skinName == ".." or "."? We catch him!
if (absolutePaths.isSubdir(skinBasePath, skinPath) === false) {
console.error(`Skin path ${skinPath} must be a subdirectory of ${skinBasePath}. Falling back to the default "colibris".`);
exports.skinName = "colibris";
exports.skinName = 'colibris';
skinPath = path.join(skinBasePath, exports.skinName);
}
if (fs.existsSync(skinPath) === false) {
console.error(`Skin path ${skinPath} does not exist. Falling back to the default "colibris".`);
exports.skinName = "colibris";
exports.skinName = 'colibris';
skinPath = path.join(skinBasePath, exports.skinName);
}
@ -725,13 +725,13 @@ exports.reloadSettings = function reloadSettings() {
if (exports.abiword) {
// Check abiword actually exists
if (exports.abiword != null) {
fs.exists(exports.abiword, function(exists) {
fs.exists(exports.abiword, (exists) => {
if (!exists) {
var abiwordError = "Abiword does not exist at this path, check your settings file.";
const abiwordError = 'Abiword does not exist at this path, check your settings file.';
if (!exports.suppressErrorsInPadText) {
exports.defaultPadText = exports.defaultPadText + "\nError: " + abiwordError + suppressDisableMsg;
exports.defaultPadText = `${exports.defaultPadText}\nError: ${abiwordError}${suppressDisableMsg}`;
}
console.error(abiwordError + ` File location: ${exports.abiword}`);
console.error(`${abiwordError} File location: ${exports.abiword}`);
exports.abiword = null;
}
});
@ -739,46 +739,46 @@ exports.reloadSettings = function reloadSettings() {
}
if (exports.soffice) {
fs.exists(exports.soffice, function(exists) {
fs.exists(exports.soffice, (exists) => {
if (!exists) {
var sofficeError = "soffice (libreoffice) does not exist at this path, check your settings file.";
const sofficeError = 'soffice (libreoffice) does not exist at this path, check your settings file.';
if (!exports.suppressErrorsInPadText) {
exports.defaultPadText = exports.defaultPadText + "\nError: " + sofficeError + suppressDisableMsg;
exports.defaultPadText = `${exports.defaultPadText}\nError: ${sofficeError}${suppressDisableMsg}`;
}
console.error(sofficeError + ` File location: ${exports.soffice}`);
console.error(`${sofficeError} File location: ${exports.soffice}`);
exports.soffice = null;
}
});
}
if (!exports.sessionKey) {
var sessionkeyFilename = absolutePaths.makeAbsolute(argv.sessionkey || "./SESSIONKEY.txt");
const sessionkeyFilename = absolutePaths.makeAbsolute(argv.sessionkey || './SESSIONKEY.txt');
try {
exports.sessionKey = fs.readFileSync(sessionkeyFilename,"utf8");
exports.sessionKey = fs.readFileSync(sessionkeyFilename, 'utf8');
console.info(`Session key loaded from: ${sessionkeyFilename}`);
} catch(e) {
} catch (e) {
console.info(`Session key file "${sessionkeyFilename}" not found. Creating with random contents.`);
exports.sessionKey = randomString(32);
fs.writeFileSync(sessionkeyFilename,exports.sessionKey,"utf8");
fs.writeFileSync(sessionkeyFilename, exports.sessionKey, 'utf8');
}
} else {
console.warn("Declaring the sessionKey in the settings.json is deprecated. This value is auto-generated now. Please remove the setting from the file. -- If you are seeing this error after restarting using the Admin User Interface then you can ignore this message.");
console.warn('Declaring the sessionKey in the settings.json is deprecated. This value is auto-generated now. Please remove the setting from the file. -- If you are seeing this error after restarting using the Admin User Interface then you can ignore this message.');
}
if (exports.dbType === "dirty") {
var dirtyWarning = "DirtyDB is used. This is fine for testing but not recommended for production.";
if (exports.dbType === 'dirty') {
const dirtyWarning = 'DirtyDB is used. This is fine for testing but not recommended for production.';
if (!exports.suppressErrorsInPadText) {
exports.defaultPadText = exports.defaultPadText + "\nWarning: " + dirtyWarning + suppressDisableMsg;
exports.defaultPadText = `${exports.defaultPadText}\nWarning: ${dirtyWarning}${suppressDisableMsg}`;
}
exports.dbSettings.filename = absolutePaths.makeAbsolute(exports.dbSettings.filename);
console.warn(dirtyWarning + ` File location: ${exports.dbSettings.filename}`);
console.warn(`${dirtyWarning} File location: ${exports.dbSettings.filename}`);
}
if (exports.ip === "") {
if (exports.ip === '') {
// using Unix socket for connectivity
console.warn(`The settings file contains an empty string ("") for the "ip" parameter. The "port" parameter will be interpreted as the path to a Unix socket to bind at.`);
console.warn('The settings file contains an empty string ("") for the "ip" parameter. The "port" parameter will be interpreted as the path to a Unix socket to bind at.');
}
};