Skip to content

Commit 287bffd

Browse files
committed
修改代码以符合ESLint
1 parent ff35ee7 commit 287bffd

File tree

4 files changed

+158
-158
lines changed

4 files changed

+158
-158
lines changed

Diff for: src/CommandProvider.ts

+45-45
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,32 @@ let commandList: vscode.Disposable[] = [];
1212
* @returns [开始行, 结束行, 开始列, 结束列]
1313
*/
1414
function getTextEditorPosition(): number[] {
15-
let st_line: number = <number>(vscode.window.activeTextEditor?.selection.start.line);
16-
let st_character: number = <number>(vscode.window.activeTextEditor?.selection.start.character);
17-
let ed_line: number = <number>(vscode.window.activeTextEditor?.selection.end.line);
18-
let ed_character: number = <number>(vscode.window.activeTextEditor?.selection.end.character);
15+
let stLine: number = <number>(vscode.window.activeTextEditor?.selection.start.line);
16+
let stCharacter: number = <number>(vscode.window.activeTextEditor?.selection.start.character);
17+
let edLine: number = <number>(vscode.window.activeTextEditor?.selection.end.line);
18+
let edCharacter: number = <number>(vscode.window.activeTextEditor?.selection.end.character);
1919

20-
// console.log("添加文字-start", st_line, st_character);
21-
// console.log("添加文字-end", ed_line, ed_character);
20+
// console.log("添加文字-start", stLine, stCharacter);
21+
// console.log("添加文字-end", edLine, edCharacter);
2222

23-
return [st_line, ed_line, st_character, ed_character];
23+
return [stLine, edLine, stCharacter, edCharacter];
2424
}
2525

2626
// add_both_fixed
2727
commandList.push(
2828
// 添加在选中文字的两边,光标位置不动
29-
vscode.commands.registerCommand("add_both_fixed", (label, content_l, content_r) => {
29+
vscode.commands.registerCommand("add_both_fixed", (label, contentL, contentR) => {
3030
// 快捷键匹配
31-
if(label=="ctrl_b"){
32-
content_l = content_r = "**";
33-
}else if(label=="ctrl_i"){
34-
content_l = content_r = "*";
31+
if(label==="ctrl_b"){
32+
contentL = contentR = "**";
33+
}else if(label==="ctrl_i"){
34+
contentL = contentR = "*";
3535
}
3636
vscode.window.activeTextEditor?.edit((editBuilder) => {
37-
let [st_line, ed_line, st_character, ed_character] = getTextEditorPosition();
37+
let [stLine, edLine, stCharacter, edCharacter] = getTextEditorPosition();
3838

39-
editBuilder.insert(new vscode.Position(st_line, st_character), content_l);
40-
editBuilder.insert(new vscode.Position(ed_line, ed_character), content_r);
39+
editBuilder.insert(new vscode.Position(stLine, stCharacter), contentL);
40+
editBuilder.insert(new vscode.Position(edLine, edCharacter), contentR);
4141
});
4242
})
4343
);
@@ -55,9 +55,9 @@ commandList.push(
5555
content = "### ";
5656
}
5757
vscode.window.activeTextEditor?.edit((editBuilder) => {
58-
let [st_line, ...rest] = getTextEditorPosition();
58+
let [stLine, ...rest] = getTextEditorPosition();
5959

60-
editBuilder.insert(new vscode.Position(st_line, 0), content);
60+
editBuilder.insert(new vscode.Position(stLine, 0), content);
6161
});
6262
})
6363
);
@@ -67,9 +67,9 @@ commandList.push(
6767
// 添加在当前位置,光标位置不动
6868
vscode.commands.registerCommand("add_cur_fixed", (label, content) => {
6969
vscode.window.activeTextEditor?.edit((editBuilder) => {
70-
let [st_line, , st_character,] = getTextEditorPosition();
70+
let [stLine, , stCharacter,] = getTextEditorPosition();
7171

72-
editBuilder.insert(new vscode.Position(st_line, st_character), content);
72+
editBuilder.insert(new vscode.Position(stLine, stCharacter), content);
7373
});
7474
})
7575
);
@@ -79,9 +79,9 @@ commandList.push(
7979
// 添加下一行开头,光标位置不动
8080
vscode.commands.registerCommand("add_nxt_fixed", (label, content) => {
8181
vscode.window.activeTextEditor?.edit((editBuilder) => {
82-
let [st_line, ...rest] = getTextEditorPosition();
82+
let [stLine, ...rest] = getTextEditorPosition();
8383

84-
editBuilder.insert(new vscode.Position(st_line + 1, 0), content);
84+
editBuilder.insert(new vscode.Position(stLine + 1, 0), content);
8585
});
8686
})
8787
);
@@ -95,16 +95,16 @@ commandList.push(
9595
canSelectMany: false,
9696
canSelectFolders: false
9797
}).then(res => {
98-
if (res != undefined && res.length != 0) {
98+
if (res !== undefined && res.length !== 0) {
9999
let uri = res[0].path;
100100
uri = uri.substring(1, uri.length);
101101
vscode.window.activeTextEditor?.edit((editBuilder) => {
102-
let [st_line, ...rest] = getTextEditorPosition();
102+
let [stLine, ...rest] = getTextEditorPosition();
103103

104-
editBuilder.insert(new vscode.Position(st_line + 1, 0), "![title](" + uri + ")");
104+
editBuilder.insert(new vscode.Position(stLine + 1, 0), "![title](" + uri + ")");
105105
});
106106
}
107-
})
107+
});
108108
})
109109
);
110110

