Enable preferConst in TS project

This commit is contained in:
Matt Bierner 2020-12-09 17:41:58 -08:00
Родитель 1633404883
Коммит 71fad5aa41
6 изменённых файлов: 14 добавлений и 8 удалений

Просмотреть файл

@ -14,3 +14,4 @@
**/extensions/**/build/** **/extensions/**/build/**
**/extensions/markdown-language-features/media/** **/extensions/markdown-language-features/media/**
**/extensions/typescript-basics/test/colorize-fixtures/** **/extensions/typescript-basics/test/colorize-fixtures/**
**/extensions/typescript-language-features/dist/**

Просмотреть файл

@ -0,0 +1,5 @@
{
"rules": {
"prefer-const": "error"
}
}

Просмотреть файл

@ -533,7 +533,7 @@ class TypeScriptCompletionItemProvider implements vscode.CompletionItemProvider<
let includesPackageJsonImport = false; let includesPackageJsonImport = false;
const items: MyCompletionItem[] = []; const items: MyCompletionItem[] = [];
for (let entry of entries) { for (const entry of entries) {
if (!shouldExcludeCompletionEntry(entry, completionConfiguration)) { if (!shouldExcludeCompletionEntry(entry, completionConfiguration)) {
items.push(new MyCompletionItem(position, document, entry, completionContext, metadata)); items.push(new MyCompletionItem(position, document, entry, completionContext, metadata));
includesPackageJsonImport = !!entry.isPackageJsonImport; includesPackageJsonImport = !!entry.isPackageJsonImport;

Просмотреть файл

@ -73,7 +73,7 @@ class DocumentSemanticTokensProvider implements vscode.DocumentSemanticTokensPro
return null; return null;
} }
let versionBeforeRequest = document.version; const versionBeforeRequest = document.version;
const response = await (this.client as ExperimentalProtocol.IExtendedTypeScriptServiceClient).execute('encodedSemanticClassifications-full', requestArg, token, { const response = await (this.client as ExperimentalProtocol.IExtendedTypeScriptServiceClient).execute('encodedSemanticClassifications-full', requestArg, token, {
cancelOnResourceChange: document.uri cancelOnResourceChange: document.uri
@ -137,7 +137,7 @@ class DocumentSemanticTokensProvider implements vscode.DocumentSemanticTokensPro
function waitForDocumentChangesToEnd(document: vscode.TextDocument) { function waitForDocumentChangesToEnd(document: vscode.TextDocument) {
let version = document.version; let version = document.version;
return new Promise<void>((s) => { return new Promise<void>((s) => {
let iv = setInterval(_ => { const iv = setInterval(_ => {
if (document.version === version) { if (document.version === version) {
clearInterval(iv); clearInterval(iv);
s(); s();

Просмотреть файл

@ -39,7 +39,7 @@ class ProtocolBuffer {
if (this.buffer.length - this.index >= toAppend.length) { if (this.buffer.length - this.index >= toAppend.length) {
toAppend.copy(this.buffer, this.index, 0, toAppend.length); toAppend.copy(this.buffer, this.index, 0, toAppend.length);
} else { } 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) { if (this.index === 0) {
this.buffer = Buffer.allocUnsafe(newSize); this.buffer = Buffer.allocUnsafe(newSize);
toAppend.copy(this.buffer, 0, 0, toAppend.length); toAppend.copy(this.buffer, 0, 0, toAppend.length);
@ -61,14 +61,14 @@ class ProtocolBuffer {
return result; return result;
} }
current += contentLengthSize; current += contentLengthSize;
let start = current; const start = current;
while (current < this.index && this.buffer[current] !== backslashR) { while (current < this.index && this.buffer[current] !== backslashR) {
current++; current++;
} }
if (current + 3 >= this.index || this.buffer[current + 1] !== backslashN || this.buffer[current + 2] !== backslashR || this.buffer[current + 3] !== backslashN) { if (current + 3 >= this.index || this.buffer[current + 1] !== backslashN || this.buffer[current + 2] !== backslashR || this.buffer[current + 3] !== backslashN) {
return result; return result;
} }
let data = this.buffer.toString('utf8', start, current); const data = this.buffer.toString('utf8', start, current);
result = parseInt(data); result = parseInt(data);
this.buffer = this.buffer.slice(current + 4); this.buffer = this.buffer.slice(current + 4);
this.index = this.index - (current + 4); this.index = this.index - (current + 4);
@ -79,7 +79,7 @@ class ProtocolBuffer {
if (this.index < length) { if (this.index < length) {
return null; return null;
} }
let result = this.buffer.toString('utf8', 0, length); const result = this.buffer.toString('utf8', 0, length);
let sourceStart = length; let sourceStart = length;
while (sourceStart < this.index && (this.buffer[sourceStart] === backslashR || this.buffer[sourceStart] === backslashN)) { while (sourceStart < this.index && (this.buffer[sourceStart] === backslashR || this.buffer[sourceStart] === backslashN)) {
sourceStart++; sourceStart++;

Просмотреть файл

@ -374,7 +374,7 @@ export default class TypeScriptServiceClient extends Disposable implements IType
this.info(`Using tsserver from: ${version.path}`); this.info(`Using tsserver from: ${version.path}`);
const apiVersion = version.apiVersion || API.defaultVersion; 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, { const handle = this.typescriptServerSpawner.spawn(version, this.capabilities, this.configuration, this.pluginManager, this.cancellerFactory, {
onFatalError: (command, err) => this.fatalError(command, err), onFatalError: (command, err) => this.fatalError(command, err),
}); });