From 8bb746aa0e4e56293e088d74c4ec19a1897b4281 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Sat, 6 Jun 2020 19:20:17 +0300 Subject: [PATCH] chore(cloudcmd) lint: indexOf -> includes --- client/dom/files.js | 12 ++++-------- client/dom/load.js | 4 ++-- client/key/index.js | 2 +- client/modules/edit-file.js | 4 +--- client/modules/edit-names.js | 4 +--- client/modules/operation/index.js | 8 ++------ client/modules/view.js | 4 ++-- server/route.spec.js | 2 +- 8 files changed, 14 insertions(+), 26 deletions(-) diff --git a/client/dom/files.js b/client/dom/files.js index 8133c11d..78425091 100644 --- a/client/dom/files.js +++ b/client/dom/files.js @@ -1,9 +1,8 @@ -/* global CloudCmd */ - 'use strict'; +/* global CloudCmd */ + const itype = require('itype'); -const currify = require('currify'); const {promisify} = require('es6-promisify'); const load = require('./load'); @@ -18,10 +17,7 @@ const DIR_HTML_FS = DIR_HTML + 'fs/'; const DIR_JSON = '/json/'; const timeout = getTimeoutOnce(2000); -const get = currify(getFile); -const unaryMap = (array, fn) => array.map((a) => fn(a)); - -module.exports.get = get; +module.exports.get = getFile; async function getFile(name) { const type = itype(name); @@ -31,7 +27,7 @@ async function getFile(name) { return await getModule(name); if (type === 'array') - return Promise.all(unaryMap(name, get)); + return Promise.all(name.map(getFile)); } function check(name) { diff --git a/client/dom/load.js b/client/dom/load.js index 9ba976fc..8292909d 100644 --- a/client/dom/load.js +++ b/client/dom/load.js @@ -20,7 +20,7 @@ function getIdBySrc(src) { if (!isStr) return; - if (~src.indexOf(':')) + if (src.includes(':')) src += '-join'; const num = src.lastIndexOf('/') + 1; @@ -81,7 +81,7 @@ module.exports.ajax = (params) => { return exec(p.error, xhr); const notText = p.dataType !== 'text'; - const isContain = ~type.indexOf(TYPE_JSON); + const isContain = type.includes(TYPE_JSON); let data = xhr.response; diff --git a/client/key/index.js b/client/key/index.js index d3578e30..42c1b671 100644 --- a/client/key/index.js +++ b/client/key/index.js @@ -71,7 +71,7 @@ function KeyProto() { const isNumpad = /Numpad/.test(event.code); let char = getChar(event); - let isSymbol = ~['.', '_', '-', '+', '='].indexOf(char); + let isSymbol = ['.', '_', '-', '+', '='].includes(char); if (!isSymbol) { isSymbol = getSymbol(shift, keyCode); diff --git a/client/modules/edit-file.js b/client/modules/edit-file.js index f9b29041..361173be 100644 --- a/client/modules/edit-file.js +++ b/client/modules/edit-file.js @@ -170,9 +170,7 @@ function getMenuData() { 'Select All Ctrl+A' : () => { editor.selectAll(); }, - 'Close Esc' : () => { - hide(); - }, + 'Close Esc' : hide, }; } diff --git a/client/modules/edit-names.js b/client/modules/edit-names.js index e26e9ad8..49cfde42 100644 --- a/client/modules/edit-names.js +++ b/client/modules/edit-names.js @@ -195,9 +195,7 @@ function setMenu(event) { 'Select All Ctrl+A' : () => { editor.selectAll(); }, - 'Close Esc' : () => { - hide(); - }, + 'Close Esc' : hide, }; const element = CloudCmd.Edit.getElement(); diff --git a/client/modules/operation/index.js b/client/modules/operation/index.js index dc80b8f8..66e91494 100644 --- a/client/modules/operation/index.js +++ b/client/modules/operation/index.js @@ -225,13 +225,9 @@ Operation.move = processFiles({ type: 'move', }); -Operation.delete = () => { - promptDelete(); -}; +Operation.delete = promptDelete; -Operation.deleteSilent = () => { - deleteSilent(); -}; +Operation.deleteSilent = deleteSilent; Operation.pack = () => { const isZip = config('packer') === 'zip'; diff --git a/client/modules/view.js b/client/modules/view.js index 5b49e522..6e3d9540 100644 --- a/client/modules/view.js +++ b/client/modules/view.js @@ -355,8 +355,8 @@ function setCurrentByPosition(position) { filesPassive, } = Info; - const isFiles = ~files.indexOf(element); - const isFilesPassive = ~filesPassive.indexOf(element); + const isFiles = files.includes(element); + const isFilesPassive = filesPassive.includes(element); if (!isFiles && !isFilesPassive) return; diff --git a/server/route.spec.js b/server/route.spec.js index 82fe1d4d..4c5b2b22 100644 --- a/server/route.spec.js +++ b/server/route.spec.js @@ -215,7 +215,7 @@ test('cloudcmd: route: not found', async (t) => { options, }); - t.ok(~body.indexOf('ENOENT: no such file or directory'), 'should return error'); + t.ok(body.includes('ENOENT: no such file or directory'), 'should return error'); t.end(); });