mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
chore(cloudcmd) lint
This commit is contained in:
parent
95ede62e81
commit
6af8f19bb6
7 changed files with 13 additions and 13 deletions
|
|
@ -32,7 +32,7 @@ function EventsProto() {
|
|||
|
||||
switch(type) {
|
||||
default:
|
||||
if (!/element$/.test(type))
|
||||
if (!type.endsWith('element'))
|
||||
throw Error('unknown eventName: ' + type);
|
||||
|
||||
parseArgs(
|
||||
|
|
|
|||
|
|
@ -36,8 +36,8 @@ function check(name) {
|
|||
}
|
||||
|
||||
function getModule(name) {
|
||||
const regExpHTML = new RegExp(FILES_HTML + '|' + FILES_HTML_ROOT);
|
||||
const regExpJSON = new RegExp(FILES_JSON);
|
||||
const regExpHTML = RegExp(FILES_HTML + '|' + FILES_HTML_ROOT);
|
||||
const regExpJSON = RegExp(FILES_JSON);
|
||||
|
||||
const isHTML = regExpHTML.test(name);
|
||||
const isJSON = regExpJSON.test(name);
|
||||
|
|
@ -54,7 +54,7 @@ function getModule(name) {
|
|||
|
||||
function getPath(name, isHTML, isJSON) {
|
||||
let path;
|
||||
const regExp = new RegExp(FILES_HTML_ROOT);
|
||||
const regExp = RegExp(FILES_HTML_ROOT);
|
||||
const isRoot = regExp.test(name);
|
||||
|
||||
if (isHTML) {
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ module.exports = (userMenu) => {
|
|||
continue;
|
||||
}
|
||||
|
||||
if (/^_/.test(str)) {
|
||||
if (str.startsWith('_')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ const respondWith = currify((f, e) => {
|
|||
const {url} = request;
|
||||
const pathname = getPathName(url);
|
||||
|
||||
if (/\/$/.test(url) || /\^\/fs/.test(pathname))
|
||||
if (url.endsWith('/') || /\^\/fs/.test(pathname))
|
||||
return;
|
||||
|
||||
if (!isGet(request))
|
||||
|
|
@ -24,7 +24,7 @@ const respondWith = currify((f, e) => {
|
|||
if (!isBasic(request))
|
||||
return;
|
||||
|
||||
if (/^\/api/.test(pathname))
|
||||
if (pathname.startsWith('/api'))
|
||||
return;
|
||||
|
||||
if (/^socket.io/.test(pathname))
|
||||
|
|
|
|||
|
|
@ -27,14 +27,14 @@ const {request} = require('serve-once')(cloudcmd, {
|
|||
test('cloudcmd: markdown: error', async (t) => {
|
||||
const {body} = await request.get('/api/v1/markdown/not-found');
|
||||
|
||||
t.ok(/ENOENT/.test(body), 'should not found');
|
||||
t.match(body, 'ENOENT', 'should not found');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('cloudcmd: markdown: relative: error', async (t) => {
|
||||
const {body} = await request.get('/api/v1/markdown/not-found?relative');
|
||||
|
||||
t.ok(/ENOENT/.test(body), 'should not found');
|
||||
t.match(body, 'ENOENT', 'should not found');
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ function rest(config, request, response) {
|
|||
*/
|
||||
function sendData(params, config, callback) {
|
||||
const p = params;
|
||||
const isMD = /^\/markdown/.test(p.name);
|
||||
const isMD = p.name.startsWith('/markdown');
|
||||
const rootDir = config('root');
|
||||
|
||||
if (isMD)
|
||||
|
|
@ -122,7 +122,7 @@ function onGET(params, config, callback) {
|
|||
if (p.name[0] === '/')
|
||||
cmd = p.name.replace('/', '');
|
||||
|
||||
if (/^pack/.test(cmd)) {
|
||||
if (cmd.startsWith('pack')) {
|
||||
cmd = cmd.replace(/^pack/, '');
|
||||
streamPack(root(cmd, rootDir), p.response, packer);
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -137,7 +137,7 @@ test('cloudcmd: rest: pack: tar: put: error', async (t) => {
|
|||
]),
|
||||
});
|
||||
|
||||
t.ok(/^ENOENT: no such file or directory/.test(body), 'should return error');
|
||||
t.match(body, /^ENOENT: no such file or directory/, 'should return error');
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
@ -219,7 +219,7 @@ test('cloudcmd: rest: pack: zip: put: error', async (t) => {
|
|||
]),
|
||||
});
|
||||
|
||||
t.ok(/^ENOENT: no such file or directory/.test(body), 'should return error');
|
||||
t.match(body, /^ENOENT: no such file or directory/, 'should return error');
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue