From 38652d4cd7edcdc84580a09dd5e9b304f62a2f2b Mon Sep 17 00:00:00 2001 From: Alexander T Date: Thu, 20 Jun 2019 10:51:29 +0300 Subject: [PATCH] no-var --- .eslintrc | 5 +- scripts/authors.ts | 4 +- scripts/bisect-test.ts | 8 +- scripts/buildProtocol.ts | 2 +- scripts/errorCheck.ts | 1 - .../importDefinitelyTypedTests.ts | 2 +- scripts/word2md.ts | 75 ++++++++++--------- src/harness/evaluator.ts | 2 +- src/harness/harness.ts | 9 ++- src/services/utilities.ts | 2 +- 10 files changed, 56 insertions(+), 54 deletions(-) diff --git a/.eslintrc b/.eslintrc index 45fa5ded49b..8fa297ff248 100644 --- a/.eslintrc +++ b/.eslintrc @@ -109,7 +109,7 @@ "no-unsafe-finally": "error", "no-unused-expressions": "error", "no-unused-labels": "error", - "no-var": "off", + "no-var": "error", "object-shorthand": "error", "one-var": "off", "prefer-const": "error", @@ -127,7 +127,8 @@ "overrides": [{ "files": ["src/lib/*.d.ts"], "rules": { - "@typescript-eslint/interface-name-prefix": "off" + "@typescript-eslint/interface-name-prefix": "off", + "no-var": "off" } }] } diff --git a/scripts/authors.ts b/scripts/authors.ts index 9c62da393f7..ba1082c18f3 100644 --- a/scripts/authors.ts +++ b/scripts/authors.ts @@ -167,14 +167,14 @@ namespace Commands { listAuthors.description = "List known and unknown authors for a given spec, e.g. 'node authors.js listAuthors origin/release-2.6..origin/release-2.7'"; } -var args = process.argv.slice(2); +const args = process.argv.slice(2); if (args.length < 1) { console.log("Usage: node authors.js [command]"); console.log("List of commands: "); Object.keys(Commands).forEach(k => console.log(` ${k}: ${(Commands as any)[k].description}`)); } else { - var cmd: Function = (Commands as any)[args[0]]; + const cmd: Function = (Commands as any)[args[0]]; if (cmd === undefined) { console.log("Unknown command " + args[1]); } diff --git a/scripts/bisect-test.ts b/scripts/bisect-test.ts index 312afd43b2e..a3e48b29a81 100644 --- a/scripts/bisect-test.ts +++ b/scripts/bisect-test.ts @@ -6,17 +6,17 @@ import cp = require("child_process"); import fs = require("fs"); // Slice off 'node bisect-test.js' from the command line args -var args = process.argv.slice(2); +const args = process.argv.slice(2); function tsc(tscArgs: string, onExit: (exitCode: number) => void) { - var tsc = cp.exec("node built/local/tsc.js " + tscArgs,() => void 0); + const tsc = cp.exec("node built/local/tsc.js " + tscArgs,() => void 0); tsc.on("close", tscExitCode => { onExit(tscExitCode); }); } // TODO: Rewrite bisect script to handle the post-jake/gulp swap period -var jake = cp.exec("jake clean local", () => void 0); +const jake = cp.exec("jake clean local", () => void 0); jake.on("close", jakeExitCode => { if (jakeExitCode === 0) { // See what we're being asked to do @@ -35,7 +35,7 @@ jake.on("close", jakeExitCode => { else if (args[1] === "emits" || args[1] === "!emits") { tsc(args[0], tscExitCode => { fs.readFile(args[2], "utf-8", (err, data) => { - var doesContains = data.indexOf(args[3]) >= 0; + const doesContains = data.indexOf(args[3]) >= 0; if (doesContains === (args[1] === "emits")) { console.log("Good"); process.exit(0); // Good diff --git a/scripts/buildProtocol.ts b/scripts/buildProtocol.ts index a245bf4d8e8..ad29741287c 100644 --- a/scripts/buildProtocol.ts +++ b/scripts/buildProtocol.ts @@ -20,8 +20,8 @@ class DeclarationsWalker { } static getExtraDeclarations(typeChecker: ts.TypeChecker, protocolFile: ts.SourceFile): string { + const walker = new DeclarationsWalker(typeChecker, protocolFile); let text = "declare namespace ts.server.protocol {\n"; - var walker = new DeclarationsWalker(typeChecker, protocolFile); walker.visitTypeNodes(protocolFile); text = walker.text ? `declare namespace ts.server.protocol {\n${walker.text}}` diff --git a/scripts/errorCheck.ts b/scripts/errorCheck.ts index 430c5f6483f..8c367d9d0c1 100644 --- a/scripts/errorCheck.ts +++ b/scripts/errorCheck.ts @@ -1,4 +1,3 @@ -declare var require: any; const fs = require("fs"); const async = require("async"); const glob = require("glob"); diff --git a/scripts/importDefinitelyTypedTests/importDefinitelyTypedTests.ts b/scripts/importDefinitelyTypedTests/importDefinitelyTypedTests.ts index f58215c2612..00caf35f84b 100644 --- a/scripts/importDefinitelyTypedTests/importDefinitelyTypedTests.ts +++ b/scripts/importDefinitelyTypedTests/importDefinitelyTypedTests.ts @@ -7,7 +7,7 @@ interface Map { [key: string]: T; } -declare var process: { +declare let process: { argv: string[]; env: Map; exit(exitCode?: number): void; diff --git a/scripts/word2md.ts b/scripts/word2md.ts index d2bcc437d24..0d2b5e0feaf 100644 --- a/scripts/word2md.ts +++ b/scripts/word2md.ts @@ -130,13 +130,13 @@ namespace Word { } } -var sys = (function () { - var fileStream = new ActiveXObject("ADODB.Stream"); - fileStream.Type = 2 /*text*/; - var binaryStream = new ActiveXObject("ADODB.Stream"); - binaryStream.Type = 1 /*binary*/; - var args: string[] = []; - for (var i = 0; i < WScript.Arguments.length; i++) { +const sys = (function () { + const fileStream = new ActiveXObject("ADODB.Stream"); + fileStream.Type = 2 /* text */; + const binaryStream = new ActiveXObject("ADODB.Stream"); + binaryStream.Type = 1 /* binary */; + const args: string[] = []; + for (let i = 0; i < WScript.Arguments.length; i++) { args[i] = WScript.Arguments.Item(i); } return { @@ -176,17 +176,17 @@ interface FindReplaceOptions { function convertDocumentToMarkdown(doc: Word.Document): string { - var result = ""; - var lastStyle: string; - var lastInTable: boolean; - var tableColumnCount: number; - var tableCellIndex: number; - var columnAlignment: number[] = []; + const columnAlignment: number[] = []; + let tableColumnCount: number; + let tableCellIndex: number; + let lastInTable: boolean; + let lastStyle: string; + let result = ""; function setProperties(target: any, properties: any) { - for (var name in properties) { + for (const name in properties) { if (properties.hasOwnProperty(name)) { - var value = properties[name]; + const value = properties[name]; if (typeof value === "object") { setProperties(target[name], value); } @@ -198,10 +198,10 @@ function convertDocumentToMarkdown(doc: Word.Document): string { } function findReplace(findText: string, findOptions: FindReplaceOptions, replaceText: string, replaceOptions: FindReplaceOptions) { - var find = doc.range().find; + const find = doc.range().find; find.clearFormatting(); setProperties(find, findOptions); - var replace = find.replacement; + const replace = find.replacement; replace.clearFormatting(); setProperties(replace, replaceOptions); find.execute(findText, @@ -219,12 +219,12 @@ function convertDocumentToMarkdown(doc: Word.Document): string { } function fixHyperlinks() { - var count = doc.hyperlinks.count; - for (var i = 0; i < count; i++) { - var hyperlink = doc.hyperlinks.item(i + 1); - var address = hyperlink.address; + const count = doc.hyperlinks.count; + for (let i = 0; i < count; i++) { + const hyperlink = doc.hyperlinks.item(i + 1); + const address = hyperlink.address; if (address && address.length > 0) { - var textToDisplay = hyperlink.textToDisplay; + const textToDisplay = hyperlink.textToDisplay; hyperlink.textToDisplay = "[" + textToDisplay + "](" + address + ")"; } } @@ -235,7 +235,7 @@ function convertDocumentToMarkdown(doc: Word.Document): string { } function writeTableHeader() { - for (var i = 0; i < tableColumnCount - 1; i++) { + for (let i = 0; i < tableColumnCount - 1; i++) { switch (columnAlignment[i]) { case 1: write("|:---:"); @@ -251,7 +251,7 @@ function convertDocumentToMarkdown(doc: Word.Document): string { } function trimEndFormattingMarks(text: string) { - var i = text.length; + let i = text.length; while (i > 0 && text.charCodeAt(i - 1) < 0x20) i--; return text.substr(0, i); } @@ -271,12 +271,13 @@ function convertDocumentToMarkdown(doc: Word.Document): string { function writeParagraph(p: Word.Paragraph) { - var range = p.range; - var text = range.text; - var style = p.style.nameLocal; - var inTable = range.tables.count > 0; - var level = 1; - var sectionBreak = text.indexOf("\x0C") >= 0; + const range = p.range; + const inTable = range.tables.count > 0; + const sectionBreak = range.text.indexOf("\x0C") >= 0; + + let level = 1; + let style = p.style.nameLocal; + let text = range.text; text = trimEndFormattingMarks(text); if (text === "/") { @@ -285,7 +286,7 @@ function convertDocumentToMarkdown(doc: Word.Document): string { // hidden text and, if so, emit that instead. The hidden text is assumed to // contain an appropriate markdown image link. range.textRetrievalMode.includeHiddenText = true; - var fullText = range.text; + const fullText = range.text; range.textRetrievalMode.includeHiddenText = false; if (text !== fullText) { text = "  " + fullText.substr(1); @@ -307,7 +308,7 @@ function convertDocumentToMarkdown(doc: Word.Document): string { case "Heading": case "Appendix": - var section = range.listFormat.listString; + const section = range.listFormat.listString; write("####".substr(0, level) + ' ' + section + " " + text + "\n\n"); break; @@ -358,7 +359,7 @@ function convertDocumentToMarkdown(doc: Word.Document): string { break; case "TOC": - var strings = text.split("\t"); + const strings = text.split("\t"); write(" ".substr(0, level * 2 - 2) + "* [" + strings[0] + " " + strings[1] + "](#" + strings[0] + ")\n"); break; } @@ -371,11 +372,11 @@ function convertDocumentToMarkdown(doc: Word.Document): string { } function writeDocument() { - var title = doc.builtInDocumentProperties.item(1) + ""; + const title = doc.builtInDocumentProperties.item(1) + ""; if (title.length) { write("# " + title + "\n\n"); } - for (var p = doc.paragraphs.first; p; p = p.next()) { + for (let p = doc.paragraphs.first; p; p = p.next()) { writeParagraph(p); } writeBlockEnd(); @@ -412,8 +413,8 @@ function main(args: string[]) { sys.write("Syntax: word2md \n"); return; } - var app: Word.Application = sys.createObject("Word.Application"); - var doc = app.documents.open(args[0]); + const app: Word.Application = sys.createObject("Word.Application"); + const doc = app.documents.open(args[0]); sys.writeFile(args[1], convertDocumentToMarkdown(doc)); doc.close(/* saveChanges */ false); app.quit(); diff --git a/src/harness/evaluator.ts b/src/harness/evaluator.ts index 32314d1dbd8..7471606da22 100644 --- a/src/harness/evaluator.ts +++ b/src/harness/evaluator.ts @@ -1,5 +1,5 @@ namespace evaluator { - declare var Symbol: SymbolConstructor; + declare let Symbol: SymbolConstructor; const sourceFile = vpath.combine(vfs.srcFolder, "source.ts"); diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 1da710ecc35..84c4555c080 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -1,9 +1,9 @@ // Block scoped definitions work poorly for global variables, temporarily enable var -/* tslint:disable:no-var-keyword */ +/* eslint-disable no-var */ // this will work in the browser via browserify -var _chai: typeof chai = require("chai"); -var assert: typeof _chai.assert = _chai.assert; +const _chai: typeof chai = require("chai"); +const assert: typeof _chai.assert = _chai.assert; { // chai's builtin `assert.isFalse` is featureful but slow - we don't use those features, // so we'll just overwrite it as an alterative to migrating a bunch of code off of chai @@ -32,6 +32,7 @@ var global: NodeJS.Global = Function("return this").call(undefined); // eslint-d declare var window: {}; declare var XMLHttpRequest: new() => XMLHttpRequest; + interface XMLHttpRequest { readonly readyState: number; readonly responseText: string; @@ -44,7 +45,7 @@ interface XMLHttpRequest { getResponseHeader(header: string): string | null; overrideMimeType(mime: string): void; } -/* tslint:enable:no-var-keyword prefer-const */ +/* eslint-enable no-var */ namespace Utils { export function encodeString(s: string): string { diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 35fca7f0e65..a3d0f154ea3 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -6,7 +6,7 @@ interface PromiseConstructor { all(values: (T | PromiseLike)[]): Promise; } /* @internal */ -declare var Promise: PromiseConstructor; +declare let Promise: PromiseConstructor; // These utilities are common to multiple language service features. /* @internal */