From 794caced01feed9998cbbe67f320d021de7a7948 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Sat, 28 Sep 2019 16:42:30 +0300 Subject: [PATCH] chore(cloudcmd) lint --- .putout.json | 7 +++++++ .webpack/js.js | 4 ++-- client/client.js | 16 ++++++++-------- client/dom/buffer.js | 2 +- client/dom/directory.js | 2 +- client/dom/files.js | 2 +- client/dom/index.js | 16 ++++++++-------- client/dom/upload-files.js | 2 +- client/key/vim/globals.fixture.js | 4 ++-- client/listeners/index.js | 2 +- client/modules/config/index.js | 2 +- server/cloudcmd.js | 4 ++-- server/route.js | 4 ++-- server/user-menu.js | 6 +++--- test/common/cloudfunc.js | 4 ++-- 15 files changed, 42 insertions(+), 35 deletions(-) diff --git a/.putout.json b/.putout.json index 598adc3336..e8ed3cf0b5 100644 --- a/.putout.json +++ b/.putout.json @@ -13,6 +13,13 @@ "client/(client|cloudcmd|load-module).js": { "remove-console": false }, + "client/modules/config/index.js": { + "apply-shorthand-properties": [{ + "ignore": [ + "ONE_MINUTE" + ] + }] + }, "test/common/cloudfunc.js": { "remove-console": false } diff --git a/.webpack/js.js b/.webpack/js.js index a3ef66bafe..8f32f4bd5c 100644 --- a/.webpack/js.js +++ b/.webpack/js.js @@ -28,7 +28,7 @@ const clean = (array) => array.filter(notEmpty); const noParse = (a) => /\.spec\.js$/.test(a); -const babelDev = { +const options = { babelrc: false, plugins: [ 'module:babel-plugin-macros', @@ -45,7 +45,7 @@ const rules = clean([ test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader', - options: babelDev, + options, }]); const plugins = [ diff --git a/client/client.js b/client/client.js index 80c61d4a62..506240d6e3 100644 --- a/client/client.js +++ b/client/client.js @@ -352,7 +352,7 @@ function CloudCmdProto(DOM) { const {noCurrent} = options; if (!isRefresh && json) - return createFileTable(json, panel, options, callback); + return await createFileTable(json, panel, options, callback); const position = DOM.getPanelPosition(panel); const sort = CloudCmd.sort[position]; @@ -403,7 +403,7 @@ function CloudCmdProto(DOM) { * @param history * @param callback */ - async function createFileTable(json, panelParam, options) { + async function createFileTable(data, panelParam, options) { const { history, noCurrent, @@ -413,7 +413,7 @@ function CloudCmdProto(DOM) { const [ error, - [templFile, templPath, templLink, templPathLink], + [file, path, link, pathLink], ] = await tryToCatch(Files.get, names); if (error) @@ -436,14 +436,14 @@ function CloudCmdProto(DOM) { panel.innerHTML = buildFromJSON({ sort : options.sort, order : options.order, - data : json, + data, id : panel.id, prefix, template : { - file : templFile, - path : templPath, - pathLink : templPathLink, - link : templLink, + file, + path, + pathLink, + link, }, }); diff --git a/client/dom/buffer.js b/client/dom/buffer.js index f3df5981ff..3569ebebff 100644 --- a/client/dom/buffer.js +++ b/client/dom/buffer.js @@ -42,7 +42,7 @@ function BufferProto() { function rmCutClass() { const files = DOM.getByClassAll(CLASS); - for (const element of [...files]) { + for (const element of files) { element.classList.remove(CLASS); } } diff --git a/client/dom/directory.js b/client/dom/directory.js index 3d0461db39..3029dfd2d0 100644 --- a/client/dom/directory.js +++ b/client/dom/directory.js @@ -16,7 +16,7 @@ module.exports = (items) => { if (items.length) Images.show('top'); - const entries = [...items].map((item) => { + const entries = Array.from(items).map((item) => { return item.webkitGetAsEntry(); }); diff --git a/client/dom/files.js b/client/dom/files.js index 7955b1284d..8133c11d50 100644 --- a/client/dom/files.js +++ b/client/dom/files.js @@ -28,7 +28,7 @@ async function getFile(name) { check(name); if (type === 'string') - return getModule(name); + return await getModule(name); if (type === 'array') return Promise.all(unaryMap(name, get)); diff --git a/client/dom/index.js b/client/dom/index.js index 9b9880a30d..f50c6d26f4 100644 --- a/client/dom/index.js +++ b/client/dom/index.js @@ -173,7 +173,7 @@ function CmdProto() { const panel = DOM.getPanel(); const selected = DOM.getByClassAll(SELECTED_FILE, panel); - return [...selected]; + return Array.from(selected); }; /* @@ -182,7 +182,7 @@ function CmdProto() { this.unselectFiles = (files) => { files = files || DOM.getSelectedFiles(); - [...files].forEach(DOM.toggleSelectedFile); + Array.from(files).forEach(DOM.toggleSelectedFile); }; /** @@ -412,7 +412,7 @@ function CmdProto() { const from = (a) => a === '..' ? 1 : 0; const i = from(name); - return [...files].slice(i); + return Array.from(files).slice(i); }; /** @@ -496,7 +496,7 @@ function CmdProto() { const first = files[0] || DOM.getCurrentFile(); const name = DOM.getCurrentName(first); - const allFiles = [...files]; + const allFiles = Array.from(files); if (name === '..') allFiles.shift(); @@ -852,13 +852,13 @@ function CmdProto() { panelPassive, } = Info; - const dirPath = DOM.getCurrentDirPath(); + const path = DOM.getCurrentDirPath(); const dirPathPassive = DOM.getNotCurrentDirPath(); let currentIndex = files.indexOf(element); CloudCmd.loadDir({ - path: dirPath, + path, panel: panelPassive, noCurrent: true, }); @@ -901,8 +901,8 @@ function CmdProto() { info.parentDirPath = DOM.getParentDirPath(); info.element = current; info.ext = Util.getExt(name); - info.files = [...files.children]; - info.filesPassive = [...filesPassive]; + info.files = Array.from(files.children); + info.filesPassive = Array.from(filesPassive); info.first = files.firstChild; info.getData = DOM.getCurrentData; info.last = files.lastChild; diff --git a/client/dom/upload-files.js b/client/dom/upload-files.js index 414be5781b..8b0e8b7a3e 100644 --- a/client/dom/upload-files.js +++ b/client/dom/upload-files.js @@ -27,7 +27,7 @@ module.exports = (dir, files) => { if (!n) return; - const array = [...files]; + const array = Array.from(files); const {name} = files[0]; eachSeries(array, loadFile(dir, n), onEnd(name)); diff --git a/client/key/vim/globals.fixture.js b/client/key/vim/globals.fixture.js index 2fa928a79e..b21348438d 100644 --- a/client/key/vim/globals.fixture.js +++ b/client/key/vim/globals.fixture.js @@ -1,7 +1,7 @@ 'use strict'; module.exports.getDOM = () => { - const resolve = Promise.resolve.bind(Promise); + const prompt = Promise.resolve.bind(Promise); const CurrentInfo = { element: {}, files: [], @@ -14,7 +14,7 @@ module.exports.getDOM = () => { }; const Dialog = { - prompt: resolve, + prompt, }; return { diff --git a/client/listeners/index.js b/client/listeners/index.js index a82b8a2090..4ac8b39c34 100644 --- a/client/listeners/index.js +++ b/client/listeners/index.js @@ -424,7 +424,7 @@ function dragndrop() { return uploadFiles(files); const isFile = (item) => item.kind === 'file'; - const dirFiles = [...items].filter(isFile); + const dirFiles = Array.from(items).filter(isFile); if (dirFiles.length) return DOM.uploadDirectory(dirFiles); diff --git a/client/modules/config/index.js b/client/modules/config/index.js index 014ea2fed6..61cb3eaabe 100644 --- a/client/modules/config/index.js +++ b/client/modules/config/index.js @@ -173,7 +173,7 @@ async function fillTemplate() { const getTarget = ({target}) => target; const handleChange = squad(onChange, getTarget); - [...inputs] + Array.from(inputs) .map(addKey(onKey)) .map(addChange(handleChange)); diff --git a/server/cloudcmd.js b/server/cloudcmd.js index a212556dd0..97120aa046 100644 --- a/server/cloudcmd.js +++ b/server/cloudcmd.js @@ -39,7 +39,7 @@ const isDev = process.env.NODE_ENV === 'development'; const getDist = (isDev) => isDev ? 'dist-dev' : 'dist'; const getIndexPath = (isDev) => path.join(DIR, '..', `${getDist(isDev)}/index.html`); -const defaultHtml = fs.readFileSync(getIndexPath(isDev), 'utf8'); +const html = fs.readFileSync(getIndexPath(isDev), 'utf8'); const initAuth = currify(_initAuth); const notEmpty = (a) => a; @@ -249,7 +249,7 @@ function cloudcmd({modules, config}) { rest(config), route(config, { - html: defaultHtml, + html, }), ponseStatic, diff --git a/server/route.js b/server/route.js index 7429eb007d..79adfb5b5f 100644 --- a/server/route.js +++ b/server/route.js @@ -169,9 +169,9 @@ function indexProcessing(config, options) { return data; } -function buildIndex(config, html, json) { +function buildIndex(config, html, data) { const panel = CloudFunc.buildFromJSON({ - data: json, + data, prefix: getPrefix(config), template: Template, }); diff --git a/server/user-menu.js b/server/user-menu.js index eff58fd208..b5a0efeff3 100644 --- a/server/user-menu.js +++ b/server/user-menu.js @@ -27,7 +27,7 @@ module.exports = currify(async({menuName}, req, res, next) => { const {method} = req; if (method === 'GET') - return onGET({ + return await onGET({ req, res, menuName, @@ -76,10 +76,10 @@ async function onGET({req, res, menuName}) { .send(result.code); } -function getError(parseError, source) { +function getError(error, source) { return ` const e = Error(\`
${codeframe({
-        error: parseError,
+        error,
         source,
         highlightCode: false,
     })}
\`); diff --git a/test/common/cloudfunc.js b/test/common/cloudfunc.js index 94750b8edc..49c95492d3 100644 --- a/test/common/cloudfunc.js +++ b/test/common/cloudfunc.js @@ -32,7 +32,7 @@ const TMPL = [ 'link', ].map(addHBS); -const JSON_FILES = { +const data = { path : '/etc/X11/', files : [{ name: 'applnk', @@ -73,7 +73,7 @@ test('cloudfunc: render', (t) => { time('CloudFunc.buildFromJSON'); const result = CloudFunc.buildFromJSON({ prefix : '', - data : JSON_FILES, + data, template, });