From 71fad5aa411cb7e2138c56185768a53409910011 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Wed, 9 Dec 2020 17:41:58 -0800 Subject: [PATCH] Enable preferConst in TS project --- .eslintignore | 1 + extensions/typescript-language-features/.eslintrc.json | 5 +++++ .../src/languageFeatures/completions.ts | 2 +- .../src/languageFeatures/semanticTokens.ts | 4 ++-- .../src/tsServer/serverProcess.electron.ts | 8 ++++---- .../src/typescriptServiceClient.ts | 2 +- 6 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 extensions/typescript-language-features/.eslintrc.json diff --git a/.eslintignore b/.eslintignore index b2c4a5b6efa..9cca7bdab3a 100644 --- a/.eslintignore +++ b/.eslintignore @@ -14,3 +14,4 @@ **/extensions/**/build/** **/extensions/markdown-language-features/media/** **/extensions/typescript-basics/test/colorize-fixtures/** +**/extensions/typescript-language-features/dist/** diff --git a/extensions/typescript-language-features/.eslintrc.json b/extensions/typescript-language-features/.eslintrc.json new file mode 100644 index 00000000000..ae8cc48c050 --- /dev/null +++ b/extensions/typescript-language-features/.eslintrc.json @@ -0,0 +1,5 @@ +{ + "rules": { + "prefer-const": "error" + } +} diff --git a/extensions/typescript-language-features/src/languageFeatures/completions.ts b/extensions/typescript-language-features/src/languageFeatures/completions.ts index e316dd6ffe4..13c90d1aa04 100644 --- a/extensions/typescript-language-features/src/languageFeatures/completions.ts +++ b/extensions/typescript-language-features/src/languageFeatures/completions.ts @@ -533,7 +533,7 @@ class TypeScriptCompletionItemProvider implements vscode.CompletionItemProvider< let includesPackageJsonImport = false; const items: MyCompletionItem[] = []; - for (let entry of entries) { + for (const entry of entries) { if (!shouldExcludeCompletionEntry(entry, completionConfiguration)) { items.push(new MyCompletionItem(position, document, entry, completionContext, metadata)); includesPackageJsonImport = !!entry.isPackageJsonImport; diff --git a/extensions/typescript-language-features/src/languageFeatures/semanticTokens.ts b/extensions/typescript-language-features/src/languageFeatures/semanticTokens.ts index 16f78dbe486..a64f2cc9be4 100644 --- a/extensions/typescript-language-features/src/languageFeatures/semanticTokens.ts +++ b/extensions/typescript-language-features/src/languageFeatures/semanticTokens.ts @@ -73,7 +73,7 @@ class DocumentSemanticTokensProvider implements vscode.DocumentSemanticTokensPro return null; } - let versionBeforeRequest = document.version; + const versionBeforeRequest = document.version; const response = await (this.client as ExperimentalProtocol.IExtendedTypeScriptServiceClient).execute('encodedSemanticClassifications-full', requestArg, token, { cancelOnResourceChange: document.uri @@ -137,7 +137,7 @@ class DocumentSemanticTokensProvider implements vscode.DocumentSemanticTokensPro function waitForDocumentChangesToEnd(document: vscode.TextDocument) { let version = document.version; return new Promise((s) => { - let iv = setInterval(_ => { + const iv = setInterval(_ => { if (document.version === version) { clearInterval(iv); s(); diff --git a/extensions/typescript-language-features/src/tsServer/serverProcess.electron.ts b/extensions/typescript-language-features/src/tsServer/serverProcess.electron.ts index 96b0c6b411e..c47a75b5e23 100644 --- a/extensions/typescript-language-features/src/tsServer/serverProcess.electron.ts +++ b/extensions/typescript-language-features/src/tsServer/serverProcess.electron.ts @@ -39,7 +39,7 @@ class ProtocolBuffer { if (this.buffer.length - this.index >= toAppend.length) { toAppend.copy(this.buffer, this.index, 0, toAppend.length); } else { - let newSize = (Math.ceil((this.index + toAppend.length) / defaultSize) + 1) * defaultSize; + const newSize = (Math.ceil((this.index + toAppend.length) / defaultSize) + 1) * defaultSize; if (this.index === 0) { this.buffer = Buffer.allocUnsafe(newSize); toAppend.copy(this.buffer, 0, 0, toAppend.length); @@ -61,14 +61,14 @@ class ProtocolBuffer { return result; } current += contentLengthSize; - let start = current; + const start = current; while (current < this.index && this.buffer[current] !== backslashR) { current++; } if (current + 3 >= this.index || this.buffer[current + 1] !== backslashN || this.buffer[current + 2] !== backslashR || this.buffer[current + 3] !== backslashN) { return result; } - let data = this.buffer.toString('utf8', start, current); + const data = this.buffer.toString('utf8', start, current); result = parseInt(data); this.buffer = this.buffer.slice(current + 4); this.index = this.index - (current + 4); @@ -79,7 +79,7 @@ class ProtocolBuffer { if (this.index < length) { return null; } - let result = this.buffer.toString('utf8', 0, length); + const result = this.buffer.toString('utf8', 0, length); let sourceStart = length; while (sourceStart < this.index && (this.buffer[sourceStart] === backslashR || this.buffer[sourceStart] === backslashN)) { sourceStart++; diff --git a/extensions/typescript-language-features/src/typescriptServiceClient.ts b/extensions/typescript-language-features/src/typescriptServiceClient.ts index e4c8c840ec1..629c833b221 100644 --- a/extensions/typescript-language-features/src/typescriptServiceClient.ts +++ b/extensions/typescript-language-features/src/typescriptServiceClient.ts @@ -374,7 +374,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType this.info(`Using tsserver from: ${version.path}`); const apiVersion = version.apiVersion || API.defaultVersion; - let mytoken = ++this.token; + const mytoken = ++this.token; const handle = this.typescriptServerSpawner.spawn(version, this.capabilities, this.configuration, this.pluginManager, this.cancellerFactory, { onFatalError: (command, err) => this.fatalError(command, err), });