@@ -126,7 +126,7 @@ function makeTable(row: number, col: number, align: number): string {
126126
content += "\n";
127127
// 插入对齐行
128128
content += "|";
129-
let alignStr: string = align == 0 ? ":--:" : align == 1 ? ":---" : "---:";
129+
let alignStr: string = align === 0 ? ":--:" : align === 1 ? ":---" : "---:";
130130
for (let i = 0; i < col; i++) {
131131
content += alignStr + "|";
132132
}
@@ -152,31 +152,31 @@ commandList.push(
152152
vscode.window.showInputBox({
153153
placeHolder: '请输入表格的行数,默认为2'
154154
}).then(res => {
155-
if (res == undefined) throw "no input";
155+
if (res === undefined) {throw new Error("no input");}
156156
else {
157-
row = isNaN(Number(res)) || res == "" ? row : Number(res);
157+
row = isNaN(Number(res)) || res === "" ? row : Number(res);
158158
return vscode.window.showInputBox({
159159
placeHolder: '请输入表格的列数,默认为2'
160-
})
160+
});
161161
}
162162
}).then(res => {
163-
if (res == undefined) throw "no input";
163+
if (res === undefined) {throw new Error("no input");}
164164
else {
165-
col = isNaN(Number(res)) || res == "" ? col : Number(res);
165+
col = isNaN(Number(res)) || res === "" ? col : Number(res);
166166
return vscode.window.showInputBox({
167167
placeHolder: '请输入表格对齐方式',
168168
prompt: '0:居中对齐(默认),1:左对齐,2:右对齐'
169-
})
169+
});
170170
}
171171
}).then(res => {
172172
align = isNaN(Number(res)) ? align : Number(res);
173173
// 检查行列必须大于0
174-
if (row <= 0 || col <= 0 || align < 0 || align > 2) throw "input error";
174+
if (row <= 0 || col <= 0 || align < 0 || align > 2) {throw new Error("input error");}
175175
// 插入视图
176176
vscode.window.activeTextEditor?.edit((editBuilder) => {
177-
let [st_line, ...rest] = getTextEditorPosition();
177+
let [stLine, ...rest] = getTextEditorPosition();
178178

179-
editBuilder.insert(new vscode.Position(st_line + 1, 0), makeTable(row, col, align));
179+
editBuilder.insert(new vscode.Position(stLine + 1, 0), makeTable(row, col, align));
180180
});
181181
});
182182
})
@@ -193,34 +193,34 @@ commandList.push(
193193
vscode.window.showInputBox({
194194
placeHolder: '请输入label信息,如"下载量","访问量"...,默认为"label"'
195195
}).then(res => {
196-
if (res == undefined) throw "no input";
196+
if (res === undefined) {throw new Error("no input");}
197197
else {
198-
_label = res == "" ? _label : res;
198+
_label = res === "" ? _label : res;
199199
return vscode.window.showInputBox({
200200
placeHolder: '请输入message信息,如"10k"...,默认为"message"'
201-
})
201+
});
202202
}
203203
}).then(res => {
204-
if (res == undefined) throw "no input";
204+
if (res === undefined) {throw new Error("no input");}
205205
else {
206-
_msg = res == "" ? _msg : res;
206+
_msg = res === "" ? _msg : res;
207207
return vscode.window.showQuickPick([
208208
'brightgreen', 'yellow', 'orange', 'red', 'blue', 'success', 'important', 'critical', 'informational', 'blueviolet'
209209
], {
210210
canPickMany: false,
211211
placeHolder: '请选择颜色'
212-
})
212+
});
213213
}
214214
}).then(res => {
215-
_style = res == undefined ? _style : res;
215+
_style = res === undefined ? _style : res;
216216
// 构造内容
217217
let content: string = "![](https://img.shields.io/badge/" + _label + "-" + _msg + "-" + _style + ")";
218218

219219
// 插入视图
220220
vscode.window.activeTextEditor?.edit((editBuilder) => {
221-
let [st_line, ...rest] = getTextEditorPosition();
221+
let [stLine, ...rest] = getTextEditorPosition();
222222

223-
editBuilder.insert(new vscode.Position(st_line + 1, 0), content);
223+
editBuilder.insert(new vscode.Position(stLine + 1, 0), content);
224224
});
225225
});
226226
})
@@ -246,6 +246,6 @@ export function initWebViewCommand(): vscode.Disposable[] {
246246
commandList.push(vscode.commands.registerCommand("nav_web", (label, url) => {
247247
const webView = createWebView(vscode.ViewColumn.Active, label, url);
248248
commandList.push(webView);
249-
}))
249+
}));
250250
return commandList;
251251
}

0 commit comments

Comments
 (0)