From 20a00481d6dfb0ce6cec998c059fa51f853e8eb8 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Mon, 7 Aug 2023 17:36:06 +0300 Subject: [PATCH] chore: server: lint --- server/markdown/index.js | 3 ++- server/prefixer.js | 4 +++- server/rest/index.js | 20 +++++++++----------- server/validate.js | 3 ++- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/server/markdown/index.js b/server/markdown/index.js index 1df05898..a1f45412 100644 --- a/server/markdown/index.js +++ b/server/markdown/index.js @@ -1,5 +1,6 @@ 'use strict'; +const isString = (a) => typeof a === 'string'; const {join} = require('path'); const {callbackify} = require('util'); @@ -56,7 +57,7 @@ async function onPUT(request) { } function check(name, request) { - if (typeof name !== 'string') + if (!isString(name)) throw Error('name should be string!'); if (!request) diff --git a/server/prefixer.js b/server/prefixer.js index 9cf65673..238d67fd 100644 --- a/server/prefixer.js +++ b/server/prefixer.js @@ -1,7 +1,9 @@ 'use strict'; +const isString = (a) => typeof a === 'string'; + module.exports = (value) => { - if (typeof value !== 'string') + if (!isString(value)) return ''; if (value.length === 1) diff --git a/server/rest/index.js b/server/rest/index.js index 91fb816d..ead6db24 100644 --- a/server/rest/index.js +++ b/server/rest/index.js @@ -1,5 +1,7 @@ 'use strict'; +const isFn = (a) => typeof a === 'function'; +const isString = (a) => typeof a === 'string'; const DIR = '../'; const DIR_COMMON = `${DIR}../common/`; @@ -148,7 +150,7 @@ function onGET(params, config, callback) { function getPackReg(packer) { if (packer === 'zip') return /\.zip$/; - + return /\.tar\.gz$/; } @@ -167,14 +169,11 @@ function streamPack(cmd, response, packer) { function getCMD(cmd) { if (cmd[0] === '/') return cmd.slice(1); - + return cmd; } -const getMoveMsg = (names) => { - const msg = formatMsg('move', names); - return msg; -}; +const getMoveMsg = (names) => formatMsg('move', names); const getRenameMsg = (from, to) => { const msg = formatMsg('rename', { @@ -376,9 +375,8 @@ module.exports._getWin32RootMsg = getWin32RootMsg; function getWin32RootMsg() { const message = 'Could not copy from/to root on windows!'; - const error = Error(message); - return error; + return Error(message); } function parseData(data) { @@ -398,12 +396,12 @@ function formatMsg(msg, data, status) { } function checkPut(name, body, callback) { - if (typeof name !== 'string') + if (!isString(name)) throw Error('name should be a string!'); - if (typeof body !== 'string') + if (!isString(body)) throw Error('body should be a string!'); - if (typeof callback !== 'function') + if (!isFn(callback)) throw Error('callback should be a function!'); } diff --git a/server/validate.js b/server/validate.js index 2154d561..8cb3283c 100644 --- a/server/validate.js +++ b/server/validate.js @@ -1,12 +1,13 @@ 'use strict'; +const isString = (a) => typeof a === 'string'; const tryCatch = require('try-catch'); const exit = require('./exit'); const columns = require('./columns'); module.exports.root = (dir, config) => { - if (typeof dir !== 'string') + if (!isString(dir)) throw Error('dir should be a string'); if (dir === '/')