Skip to content

Commit 5ce8c83

Browse files
committed
prefer-const
1 parent 504b932 commit 5ce8c83

File tree

16 files changed

+50
-53
lines changed

16 files changed

+50
-53
lines changed

.eslintrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
"no-var": "off",
113113
"object-shorthand": "error",
114114
"one-var": "off",
115-
"prefer-const": "off",
115+
"prefer-const": "error",
116116
"prefer-object-spread": "error",
117117
"quote-props": ["error", "consistent-as-needed"],
118118
"quotes": ["error", "double", { "avoidEscape": true, "allowTemplateLiterals": true }],

scripts/authors.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function getKnownAuthorMaps() {
7373
}
7474

7575
function deduplicate<T>(array: T[]): T[] {
76-
let result: T[] = [];
76+
const result: T[] = [];
7777
if (array) {
7878
for (const item of array) {
7979
if (result.indexOf(item) < 0) {

scripts/buildProtocol.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class DeclarationsWalker {
4242
return;
4343
}
4444
this.visitedTypes.push(type);
45-
let s = type.aliasSymbol || type.getSymbol();
45+
const s = type.aliasSymbol || type.getSymbol();
4646
if (!s) {
4747
return;
4848
}
@@ -64,7 +64,7 @@ class DeclarationsWalker {
6464
}
6565
else {
6666
// splice declaration in final d.ts file
67-
let text = decl.getFullText();
67+
const text = decl.getFullText();
6868
this.text += `${text}\n`;
6969
// recursively pull all dependencies into result dts file
7070

scripts/errorCheck.ts

+17-17
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
declare var require: any;
2-
let fs = require("fs");
3-
let async = require("async");
4-
let glob = require("glob");
2+
const fs = require("fs");
3+
const async = require("async");
4+
const glob = require("glob");
55

66
fs.readFile("src/compiler/diagnosticMessages.json", "utf-8", (err, data) => {
77
if (err) {
88
throw err;
99
}
1010

11-
let messages = JSON.parse(data);
12-
let keys = Object.keys(messages);
11+
const messages = JSON.parse(data);
12+
const keys = Object.keys(messages);
1313
console.log("Loaded " + keys.length + " errors");
1414

15-
for (let k of keys) {
15+
for (const k of keys) {
1616
messages[k].seen = false;
1717
}
1818

19-
let errRegex = /\(\d+,\d+\): error TS([^:]+):/g;
19+
const errRegex = /\(\d+,\d+\): error TS([^:]+):/g;
20+
const baseDir = "tests/baselines/reference/";
2021

21-
let baseDir = "tests/baselines/reference/";
2222
fs.readdir(baseDir, (err, files) => {
2323
files = files.filter(f => f.indexOf(".errors.txt") > 0);
24-
let tasks: Array<(callback: () => void) => void> = [];
24+
const tasks: Array<(callback: () => void) => void> = [];
2525
files.forEach(f => tasks.push(done => {
2626
fs.readFile(baseDir + f, "utf-8", (err, baseline) => {
2727
if (err) throw err;
2828

2929
let g: string[];
3030
while (g = errRegex.exec(baseline)) {
31-
var errCode = +g[1];
32-
let msg = keys.filter(k => messages[k].code === errCode)[0];
31+
const errCode = +g[1];
32+
const msg = keys.filter(k => messages[k].code === errCode)[0];
3333
messages[msg].seen = true;
3434
}
3535

@@ -40,7 +40,7 @@ fs.readFile("src/compiler/diagnosticMessages.json", "utf-8", (err, data) => {
4040
async.parallelLimit(tasks, 25, done => {
4141
console.log("== List of errors not present in baselines ==");
4242
let count = 0;
43-
for (let k of keys) {
43+
for (const k of keys) {
4444
if (messages[k].seen !== true) {
4545
console.log(k);
4646
count++;
@@ -52,8 +52,8 @@ fs.readFile("src/compiler/diagnosticMessages.json", "utf-8", (err, data) => {
5252
});
5353

5454
fs.readFile("src/compiler/diagnosticInformationMap.generated.ts", "utf-8", (err, data) => {
55-
let errorRegexp = /\s(\w+): \{ code/g;
56-
let errorNames: string[] = [];
55+
const errorRegexp = /\s(\w+): \{ code/g;
56+
const errorNames: string[] = [];
5757
let errMatch: string[];
5858
while (errMatch = errorRegexp.exec(data)) {
5959
errorNames.push(errMatch[1]);
@@ -62,20 +62,20 @@ fs.readFile("src/compiler/diagnosticInformationMap.generated.ts", "utf-8", (err,
6262
let allSrc = "";
6363
glob("./src/**/*.ts", {}, (err, files) => {
6464
console.log("Reading " + files.length + " source files");
65-
for (let file of files) {
65+
for (const file of files) {
6666
if (file.indexOf("diagnosticInformationMap.generated.ts") > 0) {
6767
continue;
6868
}
6969

70-
let src = fs.readFileSync(file, "utf-8");
70+
const src = fs.readFileSync(file, "utf-8");
7171
allSrc = allSrc + src;
7272
}
7373

7474
console.log("Consumed " + allSrc.length + " characters of source");
7575

7676
let count = 0;
7777
console.log("== List of errors not used in source ==");
78-
for (let errName of errorNames) {
78+
for (const errName of errorNames) {
7979
if (allSrc.indexOf(errName) < 0) {
8080
console.log(errName);
8181
count++;

scripts/importDefinitelyTypedTests/importDefinitelyTypedTests.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function filePathEndsWith(path: string, endingString: string): boolean {
4242
}
4343

4444
function copyFileSync(source: string, destination: string) {
45-
let text = fs.readFileSync(source);
45+
const text = fs.readFileSync(source);
4646
fs.writeFileSync(destination, text);
4747
}
4848

@@ -52,8 +52,8 @@ function importDefinitelyTypedTest(tscPath: string, rwcTestPath: string, testCas
5252
cmd += " @" + responseFile;
5353
}
5454

55-
let testDirectoryName = testCaseName + "_" + Math.floor((Math.random() * 10000) + 1);
56-
let testDirectoryPath = path.join(process.env.temp, testDirectoryName);
55+
const testDirectoryName = testCaseName + "_" + Math.floor((Math.random() * 10000) + 1);
56+
const testDirectoryPath = path.join(process.env.temp, testDirectoryName);
5757
if (fs.existsSync(testDirectoryPath)) {
5858
throw new Error("Could not create test directory");
5959
}
@@ -77,8 +77,8 @@ function importDefinitelyTypedTest(tscPath: string, rwcTestPath: string, testCas
7777
}
7878

7979
// copy generated file to output location
80-
let outputFilePath = path.join(testDirectoryPath, "iocapture0.json");
81-
let testCasePath = path.join(rwcTestPath, "DefinitelyTyped_" + testCaseName + ".json");
80+
const outputFilePath = path.join(testDirectoryPath, "iocapture0.json");
81+
const testCasePath = path.join(rwcTestPath, "DefinitelyTyped_" + testCaseName + ".json");
8282
copyFileSync(outputFilePath, testCasePath);
8383

8484
//console.log("output generated at: " + outputFilePath);
@@ -121,8 +121,8 @@ function importDefinitelyTypedTests(tscPath: string, rwcTestPath: string, defini
121121
throw err;
122122
}
123123

124-
let tsFiles: string[] = [];
125-
let testFiles: string[] = [];
124+
const tsFiles: string[] = [];
125+
const testFiles: string[] = [];
126126
let paramFile: string;
127127

128128
for (const filePath of files.map(f => path.join(directoryPath, f))) {

src/compiler/debug.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
/* @internal */
22
namespace ts {
33
export namespace Debug {
4+
/* eslint-disable prefer-const */
45
export let currentAssertionLevel = AssertionLevel.None;
56
export let isDebugging = false;
7+
/* eslint-enable prefer-const */
68

79
export function shouldAssert(level: AssertionLevel): boolean {
810
return currentAssertionLevel >= level;
@@ -258,4 +260,4 @@ namespace ts {
258260
isDebugInfoEnabled = true;
259261
}
260262
}
261-
}
263+
}

src/compiler/program.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,6 @@ namespace ts {
709709
const { rootNames, options, configFileParsingDiagnostics, projectReferences } = createProgramOptions;
710710
let { oldProgram } = createProgramOptions;
711711

712-
let program: Program;
713712
let processingDefaultLibFiles: SourceFile[] | undefined;
714713
let processingOtherFiles: SourceFile[] | undefined;
715714
let files: SourceFile[];
@@ -905,7 +904,7 @@ namespace ts {
905904
// unconditionally set oldProgram to undefined to prevent it from being captured in closure
906905
oldProgram = undefined;
907906

908-
program = {
907+
const program: Program = {
909908
getRootFileNames: () => rootNames,
910909
getSourceFile,
911910
getSourceFileByPath,

src/compiler/sys.ts

+1
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,7 @@ namespace ts {
635635
};
636636

637637
// TODO: GH#18217 this is used as if it's certainly defined in many places.
638+
// eslint-disable-next-line prefer-const
638639
export let sys: System = (() => {
639640
// NodeJS detects "\uFEFF" at the start of the string and *replaces* it with the actual
640641
// byte order mark from the specified encoding. Using any other byte order mark does

src/compiler/transformers/generators.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1975,12 +1975,11 @@ namespace ts {
19751975
}
19761976

19771977
function cacheExpression(node: Expression): Identifier {
1978-
let temp: Identifier;
19791978
if (isGeneratedIdentifier(node) || getEmitFlags(node) & EmitFlags.HelperName) {
19801979
return <Identifier>node;
19811980
}
19821981

1983-
temp = createTempVariable(hoistVariableDeclaration);
1982+
const temp = createTempVariable(hoistVariableDeclaration);
19841983
emitAssignment(temp, node, /*location*/ node);
19851984
return temp;
19861985
}

src/compiler/utilities.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -4724,7 +4724,7 @@ namespace ts {
47244724
return { span, newLength };
47254725
}
47264726

4727-
export let unchangedTextChangeRange = createTextChangeRange(createTextSpan(0, 0), 0);
4727+
export let unchangedTextChangeRange = createTextChangeRange(createTextSpan(0, 0), 0); // eslint-disable-line prefer-const
47284728

47294729
/**
47304730
* Called to merge all the changes that occurred across several versions of a script snapshot
@@ -7025,6 +7025,7 @@ namespace ts {
70257025
this.skipTrivia = skipTrivia || (pos => pos);
70267026
}
70277027

7028+
// eslint-disable-next-line prefer-const
70287029
export let objectAllocator: ObjectAllocator = {
70297030
getNodeConstructor: () => <any>Node,
70307031
getTokenConstructor: () => <any>Node,

src/harness/harness.ts

+2
Original file line numberDiff line numberDiff line change
@@ -623,8 +623,10 @@ namespace Harness {
623623
) => void;
624624

625625
// Settings
626+
/* eslint-disable prefer-const */
626627
export let userSpecifiedRoot = "";
627628
export let lightMode = false;
629+
/* eslint-enable prefer-const */
628630

629631
/** Functionality for compiling TypeScript code */
630632
export namespace Compiler {

src/harness/harnessLanguageService.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -594,15 +594,13 @@ namespace Harness.LanguageService {
594594
getLanguageService(): ts.LanguageService { return new LanguageServiceShimProxy(this.factory.createLanguageServiceShim(this.host)); }
595595
getClassifier(): ts.Classifier { return new ClassifierShimProxy(this.factory.createClassifierShim(this.host)); }
596596
getPreProcessedFileInfo(fileName: string, fileContents: string): ts.PreProcessedFileInfo {
597-
let shimResult: {
597+
const coreServicesShim = this.factory.createCoreServicesShim(this.host);
598+
const shimResult: {
598599
referencedFiles: ts.ShimsFileReference[];
599600
typeReferenceDirectives: ts.ShimsFileReference[];
600601
importedFiles: ts.ShimsFileReference[];
601602
isLibFile: boolean;
602-
};
603-
604-
const coreServicesShim = this.factory.createCoreServicesShim(this.host);
605-
shimResult = unwrapJSONCallResult(coreServicesShim.getPreProcessedFileInfo(fileName, ts.ScriptSnapshot.fromString(fileContents)));
603+
} = unwrapJSONCallResult(coreServicesShim.getPreProcessedFileInfo(fileName, ts.ScriptSnapshot.fromString(fileContents)));
606604

607605
const convertResult: ts.PreProcessedFileInfo = {
608606
referencedFiles: [],

src/services/services.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ namespace ts {
10121012
return sourceFile;
10131013
}
10141014

1015-
export let disableIncrementalParsing = false;
1015+
export let disableIncrementalParsing = false; // eslint-disable-line prefer-const
10161016

10171017
export function updateLanguageServiceSourceFile(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange | undefined, aggressiveChecks?: boolean): SourceFile {
10181018
// If we were given a text change range, and our version or open-ness changed, then

src/services/shims.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
//
1515

1616
/* @internal */
17-
let debugObjectHost: { CollectGarbage(): void } = (function (this: any) { return this; })();
17+
let debugObjectHost: { CollectGarbage(): void } = (function (this: any) { return this; })(); // eslint-disable-line prefer-const
1818

1919
// We need to use 'null' to interface with the managed side.
2020
/* tslint:disable:no-null-keyword */

src/testRunner/runner.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
let runners: RunnerBase[] = [];
2-
let iterations = 1;
1+
const runners: RunnerBase[] = [];
2+
const iterations = 1;
33

44
function runTests(runners: RunnerBase[]) {
55
for (let i = iterations; i > 0; i--) {
@@ -50,7 +50,7 @@ const mytestconfigFileName = "mytest.config";
5050
const testconfigFileName = "test.config";
5151

5252
const customConfig = tryGetConfig(Harness.IO.args());
53-
let testConfigContent =
53+
const testConfigContent =
5454
customConfig && Harness.IO.fileExists(customConfig)
5555
? Harness.IO.readFile(customConfig)!
5656
: Harness.IO.fileExists(mytestconfigFileName)

src/testRunner/unittests/services/transpile.ts

+4-9
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,11 @@ namespace ts {
77

88
function transpilesCorrectly(name: string, input: string, testSettings: TranspileTestSettings) {
99
describe(name, () => {
10-
let justName: string;
11-
let transpileOptions: TranspileOptions;
12-
let canUseOldTranspile: boolean;
13-
let toBeCompiled: Harness.Compiler.TestFile[];
1410
let transpileResult: TranspileOutput;
1511
let oldTranspileResult: string;
1612
let oldTranspileDiagnostics: Diagnostic[];
1713

18-
transpileOptions = testSettings.options || {};
14+
const transpileOptions: TranspileOptions = testSettings.options || {};
1915
if (!transpileOptions.compilerOptions) {
2016
transpileOptions.compilerOptions = {};
2117
}
@@ -33,13 +29,12 @@ namespace ts {
3329

3430
transpileOptions.reportDiagnostics = true;
3531

36-
justName = "transpile/" + name.replace(/[^a-z0-9\-. ]/ig, "") + (transpileOptions.compilerOptions.jsx ? Extension.Tsx : Extension.Ts);
37-
toBeCompiled = [{
32+
const justName = "transpile/" + name.replace(/[^a-z0-9\-. ]/ig, "") + (transpileOptions.compilerOptions.jsx ? Extension.Tsx : Extension.Ts);
33+
const toBeCompiled: Harness.Compiler.TestFile[] = [{
3834
unitName: transpileOptions.fileName,
3935
content: input
4036
}];
41-
42-
canUseOldTranspile = !transpileOptions.renamedDependencies;
37+
const canUseOldTranspile = !transpileOptions.renamedDependencies;
4338

4439
before(() => {
4540
transpileResult = transpileModule(input, transpileOptions);

0 commit comments

Comments
 (0)