Skip to content

Commit 90b7c11

Browse files
committed
fix(tslint&build-docs): fix build-docs and code style
1 parent f86d605 commit 90b7c11

File tree

10 files changed

+47
-46
lines changed

10 files changed

+47
-46
lines changed

bin/build-docs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/usr/bin/env node
22

3-
require('../out/script/build-docs')
3+
require('../out/build-docs')

src/common/util.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ export function executeFile(
6767
export function pcb(
6868
cb: (...args: any[]) => void,
6969
): (...args: any[]) => Promise<any> {
70-
return function(...args: any[]): Promise<any> {
70+
return (...args: any[]): Promise<any> => {
7171
return new Promise((resolve) => {
72-
cb(...args, function(...args: any[]) {
73-
resolve(args);
72+
cb(...args, (...params: any[]) => {
73+
resolve(params);
7474
});
7575
});
7676
};

src/lib/vimparser.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export declare class StringReader {
3737
constructor(str: string)
3838
}
3939

40+
// tslint:disable-next-line
4041
export declare class VimLParser {
4142
constructor(isNeovim: boolean)
4243
public parse(stringReader: StringReader): INode;

src/script/build-docs.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,12 @@ class Server {
5959
const { vimruntime } = this.config;
6060
if (vimruntime) {
6161
const paths = [EVAL_PATH, OPTIONS_PATH, INDEX_PATH, API_PATH, AUTOCMD_PATH];
62+
// tslint:disable-next-line: prefer-for-of
6263
for (let index = 0; index < paths.length; index++) {
6364
const p = join(vimruntime, paths[index]);
6465
const [err, data]: [Error, Buffer] = await pcb(readFile)(p, "utf-8");
6566
if (err) {
67+
// tslint:disable-next-line: no-console
6668
console.error(`[vimls]: read ${p} error: ${ err.message}`);
6769
}
6870
this.text[paths[index]] = (data && data.toString().split("\n")) || [];
@@ -100,7 +102,7 @@ class Server {
100102
expandKeywords: this.expandKeywordDocuments,
101103
},
102104
}, null, 2);
103-
writeFileSync("./docs/builtin-docs.json", str, "utf-8");
105+
writeFileSync("./src/docs/builtin-docs.json", str, "utf-8");
104106
}
105107

106108
private formatFunctionSnippets(fname: string, snippets: string): string {
@@ -122,8 +124,7 @@ class Server {
122124
const evalText = this.text[EVAL_PATH] || [];
123125
let isMatchLine = false;
124126
let completionItem: CompletionItem;
125-
for (let idx = 0; idx < evalText.length; idx++) {
126-
const line = evalText[idx];
127+
for (const line of evalText) {
127128
if (!isMatchLine) {
128129
if (/\*vim-variable\*/.test(line)) {
129130
isMatchLine = true;
@@ -169,8 +170,7 @@ class Server {
169170
const optionsText: string[] = this.text[OPTIONS_PATH] || [];
170171
let isMatchLine = false;
171172
let completionItem: CompletionItem;
172-
for (let idx = 0; idx < optionsText.length; idx++) {
173-
const line = optionsText[idx];
173+
for (const line of optionsText) {
174174
if (!isMatchLine) {
175175
if (/\*'aleph'\*/.test(line)) {
176176
isMatchLine = true;
@@ -210,8 +210,7 @@ class Server {
210210
const evalText = this.text[EVAL_PATH] || [];
211211
let isMatchLine = false;
212212
let completionItem: CompletionItem;
213-
for (let idx = 0; idx < evalText.length; idx++) {
214-
const line = evalText[idx];
213+
for (const line of evalText) {
215214
if (!isMatchLine) {
216215
if (/\*functions\*/.test(line)) {
217216
isMatchLine = true;
@@ -347,8 +346,7 @@ class Server {
347346
const indexText = this.text[INDEX_PATH] || [];
348347
let isMatchLine = false;
349348
let completionItem: CompletionItem;
350-
for (let idx = 0; idx < indexText.length; idx++) {
351-
const line = indexText[idx];
349+
for (const line of indexText) {
352350
if (!isMatchLine) {
353351
if (/\*ex-cmd-index\*/.test(line)) {
354352
isMatchLine = true;
@@ -560,7 +558,7 @@ async function main() {
560558
// merge autocmd
561559
next.vimAutocmdItems.forEach((item) => {
562560
const { label } = item;
563-
if (!pre.vimAutocmdItems.some((item) => item.label === label)) {
561+
if (!pre.vimAutocmdItems.some((n) => n.label === label)) {
564562
pre.vimAutocmdItems.push(item);
565563
}
566564
});

src/server/buffer.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,8 @@ export class Buffer {
276276

277277
localVariables.forEach((l) => {
278278
if ((l.data as IIdentifier[]).some((identifier) => {
279-
return funList.every((fun) => !(fun.startLine < identifier.startLine && identifier.startLine < fun.endLine));
279+
return funList.every((fun) =>
280+
!(fun.startLine < identifier.startLine && identifier.startLine < fun.endLine));
280281
})) {
281282
globalVariables.push(l);
282283
}
@@ -723,6 +724,7 @@ export class Buffer {
723724
return;
724725
}
725726

727+
// tslint:disable-next-line: max-line-length
726728
if (!/^[ \t]*((au|aut|auto|autoc|autocm|autocmd|com|comm|comma|comman|command)!?[ \t]+|([a-zA-Z]*map!?[ \t]+.*?:))/.test(str)) {
727729
return;
728730
}

src/server/builtin.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ class Builtin {
6464
private vimCommandDocuments: Record<string, string[]> = {};
6565
private vimFeatureDocuments: Record<string, string[]> = {};
6666
private expandKeywordDocuments: Record<string, string[]> = {};
67-
constructor() {}
6867

6968
public init() {
7069
this.start();
@@ -225,7 +224,7 @@ class Builtin {
225224
contents: this.formatVimDocument(this.expandKeywordDocuments[`<${name}>`]),
226225
};
227226
// command
228-
} if (isSomeMatchPattern(commandPattern, pre) && this.vimCommandDocuments[name]) {
227+
} else if (isSomeMatchPattern(commandPattern, pre) && this.vimCommandDocuments[name]) {
229228
return {
230229
contents: this.formatVimDocument(this.vimCommandDocuments[name]),
231230
};

src/server/parser.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,14 @@ export function next(
6666
if (!parserHandles[textDoc.uri]) {
6767
const { uri } = textDoc;
6868
parserHandles[uri] = origin$.pipe(
69-
filter((textDoc: TextDocument) => uri === textDoc.uri),
70-
switchMap((textDoc: TextDocument) => {
69+
filter((td: TextDocument) => uri === td.uri),
70+
switchMap((td: TextDocument) => {
7171
return timer(100).pipe(
72-
map(() => textDoc),
72+
map(() => td),
7373
);
7474
}),
75-
waitMap((textDoc: TextDocument) => {
76-
return from(handleParse(textDoc));
75+
waitMap((td: TextDocument) => {
76+
return from(handleParse(td));
7777
}, true),
7878
).subscribe(
7979
(res) => {
@@ -121,8 +121,7 @@ export function scan(paths: string | string[]) {
121121
if (config.indexes.runtimepath) {
122122
const list: string[] = [].concat(paths);
123123

124-
for (let idx = 0; idx < list.length; idx++) {
125-
let p = list[idx];
124+
for (let p of list) {
126125
if (!p) {
127126
continue;
128127
}

src/server/workspaces.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ export class Workspace {
127127
return b.isBelongToWorkdir(buf.getProjectRoot());
128128
});
129129
return this.filterDuplicate(
130-
buffers.reduce<CompletionItem[]>((res, buf) => {
131-
return res.concat(buf.getGlobalFunctionItems());
130+
buffers.reduce<CompletionItem[]>((res, cur) => {
131+
return res.concat(cur.getGlobalFunctionItems());
132132
}, []),
133133
);
134134
}
@@ -154,10 +154,10 @@ export class Workspace {
154154
return b.isBelongToWorkdir(buf.getProjectRoot());
155155
});
156156
return this.filterDuplicate(
157-
buffers.reduce<CompletionItem[]>((res, buf) => {
157+
buffers.reduce<CompletionItem[]>((res, cur) => {
158158
return res
159-
.concat(buf.getGlobalIdentifierItems())
160-
.concat(buf.getEnvItems());
159+
.concat(cur.getGlobalIdentifierItems())
160+
.concat(cur.getEnvItems());
161161
}, []),
162162
);
163163
}
@@ -185,7 +185,9 @@ export class Workspace {
185185

186186
private getGlobalLocaltion(
187187
name: string,
188+
// tslint:disable-next-line: variable-name
188189
_uri: string,
190+
// tslint:disable-next-line: variable-name
189191
_position: Position,
190192
locationType: "definition" | "references",
191193
): Location[] {
@@ -215,11 +217,11 @@ export class Workspace {
215217
});
216218
// filter function local variables
217219
if (/^([a-zA-Z_]\w*(\.\w+)*)$/.test(name)) {
218-
const gloalFunctions = this.buffers[uri].getGlobalFunctions();
220+
const glFunctions = this.buffers[uri].getGlobalFunctions();
219221
const scriptFunctions = this.buffers[uri].getScriptFunctions();
220-
const funList = Object.values(gloalFunctions).concat(
222+
const funList = Object.values(glFunctions).concat(
221223
Object.values(scriptFunctions),
222-
).reduce((res, fs) => res.concat(fs), []);
224+
).reduce((aur, fs) => aur.concat(fs), []);
223225
tmp.forEach((l) => {
224226
if (!funList.some((fun) => {
225227
return fun.startLine - 1 < l.range.start.line && l.range.start.line < fun.endLine - 1;
@@ -238,6 +240,7 @@ export class Workspace {
238240
private getScriptLocation(
239241
names: string[],
240242
uri: string,
243+
// tslint:disable-next-line: variable-name
241244
_position: Position,
242245
locationType: "definition" | "references",
243246
): Location[] {
@@ -282,9 +285,9 @@ export class Workspace {
282285
}
283286
const vimLineNum = position.line + 1;
284287
let startLine = -1;
285-
let endLine = -1
288+
let endLine = -1;
286289
// get function args completion items
287-
; ([] as IFunction[])
290+
([] as IFunction[])
288291
.concat(
289292
Object
290293
.values(this.buffers[uri].getGlobalFunctions())
@@ -364,7 +367,7 @@ export class Workspace {
364367
});
365368
if (flist.length) {
366369
const n = name.slice(2);
367-
return flist.filter((item) => item.args && item.args.some((item) => item.value === n))
370+
return flist.filter((item) => item.args && item.args.some((m) => m.value === n))
368371
.map((item) => {
369372
const startLine = item.startLine - 1;
370373
let startCol = item.startCol - 1;
@@ -508,7 +511,7 @@ export class Workspace {
508511
});
509512
});
510513
if (flist.length) {
511-
return flist.filter((item) => item.args && item.args.some((item) => item.value === name))
514+
return flist.filter((item) => item.args && item.args.some((n) => n.value === name))
512515
.map((item) => {
513516
const startLine = item.startLine - 1;
514517
let startCol = item.startCol - 1;

tslint.json

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
{
2-
"defaultSeverity": "error",
3-
"extends": [
4-
"tslint:recommended"
5-
],
6-
"jsRules": {},
7-
"rules": {
8-
"object-literal-sort-keys": false
9-
},
10-
"rulesDirectory": []
2+
"defaultSeverity": "error",
3+
"extends": ["tslint:recommended"],
4+
"jsRules": {},
5+
"rules": {
6+
"object-literal-sort-keys": false
7+
},
8+
"rulesDirectory": []
119
}

webpack.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ const path = require('path')
44
module.exports = {
55
entry: {
66
index: './src/index.ts',
7-
scan: './src/server/scan.ts'
7+
scan: './src/server/scan.ts',
8+
'build-docs': './src/script/build-docs.ts'
89
},
910
target: 'node',
1011
mode: 'none',

0 commit comments

Comments
 (0)