chore: lint

This commit is contained in:
coderiaser 2026-07-15 23:26:28 +03:00
parent 8258cdb651
commit 7edea50296
13 changed files with 82 additions and 62 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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