From 7edea50296e115a2c15a43917baca1647593f811 Mon Sep 17 00:00:00 2001 From: coderiaser Date: Wed, 15 Jul 2026 23:26:28 +0300 Subject: [PATCH] chore: lint --- .madrun.js | 2 +- client/dom/current-file.spec.js | 21 ++++++++------------- client/dom/index.js | 6 +----- client/dom/load-remote.js | 16 +++++++++++----- client/key/vim/find.spec.js | 8 +++++++- client/key/vim/index.spec.js | 1 - client/modules/view/index.spec.js | 4 +++- common/util.spec.js | 11 +++++++++-- server/cloudcmd.spec.js | 18 ++++++++++-------- server/exit.spec.js | 17 ++++++++++------- server/rest/index.spec.js | 19 ++++++++++--------- server/validate.spec.js | 1 - test/server/env.js | 20 ++++++++++++-------- 13 files changed, 82 insertions(+), 62 deletions(-) diff --git a/.madrun.js b/.madrun.js index 9910aa7c..9c75535f 100644 --- a/.madrun.js +++ b/.madrun.js @@ -21,7 +21,7 @@ export default { 'start:dev', ]), 'lint:all': () => run('lint:progress'), - 'lint': () => 'redlint fix; putout . --rulesdir rules', + 'lint': () => 'redlint fix; putout .', 'lint:progress': () => run('lint', '-f progress'), 'watch:lint': () => 'nodemon -w client -w server -w test -w common -w .webpack -x "putout -s"', 'fresh:lint': () => run('lint', '--fresh'), diff --git a/client/dom/current-file.spec.js b/client/dom/current-file.spec.js index 6bf0509b..85b18a29 100644 --- a/client/dom/current-file.spec.js +++ b/client/dom/current-file.spec.js @@ -19,14 +19,13 @@ test('current-file: setCurrentName: setAttribute', (t) => { currentFile.setCurrentName('hello', current); + globalThis.DOM = DOM; + globalThis.CloudCmd = CloudCmd; + t.calledWith(setAttribute, [ 'data-name', 'js-file-aGVsbG8=', ], 'should call setAttribute'); - - globalThis.DOM = DOM; - globalThis.CloudCmd = CloudCmd; - t.end(); }); @@ -41,14 +40,13 @@ test('current-file: setCurrentName: setAttribute: cyrillic', (t) => { currentFile.setCurrentName('ай', current); + globalThis.DOM = DOM; + globalThis.CloudCmd = CloudCmd; + t.calledWith(setAttribute, [ 'data-name', 'js-file-JUQwJUIwJUQwJUI5', ], 'should call setAttribute'); - - globalThis.DOM = DOM; - globalThis.CloudCmd = CloudCmd; - t.end(); }); @@ -76,11 +74,10 @@ test('current-file: emit', (t) => { currentFile.setCurrentName('hello', current); - t.calledWith(emit, ['current-file', current], 'should call emit'); - globalThis.DOM = DOM; globalThis.CloudCmd = CloudCmd; + t.calledWith(emit, ['current-file', current], 'should call emit'); t.end(); }); @@ -96,14 +93,12 @@ test('current-file: setCurrentName: return', (t) => { globalThis.CloudCmd = getCloudCmd(); const current = create(); - const result = currentFile.setCurrentName('hello', current); - t.equal(result, link, 'should return link'); - globalThis.DOM = DOM; globalThis.CloudCmd = CloudCmd; + t.equal(result, link, 'should return link'); t.end(); }); diff --git a/client/dom/index.js b/client/dom/index.js index f6ce6bc7..a82b6f72 100644 --- a/client/dom/index.js +++ b/client/dom/index.js @@ -442,11 +442,7 @@ export function getFilenames(files) { if (name === '..') allFiles.shift(); - const names = allFiles.map((current) => { - return DOM.getCurrentName(current); - }); - - return names; + return allFiles.map(DOM.getCurrentName); } /** diff --git a/client/dom/load-remote.js b/client/dom/load-remote.js index 43af0cf5..5be8e327 100644 --- a/client/dom/load-remote.js +++ b/client/dom/load-remote.js @@ -33,13 +33,19 @@ export const loadRemote = callbackify(async (name, options) => { local = [module.local]; } - const localURL = local.map((url) => prefix + url); + const localURL = []; - const remoteURL = remoteTmpls.map((tmpl) => { - return rendy(tmpl, { + for (const url of local) { + localURL.push(prefix + url); + } + + const remoteURL = []; + + for (const tmpl of remoteTmpls) { + remoteURL.push(rendy(tmpl, { version, - }); - }); + })); + } if (online) { const [e] = await tryToCatch(load.parallel, remoteURL); diff --git a/client/key/vim/find.spec.js b/client/key/vim/find.spec.js index c1164aea..191a3652 100644 --- a/client/key/vim/find.spec.js +++ b/client/key/vim/find.spec.js @@ -1,6 +1,12 @@ import test from 'supertape'; import {getDOM} from './globals.fixture.js'; -import {_next, _previous, find, findNext, findPrevious} from './find.js'; +import { + _next, + _previous, + find, + findNext, + findPrevious, +} from './find.js'; globalThis.DOM = getDOM(); diff --git a/client/key/vim/index.spec.js b/client/key/vim/index.spec.js index a10650ad..231c6577 100644 --- a/client/key/vim/index.spec.js +++ b/client/key/vim/index.spec.js @@ -754,4 +754,3 @@ test('cloudcmd: client: key: N: findPrevious: real', (t) => { t.calledWith(setCurrentByName, ['apple'], 'should set current by previous found name'); t.end(); }); - diff --git a/client/modules/view/index.spec.js b/client/modules/view/index.spec.js index 8d184548..abfbe3f4 100644 --- a/client/modules/view/index.spec.js +++ b/client/modules/view/index.spec.js @@ -31,8 +31,10 @@ test('cloudcmd: client: view: initConfig', (t) => { test('cloudcmd: client: view: initConfig: no options', (t) => { const config = _initConfig(); + const result = typeof config; + const expected = 'object'; - t.equal(typeof config, 'object'); + t.equal(result, expected); t.end(); }); diff --git a/common/util.spec.js b/common/util.spec.js index 6a32848c..6eee1087 100644 --- a/common/util.spec.js +++ b/common/util.spec.js @@ -106,11 +106,18 @@ test('util: getRegExp: no', (t) => { }); test('util: escapeRegExp: no str', (t) => { - t.equal(escapeRegExp(1), 1); + const result = escapeRegExp(1); + const expected = 1; + + t.equal(result, expected); t.end(); }); test('util: escapeRegExp', (t) => { - t.equal(escapeRegExp('#hello'), '\\#hello'); + const result = escapeRegExp('#hello'); + const expected = '\\#hello'; + + t.equal(result, expected); t.end(); }); + diff --git a/server/cloudcmd.spec.js b/server/cloudcmd.spec.js index 8b31f3b5..d79aa4c1 100644 --- a/server/cloudcmd.spec.js +++ b/server/cloudcmd.spec.js @@ -12,6 +12,8 @@ import cloudcmd, { } from '#server/cloudcmd'; import {connect} from '../test/before.js'; +const noop = () => {}; + const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); @@ -159,17 +161,20 @@ test('cloudcmd: auth: accept: no auth', (t) => { test('cloudcmd: getIndexPath: production', (t) => { const isDev = false; - const name = path.join(__dirname, '..', 'dist', 'index.html'); - t.equal(_getIndexPath(isDev), name); + const result = _getIndexPath(isDev); + const expected = path.join(__dirname, '..', 'dist', 'index.html'); + + t.equal(result, expected); t.end(); }); test('cloudcmd: getIndexPath: development', (t) => { const isDev = true; - const name = path.join(__dirname, '..', 'dist-dev', 'index.html'); + const result = _getIndexPath(isDev); + const expected = path.join(__dirname, '..', 'dist-dev', 'index.html'); - t.equal(_getIndexPath(isDev), name); + t.equal(result, expected); t.end(); }); @@ -216,7 +221,6 @@ test('cloudcmd: middle: dropbox', async (t) => { t.end(); }); - test('cloudcmd: logout', async (t) => { const {status} = await request.get('/logout'); @@ -227,7 +231,7 @@ test('cloudcmd: logout', async (t) => { test('cloudcmd: modules', (t) => { const middle = cloudcmd({ modules: { - hello: () => {}, + hello: noop, }, }); @@ -241,5 +245,3 @@ test('cloudcmd: setUrl: cloudcmd.js', async (t) => { t.equal(status, 200, 'should serve cloudcmd.js'); t.end(); }); - - diff --git a/server/exit.spec.js b/server/exit.spec.js index 3b454818..7776576f 100644 --- a/server/exit.spec.js +++ b/server/exit.spec.js @@ -4,44 +4,47 @@ import exit from './exit.js'; test('cloudcmd: exit: process.exit', (t) => { const {exit: exitOriginal} = process; + const exitStub = stub(); - process.exit = stub(); + process.exit = exitStub; exit(); - t.calledWith(process.exit, [1], 'should call process.exit'); process.exit = exitOriginal; + t.calledWith(exitStub, [1], 'should call process.exit'); t.end(); }); test('cloudcmd: exit: console.error', (t) => { const {exit: exitOriginal} = process; const {error} = console; + const errorStub = stub(); - console.error = stub(); + console.error = errorStub; process.exit = stub(); exit('hello world'); - t.calledWith(console.error, ['hello world'], 'should call console.error'); process.exit = exitOriginal; console.error = error; + t.calledWith(errorStub, ['hello world'], 'should call console.error'); t.end(); }); test('cloudcmd: exit.error: console.error: error', (t) => { const {exit: exitOriginal} = process; const {error} = console; + const errorStub = stub(); - console.error = stub(); + console.error = errorStub; process.exit = stub(); exit(Error('hello world')); - t.calledWith(console.error, ['hello world'], 'should call console.error'); - process.exit = exitOriginal; console.error = error; + t.calledWith(errorStub, ['hello world'], 'should call console.error'); t.end(); }); + diff --git a/server/rest/index.spec.js b/server/rest/index.spec.js index 0b25b876..9c672095 100644 --- a/server/rest/index.spec.js +++ b/server/rest/index.spec.js @@ -10,8 +10,6 @@ import { _getPackReg, _getCMD, _rename, - _pack, - _extract, _getPacker, } from './index.js'; @@ -78,7 +76,6 @@ test('rest: onPUT: no callback', async (t) => { t.end(); }); - test('rest: UserError: message', (t) => { const result = _UserError('hello'); @@ -96,14 +93,14 @@ test('rest: UserError: code', (t) => { test('rest: getPackReg: zip', (t) => { const result = _getPackReg('zip'); - t.ok(result.test('file.zip'), 'should match .zip'); + t.match('file.zip', result, 'should match .zip'); t.end(); }); test('rest: getPackReg: tar', (t) => { const result = _getPackReg('tar'); - t.ok(result.test('file.tar.gz'), 'should match .tar.gz'); + t.match('file.tar.gz', result, 'should match .tar.gz'); t.end(); }); @@ -121,25 +118,29 @@ test('rest: getCMD: no slash', (t) => { t.end(); }); -test('rest: rename: no from', async (t) => { +test('rest: rename: no from', (t) => { const callback = stub(); _rename('/', null, 'to', null, callback); const msg = '"from" should be filled'; - t.calledWith(callback, [_UserError(msg)], 'should return UserError'); + t.calledWith(callback, [ + _UserError(msg), + ], 'should return UserError'); t.end(); }); -test('rest: rename: no to', async (t) => { +test('rest: rename: no to', (t) => { const callback = stub(); _rename('/', 'from', null, null, callback); const msg = '"to" should be filled'; - t.calledWith(callback, [_UserError(msg)], 'should return UserError'); + t.calledWith(callback, [ + _UserError(msg), + ], 'should return UserError'); t.end(); }); diff --git a/server/validate.spec.js b/server/validate.spec.js index d2fd1bd9..639f185c 100644 --- a/server/validate.spec.js +++ b/server/validate.spec.js @@ -132,7 +132,6 @@ test('validate: theme: wrong', (t) => { t.end(); }); - test('validate: menu: not valid', (t) => { const exit = stub(); const msg = 'cloudcmd --menu: could be "supermenu" or "aleman" only'; diff --git a/test/server/env.js b/test/server/env.js index 323c0a99..34bc8959 100644 --- a/test/server/env.js +++ b/test/server/env.js @@ -4,34 +4,37 @@ import * as env from '../../server/env.js'; test('env: small', (t) => { process.env.cloudcmd_hello = 'world'; - t.equal(env.parse('hello'), 'world', 'should parse string from env'); delete process.env.cloudcmd_hello; + + t.equal(env.parse('hello'), 'world', 'should parse string from env'); t.end(); }); test('env: big', (t) => { process.env.CLOUDCMD_HELLO = 'world'; - t.equal(env.parse('hello'), 'world', 'should parse string from env'); delete process.env.CLOUDCMD_HELLO; + + t.equal(env.parse('hello'), 'world', 'should parse string from env'); t.end(); }); test('env: bool: false', (t) => { process.env.cloudcmd_terminal = 'false'; - t.notOk(env.bool('terminal'), 'should return false'); delete process.env.cloudcmd_terminal; + + t.notOk(env.bool('terminal'), 'should return false'); t.end(); }); test('env: bool: true', (t) => { process.env.cloudcmd_terminal = 'true'; - t.ok(env.bool('terminal'), 'should be true'); - delete process.env.cloudcmd_terminal; + + t.ok(env.bool('terminal'), 'should be true'); t.end(); }); @@ -39,9 +42,10 @@ test('env: bool: undefined', (t) => { const {cloudcmd_terminal} = process.env; process.env.cloudcmd_terminal = undefined; - - t.notOk(env.bool('terminal'), 'should be undefined'); - process.env.cloudcmd_terminal = cloudcmd_terminal; + + const result = env.bool('terminal'); + + t.notOk(result); t.end(); });