diff --git a/Gulpfile.ts b/Gulpfile.ts index 24ff1f3f3c9fe..fc6d8633d6893 100644 --- a/Gulpfile.ts +++ b/Gulpfile.ts @@ -87,7 +87,7 @@ function possiblyQuote(cmd: string) { } let useDebugMode = true; -let host = cmdLineOptions["host"]; +let host = cmdLineOptions.host; // Constants const compilerDirectory = "src/compiler/"; @@ -636,15 +636,15 @@ function restoreSavedNodeEnv() { } function runConsoleTests(defaultReporter: string, runInParallel: boolean, done: (e?: any) => void) { - const lintFlag = cmdLineOptions["lint"]; + const lintFlag = cmdLineOptions.lint; cleanTestDirs((err) => { if (err) { console.error(err); failWithStatus(err, 1); } - let testTimeout = cmdLineOptions["timeout"]; - const debug = cmdLineOptions["debug"]; - const inspect = cmdLineOptions["inspect"]; - const tests = cmdLineOptions["tests"]; - const light = cmdLineOptions["light"]; - const stackTraceLimit = cmdLineOptions["stackTraceLimit"]; + let testTimeout = cmdLineOptions.timeout; + const debug = cmdLineOptions.debug; + const inspect = cmdLineOptions.inspect; + const tests = cmdLineOptions.tests; + const light = cmdLineOptions.light; + const stackTraceLimit = cmdLineOptions.stackTraceLimit; const testConfigFile = "test.config"; if (fs.existsSync(testConfigFile)) { fs.unlinkSync(testConfigFile); @@ -660,7 +660,7 @@ function runConsoleTests(defaultReporter: string, runInParallel: boolean, done: } while (fs.existsSync(taskConfigsFolder)); fs.mkdirSync(taskConfigsFolder); - workerCount = cmdLineOptions["workers"]; + workerCount = cmdLineOptions.workers; } if (tests || light || taskConfigsFolder) { @@ -671,8 +671,8 @@ function runConsoleTests(defaultReporter: string, runInParallel: boolean, done: testTimeout = 400000; } - const colors = cmdLineOptions["colors"]; - const reporter = cmdLineOptions["reporter"] || defaultReporter; + const colors = cmdLineOptions.colors; + const reporter = cmdLineOptions.reporter || defaultReporter; // timeout normally isn"t necessary but Travis-CI has been timing out on compiler baselines occasionally // default timeout is 2sec which really should be enough, but maybe we just need a small amount longer @@ -860,7 +860,7 @@ function cleanTestDirs(done: (e?: any) => void) { // used to pass data from jake command line directly to run.js function writeTestConfigFile(tests: string, light: boolean, taskConfigsFolder?: string, workerCount?: number, stackTraceLimit?: string) { - const testConfigContents = JSON.stringify({ test: tests ? [tests] : undefined, light, workerCount, stackTraceLimit, taskConfigsFolder, noColor: !cmdLineOptions["colors"] }); + const testConfigContents = JSON.stringify({ test: tests ? [tests] : undefined, light, workerCount, stackTraceLimit, taskConfigsFolder, noColor: !cmdLineOptions.colors }); console.log("Running tests with config: " + testConfigContents); fs.writeFileSync("test.config", testConfigContents); } @@ -870,8 +870,8 @@ gulp.task("runtests-browser", "Runs the tests using the built run.js file like ' cleanTestDirs((err) => { if (err) { console.error(err); done(err); process.exit(1); } host = "node"; - const tests = cmdLineOptions["tests"]; - const light = cmdLineOptions["light"]; + const tests = cmdLineOptions.tests; + const light = cmdLineOptions.light; const testConfigFile = "test.config"; if (fs.existsSync(testConfigFile)) { fs.unlinkSync(testConfigFile); @@ -881,8 +881,8 @@ gulp.task("runtests-browser", "Runs the tests using the built run.js file like ' } const args = [nodeServerOutFile]; - if (cmdLineOptions["browser"]) { - args.push(cmdLineOptions["browser"]); + if (cmdLineOptions.browser) { + args.push(cmdLineOptions.browser); } if (tests) { args.push(JSON.stringify(tests)); @@ -892,13 +892,13 @@ gulp.task("runtests-browser", "Runs the tests using the built run.js file like ' }); gulp.task("generate-code-coverage", "Generates code coverage data via istanbul", ["tests"], (done) => { - const testTimeout = cmdLineOptions["timeout"]; + const testTimeout = cmdLineOptions.timeout; exec("istanbul", ["cover", "node_modules/mocha/bin/_mocha", "--", "-R", "min", "-t", testTimeout.toString(), run], done, done); }); function getDiffTool() { - const program = process.env["DIFF"]; + const program = process.env.DIFF; if (!program) { console.error("Add the 'DIFF' environment variable to the path of the program you want to use."); process.exit(1); @@ -1019,7 +1019,7 @@ gulp.task(instrumenterJsPath, /*help*/ false, [servicesFile], () => { }); gulp.task("tsc-instrumented", "Builds an instrumented tsc.js - run with --test=[testname]", ["local", loggedIOJsPath, instrumenterJsPath, servicesFile], (done) => { - const test = cmdLineOptions["tests"] || "iocapture"; + const test = cmdLineOptions.tests || "iocapture"; exec(host, [instrumenterJsPath, "record", test, builtLocalCompiler], done, done); }); @@ -1088,7 +1088,7 @@ function spawnLintWorker(files: {path: string}[], callback: (failures: number) = gulp.task("lint", "Runs tslint on the compiler sources. Optional arguments are: --f[iles]=regex", ["build-rules"], () => { if (fold.isTravis()) console.log(fold.start("lint")); - const fileMatcher = cmdLineOptions["files"]; + const fileMatcher = cmdLineOptions.files; const files = fileMatcher ? `src/**/${fileMatcher}` : "Gulpfile.ts 'scripts/generateLocalizedDiagnosticMessages.ts' 'scripts/tslint/**/*.ts' 'src/**/*.ts' --exclude src/lib/es5.d.ts --exclude 'src/lib/*.generated.d.ts'"; diff --git a/scripts/generateLocalizedDiagnosticMessages.ts b/scripts/generateLocalizedDiagnosticMessages.ts index edfe957515516..705d746e87ed0 100644 --- a/scripts/generateLocalizedDiagnosticMessages.ts +++ b/scripts/generateLocalizedDiagnosticMessages.ts @@ -46,9 +46,9 @@ function main(): void { function xmlObjectToString(o: any) { const out: any = {}; - for (const item of o["LCX"]["Item"][0]["Item"][0]["Item"]) { - let ItemId = item["$"]["ItemId"]; - let Val = item["Str"][0]["Tgt"] ? item["Str"][0]["Tgt"][0]["Val"][0] : item["Str"][0]["Val"][0]; + for (const item of o.LCX.Item[0].Item[0].Item) { + let ItemId = item.$.ItemId; + let Val = item.Str[0].Tgt ? item.Str[0].Tgt[0].Val[0] : item.Str[0].Val[0]; if (typeof ItemId !== "string" || typeof Val !== "string") { console.error("Unexpected XML file structure"); diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 2eca9dca05c4a..f050c4a5d16ad 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -1440,9 +1440,9 @@ namespace ts { function getFileNames(): ExpandResult { let filesSpecs: ReadonlyArray; - if (hasProperty(raw, "files") && !isNullOrUndefined(raw["files"])) { - if (isArray(raw["files"])) { - filesSpecs = >raw["files"]; + if (hasProperty(raw, "files") && !isNullOrUndefined(raw.files)) { + if (isArray(raw.files)) { + filesSpecs = >raw.files; if (filesSpecs.length === 0) { createCompilerDiagnosticOnlyIfJson(Diagnostics.The_files_list_in_config_file_0_is_empty, configFileName || "tsconfig.json"); } @@ -1453,9 +1453,9 @@ namespace ts { } let includeSpecs: ReadonlyArray; - if (hasProperty(raw, "include") && !isNullOrUndefined(raw["include"])) { - if (isArray(raw["include"])) { - includeSpecs = >raw["include"]; + if (hasProperty(raw, "include") && !isNullOrUndefined(raw.include)) { + if (isArray(raw.include)) { + includeSpecs = >raw.include; } else { createCompilerDiagnosticOnlyIfJson(Diagnostics.Compiler_option_0_requires_a_value_of_type_1, "include", "Array"); @@ -1463,16 +1463,16 @@ namespace ts { } let excludeSpecs: ReadonlyArray; - if (hasProperty(raw, "exclude") && !isNullOrUndefined(raw["exclude"])) { - if (isArray(raw["exclude"])) { - excludeSpecs = >raw["exclude"]; + if (hasProperty(raw, "exclude") && !isNullOrUndefined(raw.exclude)) { + if (isArray(raw.exclude)) { + excludeSpecs = >raw.exclude; } else { createCompilerDiagnosticOnlyIfJson(Diagnostics.Compiler_option_0_requires_a_value_of_type_1, "exclude", "Array"); } } else { - const outDir = raw["compilerOptions"] && raw["compilerOptions"]["outDir"]; + const outDir = raw.compilerOptions && raw.compilerOptions.outDir; if (outDir) { excludeSpecs = [outDir]; } @@ -1591,7 +1591,7 @@ namespace ts { const options = convertCompilerOptionsFromJsonWorker(json.compilerOptions, basePath, errors, configFileName); // typingOptions has been deprecated and is only supported for backward compatibility purposes. // It should be removed in future releases - use typeAcquisition instead. - const typeAcquisition = convertTypeAcquisitionFromJsonWorker(json["typeAcquisition"] || json["typingOptions"], basePath, errors, configFileName); + const typeAcquisition = convertTypeAcquisitionFromJsonWorker(json.typeAcquisition || json.typingOptions, basePath, errors, configFileName); json.compileOnSave = convertCompileOnSaveOptionFromJson(json, basePath, errors); let extendedConfigPath: Path; @@ -1748,7 +1748,7 @@ namespace ts { if (!hasProperty(jsonOption, compileOnSaveCommandLineOption.name)) { return undefined; } - const result = convertJsonOption(compileOnSaveCommandLineOption, jsonOption["compileOnSave"], basePath, errors); + const result = convertJsonOption(compileOnSaveCommandLineOption, jsonOption.compileOnSave, basePath, errors); if (typeof result === "boolean" && result) { return result; } diff --git a/src/compiler/core.ts b/src/compiler/core.ts index d794b8177667a..5ee6aab5d7db0 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -33,8 +33,8 @@ namespace ts { // Using 'delete' on an object causes V8 to put the object in dictionary mode. // This disables creation of hidden classes, which are expensive when an object is // constantly changing shape. - map["__"] = undefined; - delete map["__"]; + map.__ = undefined; + delete map.__; return map; } diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index fa3ec22f586cd..c3dc02fee7ae2 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -131,7 +131,7 @@ namespace ts { const _os = require("os"); const _crypto = require("crypto"); - const useNonPollingWatchers = process.env["TSC_NONPOLLING_WATCHER"]; + const useNonPollingWatchers = process.env.TSC_NONPOLLING_WATCHER; function createWatchedFileSet() { const dirWatchers = createMap(); diff --git a/src/harness/compilerRunner.ts b/src/harness/compilerRunner.ts index a567c1c9e384e..c58accb657cd9 100644 --- a/src/harness/compilerRunner.ts +++ b/src/harness/compilerRunner.ts @@ -80,9 +80,9 @@ class CompilerBaselineRunner extends RunnerBase { tsConfigFiles.push(this.createHarnessTestFile(testCaseContent.tsConfigFileUnitData, rootDir, ts.combinePaths(rootDir, tsConfigOptions.configFilePath))); } else { - const baseUrl = harnessSettings["baseUrl"]; + const baseUrl = harnessSettings.baseUrl; if (baseUrl !== undefined && !ts.isRootedDiskPath(baseUrl)) { - harnessSettings["baseUrl"] = ts.getNormalizedAbsolutePath(baseUrl, rootDir); + harnessSettings.baseUrl = ts.getNormalizedAbsolutePath(baseUrl, rootDir); } } @@ -94,7 +94,7 @@ class CompilerBaselineRunner extends RunnerBase { toBeCompiled = []; otherFiles = []; - if (testCaseContent.settings["noImplicitReferences"] || /require\(/.test(lastUnit.content) || /reference\spath/.test(lastUnit.content)) { + if (testCaseContent.settings.noImplicitReferences || /require\(/.test(lastUnit.content) || /reference\spath/.test(lastUnit.content)) { toBeCompiled.push(this.createHarnessTestFile(lastUnit, rootDir)); units.forEach(unit => { if (unit.name !== lastUnit.name) { @@ -114,7 +114,7 @@ class CompilerBaselineRunner extends RunnerBase { } const output = Harness.Compiler.compileFiles( - toBeCompiled, otherFiles, harnessSettings, /*options*/ tsConfigOptions, /*currentDirectory*/ harnessSettings["currentDirectory"]); + toBeCompiled, otherFiles, harnessSettings, /*options*/ tsConfigOptions, /*currentDirectory*/ harnessSettings.currentDirectory); options = output.options; result = output.result; diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 6724015107974..d88f0e0854e0f 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -3281,7 +3281,7 @@ ${code} } function containTSConfigJson(files: FourSlashFile[]): boolean { - return ts.forEach(files, f => f.fileOptions["Filename"] === "tsconfig.json"); + return ts.forEach(files, f => f.fileOptions.Filename === "tsconfig.json"); } function getNonFileNameOptionInFileList(files: FourSlashFile[]): string { diff --git a/src/harness/harness.ts b/src/harness/harness.ts index a3789eb9ebf8f..ec5f6be92e673 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -916,8 +916,8 @@ namespace Harness { if (file.content !== undefined) { const fileName = ts.normalizePath(file.unitName); const path = ts.toPath(file.unitName, currentDirectory, getCanonicalFileName); - if (file.fileOptions && file.fileOptions["symlink"]) { - const links = file.fileOptions["symlink"].split(","); + if (file.fileOptions && file.fileOptions.symlink) { + const links = file.fileOptions.symlink.split(","); for (const link of links) { const linkPath = ts.toPath(link, currentDirectory, getCanonicalFileName); realPathMap.set(linkPath, fileName); @@ -1232,7 +1232,7 @@ namespace Harness { if (options.declaration && result.errors.length === 0 && result.declFilesCode.length > 0) { ts.forEach(inputFiles, file => addDtsFile(file, declInputFiles)); ts.forEach(otherFiles, file => addDtsFile(file, declOtherFiles)); - return { declInputFiles, declOtherFiles, harnessSettings, options, currentDirectory: currentDirectory || harnessSettings["currentDirectory"] }; + return { declInputFiles, declOtherFiles, harnessSettings, options, currentDirectory: currentDirectory || harnessSettings.currentDirectory }; } function addDtsFile(file: TestFile, dtsFiles: TestFile[]) { @@ -1676,7 +1676,7 @@ namespace Harness { } function fileOutput(file: GeneratedFile, harnessSettings: Harness.TestCaseParser.CompilerSettings): string { - const fileName = harnessSettings["fullEmitPaths"] ? file.fileName : ts.getBaseFileName(file.fileName); + const fileName = harnessSettings.fullEmitPaths ? file.fileName : ts.getBaseFileName(file.fileName); return "//// [" + fileName + "]\r\n" + getByteOrderMarkText(file) + file.code; } diff --git a/src/harness/typeWriter.ts b/src/harness/typeWriter.ts index 559d8ed332ef9..af626f1e548bd 100644 --- a/src/harness/typeWriter.ts +++ b/src/harness/typeWriter.ts @@ -101,8 +101,8 @@ class TypeWriterWalker { } count++; symbolString += ", "; - if ((declaration as any)["__symbolTestOutputCache"]) { - symbolString += (declaration as any)["__symbolTestOutputCache"]; + if ((declaration as any).__symbolTestOutputCache) { + symbolString += (declaration as any).__symbolTestOutputCache; continue; } const declSourceFile = declaration.getSourceFile(); @@ -111,7 +111,7 @@ class TypeWriterWalker { const isLibFile = /lib(.*)\.d\.ts/i.test(fileName); const declText = `Decl(${ fileName }, ${ isLibFile ? "--" : declLineAndCharacter.line }, ${ isLibFile ? "--" : declLineAndCharacter.character })`; symbolString += declText; - (declaration as any)["__symbolTestOutputCache"] = declText; + (declaration as any).__symbolTestOutputCache = declText; } } symbolString += ")"; diff --git a/src/harness/unittests/convertCompilerOptionsFromJson.ts b/src/harness/unittests/convertCompilerOptionsFromJson.ts index 14c0cb7347db3..c55dee26dc460 100644 --- a/src/harness/unittests/convertCompilerOptionsFromJson.ts +++ b/src/harness/unittests/convertCompilerOptionsFromJson.ts @@ -9,7 +9,7 @@ namespace ts { } function assertCompilerOptionsWithJson(json: any, configFileName: string, expectedResult: { compilerOptions: CompilerOptions, errors: Diagnostic[] }) { - const { options: actualCompilerOptions, errors: actualErrors} = convertCompilerOptionsFromJson(json["compilerOptions"], "/apath/", configFileName); + const { options: actualCompilerOptions, errors: actualErrors} = convertCompilerOptionsFromJson(json.compilerOptions, "/apath/", configFileName); const parsedCompilerOptions = JSON.stringify(actualCompilerOptions); const expectedCompilerOptions = JSON.stringify(expectedResult.compilerOptions); @@ -33,7 +33,7 @@ namespace ts { assert(!!result.endOfFileToken); const host: ParseConfigHost = new Utils.MockParseConfigHost("/apath/", true, []); const { options: actualCompilerOptions, errors: actualParseErrors } = parseJsonSourceFileConfigFileContent(result, host, "/apath/", /*existingOptions*/ undefined, configFileName); - expectedResult.compilerOptions["configFilePath"] = configFileName; + expectedResult.compilerOptions.configFilePath = configFileName; const parsedCompilerOptions = JSON.stringify(actualCompilerOptions); const expectedCompilerOptions = JSON.stringify(expectedResult.compilerOptions); diff --git a/src/harness/unittests/convertTypeAcquisitionFromJson.ts b/src/harness/unittests/convertTypeAcquisitionFromJson.ts index 67646de3680bd..5a367edebbb29 100644 --- a/src/harness/unittests/convertTypeAcquisitionFromJson.ts +++ b/src/harness/unittests/convertTypeAcquisitionFromJson.ts @@ -32,7 +32,7 @@ namespace ts { } function assertTypeAcquisitionWithJson(json: any, configFileName: string, expectedResult: ExpectedResult) { - const jsonOptions = json["typeAcquisition"] || json["typingOptions"]; + const jsonOptions = json.typeAcquisition || json.typingOptions; const { options: actualTypeAcquisition, errors: actualErrors } = convertTypeAcquisitionFromJson(jsonOptions, "/apath/", configFileName); verifyAcquisition(actualTypeAcquisition, expectedResult); verifyErrors(actualErrors, expectedResult); diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 47c555cdad93d..f749c27cbbc6d 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -1350,10 +1350,10 @@ namespace ts.server { const projectOptions: ProjectOptions = { files: parsedCommandLine.fileNames, compilerOptions: parsedCommandLine.options, - configHasExtendsProperty: parsedCommandLine.raw["extends"] !== undefined, - configHasFilesProperty: parsedCommandLine.raw["files"] !== undefined, - configHasIncludeProperty: parsedCommandLine.raw["include"] !== undefined, - configHasExcludeProperty: parsedCommandLine.raw["exclude"] !== undefined, + configHasExtendsProperty: parsedCommandLine.raw.extends !== undefined, + configHasFilesProperty: parsedCommandLine.raw.files !== undefined, + configHasIncludeProperty: parsedCommandLine.raw.include !== undefined, + configHasExcludeProperty: parsedCommandLine.raw.exclude !== undefined, wildcardDirectories: createMapFromTemplate(parsedCommandLine.wildcardDirectories), typeAcquisition: parsedCommandLine.typeAcquisition, compileOnSave: parsedCommandLine.compileOnSave diff --git a/src/server/server.ts b/src/server/server.ts index decf614cf8ea7..de02726cd23d9 100644 --- a/src/server/server.ts +++ b/src/server/server.ts @@ -626,7 +626,7 @@ namespace ts.server { function createLogger() { const cmdLineLogFileName = findArgument("--logFile"); const cmdLineVerbosity = getLogLevel(findArgument("--logVerbosity")); - const envLogOptions = parseLoggingEnvironmentString(process.env["TSS_LOG"]); + const envLogOptions = parseLoggingEnvironmentString(process.env.TSS_LOG); const logFileName = cmdLineLogFileName ? stripQuotes(cmdLineLogFileName) diff --git a/src/services/textChanges.ts b/src/services/textChanges.ts index 63cfa64ef07b9..bc3a8e27ef058 100644 --- a/src/services/textChanges.ts +++ b/src/services/textChanges.ts @@ -6,25 +6,25 @@ namespace ts.textChanges { * It can be changed to side-table later if we decide that current design is too invasive. */ function getPos(n: TextRange): number { - const result = (n)["__pos"]; + const result = (n).__pos; Debug.assert(typeof result === "number"); return result; } function setPos(n: TextRange, pos: number): void { Debug.assert(typeof pos === "number"); - (n)["__pos"] = pos; + (n).__pos = pos; } function getEnd(n: TextRange): number { - const result = (n)["__end"]; + const result = (n).__end; Debug.assert(typeof result === "number"); return result; } function setEnd(n: TextRange, end: number): void { Debug.assert(typeof end === "number"); - (n)["__end"] = end; + (n).__end = end; } export interface ConfigurableStart { diff --git a/tslint.json b/tslint.json index d5a182ff0cc15..06f76848fedbb 100644 --- a/tslint.json +++ b/tslint.json @@ -68,6 +68,7 @@ "check-module", "check-separator", "check-type" - ] + ], + "no-string-literal": true } }