lint: src/node/utils/AbsolutePaths.js

This commit is contained in:
John McLear 2021-01-21 21:06:52 +00:00 committed by Richard Hansen
parent 7afc809073
commit 60bc849be2

View file

@ -1,3 +1,4 @@
'use strict';
/**
* Library for deterministic relative filename expansion for Etherpad.
*/
@ -40,7 +41,7 @@ let etherpadRoot = null;
* @return {string[]|boolean} The shortened array, or false if there was no
* overlap.
*/
const popIfEndsWith = function (stringArray, lastDesiredElements) {
const popIfEndsWith = (stringArray, lastDesiredElements) => {
if (stringArray.length <= lastDesiredElements.length) {
absPathLogger.debug(`In order to pop "${lastDesiredElements.join(path.sep)}" from "${stringArray.join(path.sep)}", it should contain at least ${lastDesiredElements.length + 1} elements`);
@ -72,8 +73,8 @@ const popIfEndsWith = function (stringArray, lastDesiredElements) {
* @return {string} The identified absolute base path. If such path cannot be
* identified, prints a log and exits the application.
*/
exports.findEtherpadRoot = function () {
if (etherpadRoot !== null) {
exports.findEtherpadRoot = () => {
if (etherpadRoot != null) {
return etherpadRoot;
}
@ -126,7 +127,7 @@ exports.findEtherpadRoot = function () {
* it is returned unchanged. Otherwise it is interpreted
* relative to exports.root.
*/
exports.makeAbsolute = function (somePath) {
exports.makeAbsolute = (somePath) => {
if (path.isAbsolute(somePath)) {
return somePath;
}
@ -145,7 +146,7 @@ exports.makeAbsolute = function (somePath) {
* a subdirectory of the base one
* @return {boolean}
*/
exports.isSubdir = function (parent, arbitraryDir) {
exports.isSubdir = (parent, arbitraryDir) => {
// modified from: https://stackoverflow.com/questions/37521893/determine-if-a-path-is-subdirectory-of-another-in-node-js#45242825
const relative = path.relative(parent, arbitraryDir);
const isSubdir = !!relative && !relative.startsWith('..') && !path.isAbsolute(relative);