chore(cloudcmd) lint

This commit is contained in:
coderaiser 2021-09-30 17:22:59 +03:00
parent 8f466b4c9a
commit 111eba8c31
33 changed files with 139 additions and 155 deletions

View file

@ -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']),

View file

@ -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"

View file

@ -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();
});

View file

@ -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 + '"]';

View file

@ -14,7 +14,5 @@ module.exports.clear = () => {
list = [];
};
module.exports.get = () => {
return list;
};
module.exports.get = () => list;

View file

@ -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;
}

View file

@ -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();

View file

@ -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();
});

View file

@ -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, {

View file

@ -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;

View file

@ -56,7 +56,7 @@ function _upload(callback, file) {
});
}
async function loadFiles() {
function loadFiles() {
const js = '//api.filepicker.io/v2/filepicker.js';
return Promise.all([

View file

@ -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');

View file

@ -96,9 +96,7 @@ function getEditor() {
return editor;
}
module.exports.getElement = () => {
return Element;
};
module.exports.getElement = () => Element;
module.exports.hide = () => {
CloudCmd.View.hide();

View file

@ -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,
};
}

View file

@ -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;

View file

@ -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();
});

View file

@ -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)

View file

@ -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();
});

View file

@ -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);
};

View file

@ -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();
});

View file

@ -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();
});

View file

@ -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();
});

View file

@ -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();
});

View file

@ -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();
});

View file

@ -114,7 +114,7 @@ function createConfig({configPath} = {}) {
return configManager;
}
const write = async (filename, config) => {
const write = (filename, config) => {
return writejson(filename, config('*'), {mode: 0o600});
};

View file

@ -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();
});

View file

@ -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

View file

@ -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();
});

View file

@ -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 '';

View file

@ -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();
});

View file

@ -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();
});

View file

@ -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();
});

View file

@ -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();