Skip to content

Commit 631cc8b

Browse files
committed
chore: eslint fix
1 parent f880cc9 commit 631cc8b

File tree

1 file changed

+23
-28
lines changed

1 file changed

+23
-28
lines changed

common/utils/getTestCase.js

+23-28
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,22 @@
1-
const { ListNode, parse, toArray } = require("../structures/ListNode");
2-
3-
4-
/**
1+
/**
52
* 获取test case 入参的数据类型
63
* @param {string} jsCode leetcode的实例函数体
74
* @param {string} type 类型,param入参,returns返回值
85
* @returns {string[]}
96
*/
107
const getDataStructure = (jsCode, type = 'param') => {
11-
const regexMap = {
12-
param: /@param\s+{\s*([^}\s]+)\s*}/g,
13-
return: /@return\s+{\s*([^}\s]+)\s*}/g
14-
};
15-
const regex = regexMap[type];
16-
const paramTypes = [];
17-
let match;
18-
while ((match = regex.exec(jsCode)) !== null) {
19-
paramTypes.push(match[1]);
20-
}
21-
return paramTypes
22-
}
23-
24-
8+
const regexMap = {
9+
param: /@param\s+{\s*([^}\s]+)\s*}/g,
10+
return: /@return\s+{\s*([^}\s]+)\s*}/g,
11+
};
12+
const regex = regexMap[type];
13+
const paramTypes = [];
14+
let match;
15+
while ((match = regex.exec(jsCode)) !== null) {
16+
paramTypes.push(match[1]);
17+
}
18+
return paramTypes;
19+
};
2520

2621
/**
2722
* test case 需要从两个地方拿到内容
@@ -30,14 +25,14 @@ const getDataStructure = (jsCode, type = 'param') => {
3025
* @param question
3126
* @returns {string}
3227
*/
33-
function getTestCase(question){
34-
const detail = question.detail.replaceAll("`","");
35-
const cases = detail.match(/(<[a-zA-Z]+>)?[|:](<\/[a-zA-Z]+>)?.+\n/g)
36-
?.map(str=>`[${str?.replace(/(<[a-zA-Z]+>)?[|:]/gm,"")?.replace(/(<\/[a-zA-Z]+>)?/,"")?.replace("\n","")}]`)
37-
const expires = detail.match(/(<[a-zA-Z]+>)?[|:](<\/[a-zA-Z]+>)?.+\n/g)
38-
?.map(str=>str?.replace(/(<[a-zA-Z]+>)?[|:](<\/[a-zA-Z]+>)?/gm,"")?.replace(/(<\/[a-zA-Z]+>)?/gm,"")?.replace("\n",""))
39-
const functionName = question.jsCode?.match(/var.+=/g)?.[0]?.replace("var ","")?.replace(" =","");
40-
return `showLogs(
28+
function getTestCase(question) {
29+
const detail = question.detail.replaceAll('`', '');
30+
const cases = detail.match(/(<[a-zA-Z]+>)?[|:](<\/[a-zA-Z]+>)?.+\n/g)
31+
?.map((str) => `[${str?.replace(/(<[a-zA-Z]+>)?[|:]/gm, '')?.replace(/(<\/[a-zA-Z]+>)?/, '')?.replace('\n', '')}]`);
32+
const expires = detail.match(/(<[a-zA-Z]+>)?[|:](<\/[a-zA-Z]+>)?.+\n/g)
33+
?.map((str) => str?.replace(/(<[a-zA-Z]+>)?[|:](<\/[a-zA-Z]+>)?/gm, '')?.replace(/(<\/[a-zA-Z]+>)?/gm, '')?.replace('\n', ''));
34+
const functionName = question.jsCode?.match(/var.+=/g)?.[0]?.replace('var ', '')?.replace(' =', '');
35+
return `showLogs(
4136
${functionName},
4237
{
4338
data: [${cases}],
@@ -47,6 +42,6 @@ function getTestCase(question){
4742
data: [${expires}],
4843
structrue: ${JSON.stringify(getDataStructure(question.jsCode, 'return'))}
4944
}
50-
)`
45+
)`;
5146
}
52-
module.exports = {getTestCase, getDataStructure}
47+
module.exports = { getTestCase, getDataStructure };

0 commit comments

Comments
 (0)