diff --git a/.madrun.mjs b/.madrun.mjs index 582c19e2..e04604b7 100644 --- a/.madrun.mjs +++ b/.madrun.mjs @@ -23,7 +23,7 @@ export default { 'spell': () => 'yaspeller . || true', 'fix:lint': () => run('lint', '--fix'), 'lint:stream': () => run('lint', '-f stream'), - 'test': () => [testEnv, `tape 'test/**/*.js' '{client,static,common,server}/**/*.spec.js' -f fail`], + 'test': () => [testEnv, `tape --no-check-duplicates 'test/**/*.js' '{client,static,common,server}/**/*.spec.js' -f fail`], 'test:client': () => `tape 'test/client/**/*.js'`, 'test:server': () => `tape 'test/**/*.js' 'server/**/*.spec.js' 'common/**/*.spec.js'`, 'wisdom': () => run(['lint:all', 'build', 'test']), diff --git a/.putout.json b/.putout.json index eb480d3d..b7d0e6c8 100644 --- a/.putout.json +++ b/.putout.json @@ -34,7 +34,7 @@ "remove-console": "off" }, "storage.js": { - "remove-useless-async": "off" + "promises/remove-useless-async": "off" }, "docker.yml": { "github/set-node-versions": "off" diff --git a/client/dom/current-file.spec.js b/client/dom/current-file.spec.js index 513c3e43..c82afe04 100644 --- a/client/dom/current-file.spec.js +++ b/client/dom/current-file.spec.js @@ -150,7 +150,7 @@ test('current-file: isCurrentFile: no', (t) => { global.DOM = DOM; global.CloudCmd = CloudCmd; - t.equal(result, expect, 'should equal'); + t.equal(result, expect); t.end(); }); diff --git a/client/dom/dom-tree.js b/client/dom/dom-tree.js index 3bef0e4f..2927f97e 100644 --- a/client/dom/dom-tree.js +++ b/client/dom/dom-tree.js @@ -49,9 +49,7 @@ module.exports.getById = (id, element = document) => { * @param className - className * @param element - element */ -module.exports.getByClass = (className, element = document) => { - return DOM.getByClassAll(className, element)[0]; -}; +module.exports.getByClass = (className, element = document) => DOM.getByClassAll(className, element)[0]; module.exports.getByDataName = (attribute, element = document) => { const selector = '[' + 'data-name="' + attribute + '"]'; diff --git a/client/dom/events/event-store.js b/client/dom/events/event-store.js index 6d9273c0..ae08a7ee 100644 --- a/client/dom/events/event-store.js +++ b/client/dom/events/event-store.js @@ -14,7 +14,5 @@ module.exports.clear = () => { list = []; }; -module.exports.get = () => { - return list; -}; +module.exports.get = () => list; diff --git a/client/dom/files.js b/client/dom/files.js index 78425091..dce0ac39 100644 --- a/client/dom/files.js +++ b/client/dom/files.js @@ -19,12 +19,12 @@ const timeout = getTimeoutOnce(2000); module.exports.get = getFile; -async function getFile(name) { +function getFile(name) { const type = itype(name); check(name); if (type === 'string') - return await getModule(name); + return getModule(name); if (type === 'array') return Promise.all(name.map(getFile)); @@ -35,7 +35,7 @@ function check(name) { throw Error('name could not be empty!'); } -async function getModule(name) { +function getModule(name) { const regExpHTML = new RegExp(FILES_HTML + '|' + FILES_HTML_ROOT); const regExpJSON = new RegExp(FILES_JSON); @@ -73,7 +73,7 @@ function getPath(name, isHTML, isJSON) { function showError(name) { const str = 'Wrong file name: ' + name; - const error = new Error(str); + const error = Error(str); throw error; } diff --git a/client/dom/index.js b/client/dom/index.js index 38b6ddef..1473a02c 100644 --- a/client/dom/index.js +++ b/client/dom/index.js @@ -509,9 +509,7 @@ module.exports.saveDataToStorage = async (name, data, hash) => { return hash; }; -module.exports.getFM = () => { - return DOM.getPanel().parentElement; -}; +module.exports.getFM = () => DOM.getPanel().parentElement; module.exports.getPanelPosition = (panel) => { panel = panel || DOM.getPanel(); diff --git a/client/dom/io/send-request.spec.js b/client/dom/io/send-request.spec.js index bd14aa2e..077ba4c7 100644 --- a/client/dom/io/send-request.spec.js +++ b/client/dom/io/send-request.spec.js @@ -8,7 +8,7 @@ test('cloudcmd: client: io: replaceHash', (t) => { const result = _replaceHash(url); const expected = '/hello/%23%23%23%23world'; - t.equal(result, expected, 'should equal'); + t.equal(result, expected); t.end(); }); diff --git a/client/dom/load-remote.js b/client/dom/load-remote.js index b4e0aa22..eb295bb7 100644 --- a/client/dom/load-remote.js +++ b/client/dom/load-remote.js @@ -36,9 +36,7 @@ module.exports = (name, options, callback = options) => { local = [module.local]; } - const localURL = local.map((url) => { - return prefix + url; - }); + const localURL = local.map((url) => prefix + url); const remoteURL = remoteTmpls.map((tmpl) => { return rendy(tmpl, { diff --git a/client/key/vim/index.js b/client/key/vim/index.js index bc8e5b41..7b781057 100644 --- a/client/key/vim/index.js +++ b/client/key/vim/index.js @@ -14,57 +14,64 @@ module.exports = async (key, event) => { await vim(key, operations); }; -const getOperations = (event) => { - return { - escape: DOM.unselectFiles, - remove: () => { - CloudCmd.Operation.show('delete'); - }, - copy: () => { - DOM.Buffer.copy(); - DOM.unselectFiles(); - }, - select: () => { - const current = Info.element; - DOM.toggleSelectedFile(current); - }, - paste: DOM.Buffer.paste, - moveNext: ({count, isVisual, isDelete}) => { - setCurrent('next', { - count, - isVisual, - isDelete, - }); - }, - movePrevious: ({count, isVisual, isDelete}) => { - setCurrent('previous', { - count, - isVisual, - isDelete, - }); - }, - find: async () => { - event.preventDefault(); - const [, value] = await Dialog.prompt('Find', ''); - - if (!value) - return; - - const names = Info.files.map(DOM.getCurrentName); - const [result] = finder.find(value, names); - - DOM.setCurrentByName(result); - }, - findNext: () => { - const name = finder.findNext(); - DOM.setCurrentByName(name); - }, - findPrevious: () => { - const name = finder.findPrevious(); - DOM.setCurrentByName(name); - }, - }; -}; +const getOperations = (event) => ({ + escape: DOM.unselectFiles, + + remove: () => { + CloudCmd.Operation.show('delete'); + }, + + copy: () => { + DOM.Buffer.copy(); + DOM.unselectFiles(); + }, + + select: () => { + const current = Info.element; + DOM.toggleSelectedFile(current); + }, + + paste: DOM.Buffer.paste, + + moveNext: ({count, isVisual, isDelete}) => { + setCurrent('next', { + count, + isVisual, + isDelete, + }); + }, + + movePrevious: ({count, isVisual, isDelete}) => { + setCurrent('previous', { + count, + isVisual, + isDelete, + }); + }, + + find: async () => { + event.preventDefault(); + const [, value] = await Dialog.prompt('Find', ''); + + if (!value) + return; + + const names = Info.files.map(DOM.getCurrentName); + const [result] = finder.find(value, names); + + DOM.setCurrentByName(result); + }, + + findNext: () => { + const name = finder.findNext(); + DOM.setCurrentByName(name); + }, + + findPrevious: () => { + const name = finder.findPrevious(); + DOM.setCurrentByName(name); + }, +}); module.exports.selectFile = selectFile; diff --git a/client/modules/cloud.js b/client/modules/cloud.js index 59c203c9..4d6e4bd0 100644 --- a/client/modules/cloud.js +++ b/client/modules/cloud.js @@ -56,7 +56,7 @@ function _upload(callback, file) { }); } -async function loadFiles() { +function loadFiles() { const js = '//api.filepicker.io/v2/filepicker.js'; return Promise.all([ diff --git a/client/modules/config/input.js b/client/modules/config/input.js index f140fa60..3929154f 100644 --- a/client/modules/config/input.js +++ b/client/modules/config/input.js @@ -2,9 +2,7 @@ const currify = require('currify'); -const isType = currify((type, object, name) => { - return typeof object[name] === type; -}); +const isType = currify((type, object, name) => typeof object[name] === type); const isBool = isType('boolean'); diff --git a/client/modules/edit.js b/client/modules/edit.js index 151b3f5d..5676034c 100644 --- a/client/modules/edit.js +++ b/client/modules/edit.js @@ -96,9 +96,7 @@ function getEditor() { return editor; } -module.exports.getElement = () => { - return Element; -}; +module.exports.getElement = () => Element; module.exports.hide = () => { CloudCmd.View.hide(); diff --git a/client/modules/konsole.js b/client/modules/konsole.js index 867bf8b2..df143e8d 100644 --- a/client/modules/konsole.js +++ b/client/modules/konsole.js @@ -63,9 +63,7 @@ function getEnv() { ACTIVE_DIR: DOM.getCurrentDirPath.bind(DOM), PASSIVE_DIR: DOM.getNotCurrentDirPath.bind(DOM), CURRENT_NAME: DOM.getCurrentName.bind(DOM), - CURRENT_PATH: () => { - return Info.path; - }, + CURRENT_PATH: () => Info.path, }; } diff --git a/client/modules/operation/index.js b/client/modules/operation/index.js index 2a308abb..275939bd 100644 --- a/client/modules/operation/index.js +++ b/client/modules/operation/index.js @@ -269,9 +269,7 @@ async function promptDelete() { } else { const current = DOM.getCurrentFile(); const isDir = DOM.isCurrentIsDir(current); - const getType = (isDir) => { - return isDir ? 'directory' : 'file'; - }; + const getType = (isDir) => isDir ? 'directory' : 'file'; const type = getType(isDir) + ' '; @@ -369,7 +367,7 @@ async function _processFiles(options, data) { const operation = isCopy ? copyFn : moveFn; if (shouldAsk && config(option)) { - const [cancel, newTo] = await prompt(title, to, names.map(encode)); + const [cancel, newTo] = prompt(title, to, names.map(encode)); if (!cancel) ask(newTo); @@ -485,7 +483,7 @@ function twopack(operation, type) { }); } -async function prompt(msg, to, names) { +function prompt(msg, to, names) { const n = names.length; const [name] = names; diff --git a/client/modules/user-menu/get-user-menu.spec.js b/client/modules/user-menu/get-user-menu.spec.js index 5da03054..911a5e14 100644 --- a/client/modules/user-menu/get-user-menu.spec.js +++ b/client/modules/user-menu/get-user-menu.spec.js @@ -15,7 +15,7 @@ test('user-menu: getUserMenu', (t) => { const [key] = Object.keys(result); - t.equal(key, 'F2 - Rename file', 'should equal'); + t.equal(key, 'F2 - Rename file'); t.end(); }); diff --git a/client/modules/view/index.js b/client/modules/view/index.js index 26426429..44fb3384 100644 --- a/client/modules/view/index.js +++ b/client/modules/view/index.js @@ -247,12 +247,10 @@ function hide() { function viewImage(path, prefixURL) { const isSupportedImage = (a) => isImage(a) || a === path; - const makeTitle = (path) => { - return { - href: `${prefixURL}${path}`, - title: encode(basename(path)), - }; - }; + const makeTitle = (path) => ({ + href: `${prefixURL}${path}`, + title: encode(basename(path)), + }); const names = Info.files .map(DOM.getCurrentPath) diff --git a/client/modules/view/index.spec.js b/client/modules/view/index.spec.js index 209ed234..3d2c3ee7 100644 --- a/client/modules/view/index.spec.js +++ b/client/modules/view/index.spec.js @@ -49,7 +49,7 @@ test('cloudcmd: client: view: initConfig: no options', (t) => { global.CloudCmd = CloudCmd; global.DOM = DOM; - t.equal(typeof config, 'object', 'should equal'); + t.equal(typeof config, 'object'); t.end(); }); diff --git a/common/callbackify.js b/common/callbackify.js index f661eed7..a8657480 100644 --- a/common/callbackify.js +++ b/common/callbackify.js @@ -2,13 +2,11 @@ const success = (f) => (data) => f(null, data); -module.exports = (promise) => { - return (...a) => { - const fn = a.pop(); - - promise(...a) - .then(success(fn)) - .catch(fn); - }; +module.exports = (promise) => (...a) => { + const fn = a.pop(); + + promise(...a) + .then(success(fn)) + .catch(fn); }; diff --git a/common/callbackify.spec.js b/common/callbackify.spec.js index 0b7f6d8c..9558dfcb 100644 --- a/common/callbackify.spec.js +++ b/common/callbackify.spec.js @@ -1,31 +1,32 @@ 'use strict'; -const test = require('supertape'); +const tryToCatch = require('try-to-catch'); + +const { + test, + stub, +} = require('supertape'); const callbackify = require('./callbackify'); +const {promisify} = require('util'); -test('cloudcmd: common: callbackify: error', (t) => { - const promise = async () => { - throw Error('hello'); - }; +test('cloudcmd: common: callbackify: error', async (t) => { + const promise = stub().rejects(Error('hello')); const fn = callbackify(promise); + const [error] = await tryToCatch(promisify(fn)); - fn((e) => { - t.equal(e.message, 'hello'); - t.end(); - }); + t.equal(error.message, 'hello'); + t.end(); }); -test('cloudcmd: common: callbackify', (t) => { - const promise = async () => { - return 'hi'; - }; +test('cloudcmd: common: callbackify', async (t) => { + const promise = stub().resolves('hi'); const fn = callbackify(promise); + const promiseAgain = promisify(fn); + const data = await promiseAgain(); - fn((e, data) => { - t.equal(data, 'hi'); - t.end(); - }); + t.equal(data, 'hi'); + t.end(); }); diff --git a/common/cloudfunc.spec.js b/common/cloudfunc.spec.js index 8d14b89a..b77dfd8f 100644 --- a/common/cloudfunc.spec.js +++ b/common/cloudfunc.spec.js @@ -92,7 +92,7 @@ test('cloudfunc: getSize: dir', (t) => { const expected = '<dir>'; - t.equal(result, expected, 'should equal'); + t.equal(result, expected); t.end(); }); @@ -106,7 +106,7 @@ test('cloudfunc: getSize: link: dir', (t) => { const expected = '<link>'; - t.equal(result, expected, 'should equal'); + t.equal(result, expected); t.end(); }); @@ -120,7 +120,7 @@ test('cloudfunc: getSize: link: file', (t) => { const expected = '<link>'; - t.equal(result, expected, 'should equal'); + t.equal(result, expected); t.end(); }); @@ -134,6 +134,6 @@ test('cloudfunc: getSize: file', (t) => { const expected = '100.00kb'; - t.equal(result, expected, 'should equal'); + t.equal(result, expected); t.end(); }); diff --git a/common/datetime.spec.js b/common/datetime.spec.js index cc2aed16..2919c87e 100644 --- a/common/datetime.spec.js +++ b/common/datetime.spec.js @@ -11,7 +11,7 @@ test('common: datetime', (t) => { const expected = '2018.08.17 10:56:48'; - t.equal(result, expected, 'should equal'); + t.equal(result, expected); t.end(); }); @@ -41,7 +41,7 @@ test('common: 0 before number', (t) => { const expected = '2018.08.17 10:56:08'; - t.equal(result, expected, 'should equal'); + t.equal(result, expected); t.end(); }); diff --git a/common/util.spec.js b/common/util.spec.js index cb84f18d..36ee25d3 100644 --- a/common/util.spec.js +++ b/common/util.spec.js @@ -113,12 +113,12 @@ test('util: getRegExp: no', (t) => { }); test('util: escapeRegExp: no str', (t) => { - t.equal(escapeRegExp(1), 1, 'should equal'); + t.equal(escapeRegExp(1), 1); t.end(); }); test('util: escapeRegExp', (t) => { - t.equal(escapeRegExp('#hello'), '\\#hello', 'should equal'); + t.equal(escapeRegExp('#hello'), '\\#hello'); t.end(); }); diff --git a/server/cloudcmd.spec.js b/server/cloudcmd.spec.js index ae4208db..32d6db24 100644 --- a/server/cloudcmd.spec.js +++ b/server/cloudcmd.spec.js @@ -52,7 +52,7 @@ test('cloudcmd: getPrefix', (t) => { const value = 'hello'; const result = _getPrefix(value); - t.equal(result, value, 'should equal'); + t.equal(result, value); t.end(); }); @@ -61,7 +61,7 @@ test('cloudcmd: getPrefix: function', (t) => { const fn = () => value; const result = _getPrefix(fn); - t.equal(result, value, 'should equal'); + t.equal(result, value); t.end(); }); @@ -70,7 +70,7 @@ test('cloudcmd: getPrefix: function: empty', (t) => { const fn = () => value; const result = _getPrefix(fn); - t.equal(result, '', 'should equal'); + t.equal(result, ''); t.end(); }); @@ -86,7 +86,7 @@ test('cloudcmd: replaceDist', (t) => { process.env.NODE_ENV = NODE_ENV; - t.equal(result, expected, 'should equal'); + t.equal(result, expected); t.end(); }); @@ -100,7 +100,7 @@ test('cloudcmd: replaceDist: !isDev', (t) => { reset(); - t.equal(result, url, 'should equal'); + t.equal(result, url); t.end(); }); diff --git a/server/config.js b/server/config.js index 759ffbd8..75d6c5a3 100644 --- a/server/config.js +++ b/server/config.js @@ -114,7 +114,7 @@ function createConfig({configPath} = {}) { return configManager; } -const write = async (filename, config) => { +const write = (filename, config) => { return writejson(filename, config('*'), {mode: 0o600}); }; diff --git a/server/distribute/import.spec.js b/server/distribute/import.spec.js index 2ec2fce0..8467d147 100644 --- a/server/distribute/import.spec.js +++ b/server/distribute/import.spec.js @@ -29,7 +29,7 @@ test('distribute: import: canceled', async (t) => { await done(); - t.equal(status, 'canceled', 'should equal'); + t.equal(status, 'canceled'); t.end(); }); @@ -73,7 +73,7 @@ test('distribute: import: received', async (t) => { const {status} = await distribute.import(configManager); await done(); - t.equal(status, 'received', 'should equal'); + t.equal(status, 'received'); t.end(); }); @@ -97,7 +97,7 @@ test('distribute: import: received: auth: reject', async (t) => { const {status} = await distribute.import(configManager); await done(); - t.equal(status, 'reject', 'should equal'); + t.equal(status, 'reject'); t.end(); }); @@ -121,7 +121,7 @@ test('distribute: import: received: auth: accept', async (t) => { const {status} = await distribute.import(configManager); await done(); - t.equal(status, 'received', 'should equal'); + t.equal(status, 'received'); t.end(); }); @@ -143,7 +143,7 @@ test('distribute: import: received: no name', async (t) => { const {status} = await distribute.import(configManager); await done(); - t.equal(status, 'received', 'should equal'); + t.equal(status, 'received'); t.end(); }); @@ -167,7 +167,7 @@ test('distribute: import: error', async (t) => { await done(); - t.equal(status, 'connect_error', 'should equal'); + t.equal(status, 'connect_error'); t.end(); }); @@ -189,7 +189,7 @@ test('distribute: import: config:change: no export', async (t) => { await done(); - t.equal(status, 'connect_error', 'should equal'); + t.equal(status, 'connect_error'); t.end(); }); diff --git a/server/distribute/log.js b/server/distribute/log.js index 6a37de50..dc0a48f2 100644 --- a/server/distribute/log.js +++ b/server/distribute/log.js @@ -32,9 +32,7 @@ function stringToRGB(a) { ]; } -const add = (a, b) => { - return a + b.charCodeAt(0); -}; +const add = (a, b) => a + b.charCodeAt(0); function crc(a) { return a diff --git a/server/distribute/log.spec.js b/server/distribute/log.spec.js index 83c7a963..1078c82a 100644 --- a/server/distribute/log.spec.js +++ b/server/distribute/log.spec.js @@ -8,7 +8,7 @@ test('distribute: log: getMessage', (t) => { const e = 'hello'; const result = log.getMessage(e); - t.equal(e, result, 'should equal'); + t.equal(e, result); t.end(); }); @@ -18,7 +18,7 @@ test('distribute: log: getMessage: message', (t) => { message, }); - t.equal(result, message, 'should equal'); + t.equal(result, message); t.end(); }); diff --git a/server/show-config.js b/server/show-config.js index c7ee2dec..4591d068 100644 --- a/server/show-config.js +++ b/server/show-config.js @@ -8,9 +8,7 @@ const { module.exports = (config) => { check(config); - const data = Object.keys(config).map((name) => { - return [name, config[name]]; - }); + const data = Object.keys(config).map((name) => [name, config[name]]); if (!data.length) return ''; diff --git a/server/terminal.spec.js b/server/terminal.spec.js index 863f4b48..2a20f6cb 100644 --- a/server/terminal.spec.js +++ b/server/terminal.spec.js @@ -74,7 +74,7 @@ test('cloudcmd: terminal: no arg', (t) => { mockRequire.stop('gritty'); - t.equal(result, gritty, 'should equal'); + t.equal(result, gritty); t.end(); }); diff --git a/server/user-menu.spec.js b/server/user-menu.spec.js index eba01007..623dcfa7 100644 --- a/server/user-menu.spec.js +++ b/server/user-menu.spec.js @@ -39,7 +39,7 @@ test('cloudcmd: user menu', async (t) => { threadIt.terminate(); - t.equal(userMenuFile, body, 'should equal'); + t.equal(userMenuFile, body); t.end(); }); @@ -61,7 +61,7 @@ test('cloudcmd: user menu: io.mv', async (t) => { threadIt.terminate(); fs.promises.readFile = readFile; - t.equal(fixtureMoveFix, body, 'should equal'); + t.equal(fixtureMoveFix, body); t.end(); }); @@ -83,7 +83,7 @@ test('cloudcmd: user menu: io.cp', async (t) => { threadIt.terminate(); fs.promises.readFile = readFile; - t.equal(fixtureCopyFix, body, 'should equal'); + t.equal(fixtureCopyFix, body); t.end(); }); diff --git a/test/server/columns.js b/test/server/columns.js index 9ccb0e66..c57705d7 100644 --- a/test/server/columns.js +++ b/test/server/columns.js @@ -12,7 +12,7 @@ test('columns', (t) => { process.env.NODE_ENV = NODE_ENV; - t.equal(columns[''], '', 'should equal'); + t.equal(columns[''], ''); t.end(); }); @@ -25,7 +25,7 @@ test('columns: dev', (t) => { process.env.NODE_ENV = NODE_ENV; - t.equal(columns['name-size-date'], css, 'should equal'); + t.equal(columns['name-size-date'], css); t.end(); }); diff --git a/test/server/env.js b/test/server/env.js index 0c0d9089..c745428a 100644 --- a/test/server/env.js +++ b/test/server/env.js @@ -40,7 +40,7 @@ test('env: bool: undefined', (t) => { const {cloudcmd_terminal} = process.env; process.env.cloudcmd_terminal = undefined; - t.equal(env.bool('terminal'), undefined, 'should be undefined'); + t.notOk(env.bool('terminal'), 'should be undefined'); process.env.cloudcmd_terminal = cloudcmd_terminal; t.end();