Skip to content

Commit 1f282f1

Browse files
author
Andy
authored
Fix "noStringLiteral" lint errors (#19310)
1 parent a53d3bb commit 1f282f1

15 files changed

+64
-63
lines changed

Gulpfile.ts

+20-20
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function possiblyQuote(cmd: string) {
8787
}
8888

8989
let useDebugMode = true;
90-
let host = cmdLineOptions["host"];
90+
let host = cmdLineOptions.host;
9191

9292
// Constants
9393
const compilerDirectory = "src/compiler/";
@@ -651,15 +651,15 @@ function restoreSavedNodeEnv() {
651651
}
652652

653653
function runConsoleTests(defaultReporter: string, runInParallel: boolean, done: (e?: any) => void) {
654-
const lintFlag = cmdLineOptions["lint"];
654+
const lintFlag = cmdLineOptions.lint;
655655
cleanTestDirs((err) => {
656656
if (err) { console.error(err); failWithStatus(err, 1); }
657-
let testTimeout = cmdLineOptions["timeout"];
658-
const debug = cmdLineOptions["debug"];
659-
const inspect = cmdLineOptions["inspect"];
660-
const tests = cmdLineOptions["tests"];
661-
const light = cmdLineOptions["light"];
662-
const stackTraceLimit = cmdLineOptions["stackTraceLimit"];
657+
let testTimeout = cmdLineOptions.timeout;
658+
const debug = cmdLineOptions.debug;
659+
const inspect = cmdLineOptions.inspect;
660+
const tests = cmdLineOptions.tests;
661+
const light = cmdLineOptions.light;
662+
const stackTraceLimit = cmdLineOptions.stackTraceLimit;
663663
const testConfigFile = "test.config";
664664
if (fs.existsSync(testConfigFile)) {
665665
fs.unlinkSync(testConfigFile);
@@ -675,7 +675,7 @@ function runConsoleTests(defaultReporter: string, runInParallel: boolean, done:
675675
} while (fs.existsSync(taskConfigsFolder));
676676
fs.mkdirSync(taskConfigsFolder);
677677

678-
workerCount = cmdLineOptions["workers"];
678+
workerCount = cmdLineOptions.workers;
679679
}
680680

681681
if (tests || light || taskConfigsFolder) {
@@ -686,8 +686,8 @@ function runConsoleTests(defaultReporter: string, runInParallel: boolean, done:
686686
testTimeout = 400000;
687687
}
688688

689-
const colors = cmdLineOptions["colors"];
690-
const reporter = cmdLineOptions["reporter"] || defaultReporter;
689+
const colors = cmdLineOptions.colors;
690+
const reporter = cmdLineOptions.reporter || defaultReporter;
691691

692692
// timeout normally isn"t necessary but Travis-CI has been timing out on compiler baselines occasionally
693693
// default timeout is 2sec which really should be enough, but maybe we just need a small amount longer
@@ -875,7 +875,7 @@ function cleanTestDirs(done: (e?: any) => void) {
875875

876876
// used to pass data from jake command line directly to run.js
877877
function writeTestConfigFile(tests: string, light: boolean, taskConfigsFolder?: string, workerCount?: number, stackTraceLimit?: string) {
878-
const testConfigContents = JSON.stringify({ test: tests ? [tests] : undefined, light, workerCount, stackTraceLimit, taskConfigsFolder, noColor: !cmdLineOptions["colors"] });
878+
const testConfigContents = JSON.stringify({ test: tests ? [tests] : undefined, light, workerCount, stackTraceLimit, taskConfigsFolder, noColor: !cmdLineOptions.colors });
879879
console.log("Running tests with config: " + testConfigContents);
880880
fs.writeFileSync("test.config", testConfigContents);
881881
}
@@ -885,8 +885,8 @@ gulp.task("runtests-browser", "Runs the tests using the built run.js file like '
885885
cleanTestDirs((err) => {
886886
if (err) { console.error(err); done(err); process.exit(1); }
887887
host = "node";
888-
const tests = cmdLineOptions["tests"];
889-
const light = cmdLineOptions["light"];
888+
const tests = cmdLineOptions.tests;
889+
const light = cmdLineOptions.light;
890890
const testConfigFile = "test.config";
891891
if (fs.existsSync(testConfigFile)) {
892892
fs.unlinkSync(testConfigFile);
@@ -896,8 +896,8 @@ gulp.task("runtests-browser", "Runs the tests using the built run.js file like '
896896
}
897897

898898
const args = [nodeServerOutFile];
899-
if (cmdLineOptions["browser"]) {
900-
args.push(cmdLineOptions["browser"]);
899+
if (cmdLineOptions.browser) {
900+
args.push(cmdLineOptions.browser);
901901
}
902902
if (tests) {
903903
args.push(JSON.stringify(tests));
@@ -907,13 +907,13 @@ gulp.task("runtests-browser", "Runs the tests using the built run.js file like '
907907
});
908908

909909
gulp.task("generate-code-coverage", "Generates code coverage data via istanbul", ["tests"], (done) => {
910-
const testTimeout = cmdLineOptions["timeout"];
910+
const testTimeout = cmdLineOptions.timeout;
911911
exec("istanbul", ["cover", "node_modules/mocha/bin/_mocha", "--", "-R", "min", "-t", testTimeout.toString(), run], done, done);
912912
});
913913

914914

915915
function getDiffTool() {
916-
const program = process.env["DIFF"];
916+
const program = process.env.DIFF;
917917
if (!program) {
918918
console.error("Add the 'DIFF' environment variable to the path of the program you want to use.");
919919
process.exit(1);
@@ -1034,7 +1034,7 @@ gulp.task(instrumenterJsPath, /*help*/ false, [servicesFile], () => {
10341034
});
10351035

10361036
gulp.task("tsc-instrumented", "Builds an instrumented tsc.js - run with --test=[testname]", ["local", loggedIOJsPath, instrumenterJsPath, servicesFile], (done) => {
1037-
const test = cmdLineOptions["tests"] || "iocapture";
1037+
const test = cmdLineOptions.tests || "iocapture";
10381038
exec(host, [instrumenterJsPath, "record", test, builtLocalCompiler], done, done);
10391039
});
10401040

@@ -1103,7 +1103,7 @@ function spawnLintWorker(files: {path: string}[], callback: (failures: number) =
11031103

11041104
gulp.task("lint", "Runs tslint on the compiler sources. Optional arguments are: --f[iles]=regex", ["build-rules"], () => {
11051105
if (fold.isTravis()) console.log(fold.start("lint"));
1106-
const fileMatcher = cmdLineOptions["files"];
1106+
const fileMatcher = cmdLineOptions.files;
11071107
const files = fileMatcher
11081108
? `src/**/${fileMatcher}`
11091109
: "Gulpfile.ts 'scripts/generateLocalizedDiagnosticMessages.ts' 'scripts/tslint/**/*.ts' 'src/**/*.ts' --exclude src/lib/es5.d.ts --exclude 'src/lib/*.generated.d.ts'";

scripts/generateLocalizedDiagnosticMessages.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ function main(): void {
8484

8585
function xmlObjectToString(o: any) {
8686
const out: any = {};
87-
for (const item of o["LCX"]["Item"][0]["Item"][0]["Item"]) {
88-
let ItemId = item["$"]["ItemId"];
89-
let Val = item["Str"][0]["Tgt"] ? item["Str"][0]["Tgt"][0]["Val"][0] : item["Str"][0]["Val"][0];
87+
for (const item of o.LCX.Item[0].Item[0].Item) {
88+
let ItemId = item.$.ItemId;
89+
let Val = item.Str[0].Tgt ? item.Str[0].Tgt[0].Val[0] : item.Str[0].Val[0];
9090

9191
if (typeof ItemId !== "string" || typeof Val !== "string") {
9292
console.error("Unexpected XML file structure");

src/compiler/commandLineParser.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -1440,9 +1440,9 @@ namespace ts {
14401440

14411441
function getFileNames(): ExpandResult {
14421442
let filesSpecs: ReadonlyArray<string>;
1443-
if (hasProperty(raw, "files") && !isNullOrUndefined(raw["files"])) {
1444-
if (isArray(raw["files"])) {
1445-
filesSpecs = <ReadonlyArray<string>>raw["files"];
1443+
if (hasProperty(raw, "files") && !isNullOrUndefined(raw.files)) {
1444+
if (isArray(raw.files)) {
1445+
filesSpecs = <ReadonlyArray<string>>raw.files;
14461446
if (filesSpecs.length === 0) {
14471447
createCompilerDiagnosticOnlyIfJson(Diagnostics.The_files_list_in_config_file_0_is_empty, configFileName || "tsconfig.json");
14481448
}
@@ -1453,26 +1453,26 @@ namespace ts {
14531453
}
14541454

14551455
let includeSpecs: ReadonlyArray<string>;
1456-
if (hasProperty(raw, "include") && !isNullOrUndefined(raw["include"])) {
1457-
if (isArray(raw["include"])) {
1458-
includeSpecs = <ReadonlyArray<string>>raw["include"];
1456+
if (hasProperty(raw, "include") && !isNullOrUndefined(raw.include)) {
1457+
if (isArray(raw.include)) {
1458+
includeSpecs = <ReadonlyArray<string>>raw.include;
14591459
}
14601460
else {
14611461
createCompilerDiagnosticOnlyIfJson(Diagnostics.Compiler_option_0_requires_a_value_of_type_1, "include", "Array");
14621462
}
14631463
}
14641464

14651465
let excludeSpecs: ReadonlyArray<string>;
1466-
if (hasProperty(raw, "exclude") && !isNullOrUndefined(raw["exclude"])) {
1467-
if (isArray(raw["exclude"])) {
1468-
excludeSpecs = <ReadonlyArray<string>>raw["exclude"];
1466+
if (hasProperty(raw, "exclude") && !isNullOrUndefined(raw.exclude)) {
1467+
if (isArray(raw.exclude)) {
1468+
excludeSpecs = <ReadonlyArray<string>>raw.exclude;
14691469
}
14701470
else {
14711471
createCompilerDiagnosticOnlyIfJson(Diagnostics.Compiler_option_0_requires_a_value_of_type_1, "exclude", "Array");
14721472
}
14731473
}
14741474
else {
1475-
const outDir = raw["compilerOptions"] && raw["compilerOptions"]["outDir"];
1475+
const outDir = raw.compilerOptions && raw.compilerOptions.outDir;
14761476
if (outDir) {
14771477
excludeSpecs = [outDir];
14781478
}
@@ -1591,7 +1591,7 @@ namespace ts {
15911591
const options = convertCompilerOptionsFromJsonWorker(json.compilerOptions, basePath, errors, configFileName);
15921592
// typingOptions has been deprecated and is only supported for backward compatibility purposes.
15931593
// It should be removed in future releases - use typeAcquisition instead.
1594-
const typeAcquisition = convertTypeAcquisitionFromJsonWorker(json["typeAcquisition"] || json["typingOptions"], basePath, errors, configFileName);
1594+
const typeAcquisition = convertTypeAcquisitionFromJsonWorker(json.typeAcquisition || json.typingOptions, basePath, errors, configFileName);
15951595
json.compileOnSave = convertCompileOnSaveOptionFromJson(json, basePath, errors);
15961596
let extendedConfigPath: Path;
15971597

@@ -1748,7 +1748,7 @@ namespace ts {
17481748
if (!hasProperty(jsonOption, compileOnSaveCommandLineOption.name)) {
17491749
return undefined;
17501750
}
1751-
const result = convertJsonOption(compileOnSaveCommandLineOption, jsonOption["compileOnSave"], basePath, errors);
1751+
const result = convertJsonOption(compileOnSaveCommandLineOption, jsonOption.compileOnSave, basePath, errors);
17521752
if (typeof result === "boolean" && result) {
17531753
return result;
17541754
}

src/compiler/core.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ namespace ts {
3333
// Using 'delete' on an object causes V8 to put the object in dictionary mode.
3434
// This disables creation of hidden classes, which are expensive when an object is
3535
// constantly changing shape.
36-
map["__"] = undefined;
37-
delete map["__"];
36+
map.__ = undefined;
37+
delete map.__;
3838

3939
return map;
4040
}

src/compiler/sys.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ namespace ts {
131131
const _os = require("os");
132132
const _crypto = require("crypto");
133133

134-
const useNonPollingWatchers = process.env["TSC_NONPOLLING_WATCHER"];
134+
const useNonPollingWatchers = process.env.TSC_NONPOLLING_WATCHER;
135135

136136
function createWatchedFileSet() {
137137
const dirWatchers = createMap<DirectoryWatcher>();

src/harness/compilerRunner.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ class CompilerBaselineRunner extends RunnerBase {
8080
tsConfigFiles.push(this.createHarnessTestFile(testCaseContent.tsConfigFileUnitData, rootDir, ts.combinePaths(rootDir, tsConfigOptions.configFilePath)));
8181
}
8282
else {
83-
const baseUrl = harnessSettings["baseUrl"];
83+
const baseUrl = harnessSettings.baseUrl;
8484
if (baseUrl !== undefined && !ts.isRootedDiskPath(baseUrl)) {
85-
harnessSettings["baseUrl"] = ts.getNormalizedAbsolutePath(baseUrl, rootDir);
85+
harnessSettings.baseUrl = ts.getNormalizedAbsolutePath(baseUrl, rootDir);
8686
}
8787
}
8888

@@ -94,7 +94,7 @@ class CompilerBaselineRunner extends RunnerBase {
9494
toBeCompiled = [];
9595
otherFiles = [];
9696

97-
if (testCaseContent.settings["noImplicitReferences"] || /require\(/.test(lastUnit.content) || /reference\spath/.test(lastUnit.content)) {
97+
if (testCaseContent.settings.noImplicitReferences || /require\(/.test(lastUnit.content) || /reference\spath/.test(lastUnit.content)) {
9898
toBeCompiled.push(this.createHarnessTestFile(lastUnit, rootDir));
9999
units.forEach(unit => {
100100
if (unit.name !== lastUnit.name) {
@@ -114,7 +114,7 @@ class CompilerBaselineRunner extends RunnerBase {
114114
}
115115

116116
const output = Harness.Compiler.compileFiles(
117-
toBeCompiled, otherFiles, harnessSettings, /*options*/ tsConfigOptions, /*currentDirectory*/ harnessSettings["currentDirectory"]);
117+
toBeCompiled, otherFiles, harnessSettings, /*options*/ tsConfigOptions, /*currentDirectory*/ harnessSettings.currentDirectory);
118118

119119
options = output.options;
120120
result = output.result;

src/harness/fourslash.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3281,7 +3281,7 @@ ${code}
32813281
}
32823282

32833283
function containTSConfigJson(files: FourSlashFile[]): boolean {
3284-
return ts.forEach(files, f => f.fileOptions["Filename"] === "tsconfig.json");
3284+
return ts.forEach(files, f => f.fileOptions.Filename === "tsconfig.json");
32853285
}
32863286

32873287
function getNonFileNameOptionInFileList(files: FourSlashFile[]): string {

src/harness/harness.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -916,8 +916,8 @@ namespace Harness {
916916
if (file.content !== undefined) {
917917
const fileName = ts.normalizePath(file.unitName);
918918
const path = ts.toPath(file.unitName, currentDirectory, getCanonicalFileName);
919-
if (file.fileOptions && file.fileOptions["symlink"]) {
920-
const links = file.fileOptions["symlink"].split(",");
919+
if (file.fileOptions && file.fileOptions.symlink) {
920+
const links = file.fileOptions.symlink.split(",");
921921
for (const link of links) {
922922
const linkPath = ts.toPath(link, currentDirectory, getCanonicalFileName);
923923
realPathMap.set(linkPath, fileName);
@@ -1232,7 +1232,7 @@ namespace Harness {
12321232
if (options.declaration && result.errors.length === 0 && result.declFilesCode.length > 0) {
12331233
ts.forEach(inputFiles, file => addDtsFile(file, declInputFiles));
12341234
ts.forEach(otherFiles, file => addDtsFile(file, declOtherFiles));
1235-
return { declInputFiles, declOtherFiles, harnessSettings, options, currentDirectory: currentDirectory || harnessSettings["currentDirectory"] };
1235+
return { declInputFiles, declOtherFiles, harnessSettings, options, currentDirectory: currentDirectory || harnessSettings.currentDirectory };
12361236
}
12371237

12381238
function addDtsFile(file: TestFile, dtsFiles: TestFile[]) {
@@ -1676,7 +1676,7 @@ namespace Harness {
16761676
}
16771677

16781678
function fileOutput(file: GeneratedFile, harnessSettings: Harness.TestCaseParser.CompilerSettings): string {
1679-
const fileName = harnessSettings["fullEmitPaths"] ? file.fileName : ts.getBaseFileName(file.fileName);
1679+
const fileName = harnessSettings.fullEmitPaths ? file.fileName : ts.getBaseFileName(file.fileName);
16801680
return "//// [" + fileName + "]\r\n" + getByteOrderMarkText(file) + file.code;
16811681
}
16821682

src/harness/typeWriter.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ class TypeWriterWalker {
101101
}
102102
count++;
103103
symbolString += ", ";
104-
if ((declaration as any)["__symbolTestOutputCache"]) {
105-
symbolString += (declaration as any)["__symbolTestOutputCache"];
104+
if ((declaration as any).__symbolTestOutputCache) {
105+
symbolString += (declaration as any).__symbolTestOutputCache;
106106
continue;
107107
}
108108
const declSourceFile = declaration.getSourceFile();
@@ -111,7 +111,7 @@ class TypeWriterWalker {
111111
const isLibFile = /lib(.*)\.d\.ts/i.test(fileName);
112112
const declText = `Decl(${ fileName }, ${ isLibFile ? "--" : declLineAndCharacter.line }, ${ isLibFile ? "--" : declLineAndCharacter.character })`;
113113
symbolString += declText;
114-
(declaration as any)["__symbolTestOutputCache"] = declText;
114+
(declaration as any).__symbolTestOutputCache = declText;
115115
}
116116
}
117117
symbolString += ")";

src/harness/unittests/convertCompilerOptionsFromJson.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace ts {
99
}
1010

1111
function assertCompilerOptionsWithJson(json: any, configFileName: string, expectedResult: { compilerOptions: CompilerOptions, errors: Diagnostic[] }) {
12-
const { options: actualCompilerOptions, errors: actualErrors} = convertCompilerOptionsFromJson(json["compilerOptions"], "/apath/", configFileName);
12+
const { options: actualCompilerOptions, errors: actualErrors} = convertCompilerOptionsFromJson(json.compilerOptions, "/apath/", configFileName);
1313

1414
const parsedCompilerOptions = JSON.stringify(actualCompilerOptions);
1515
const expectedCompilerOptions = JSON.stringify(expectedResult.compilerOptions);
@@ -33,7 +33,7 @@ namespace ts {
3333
assert(!!result.endOfFileToken);
3434
const host: ParseConfigHost = new Utils.MockParseConfigHost("/apath/", true, []);
3535
const { options: actualCompilerOptions, errors: actualParseErrors } = parseJsonSourceFileConfigFileContent(result, host, "/apath/", /*existingOptions*/ undefined, configFileName);
36-
expectedResult.compilerOptions["configFilePath"] = configFileName;
36+
expectedResult.compilerOptions.configFilePath = configFileName;
3737

3838
const parsedCompilerOptions = JSON.stringify(actualCompilerOptions);
3939
const expectedCompilerOptions = JSON.stringify(expectedResult.compilerOptions);

src/harness/unittests/convertTypeAcquisitionFromJson.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace ts {
3232
}
3333

3434
function assertTypeAcquisitionWithJson(json: any, configFileName: string, expectedResult: ExpectedResult) {
35-
const jsonOptions = json["typeAcquisition"] || json["typingOptions"];
35+
const jsonOptions = json.typeAcquisition || json.typingOptions;
3636
const { options: actualTypeAcquisition, errors: actualErrors } = convertTypeAcquisitionFromJson(jsonOptions, "/apath/", configFileName);
3737
verifyAcquisition(actualTypeAcquisition, expectedResult);
3838
verifyErrors(actualErrors, expectedResult);

src/server/editorServices.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1350,10 +1350,10 @@ namespace ts.server {
13501350
const projectOptions: ProjectOptions = {
13511351
files: parsedCommandLine.fileNames,
13521352
compilerOptions: parsedCommandLine.options,
1353-
configHasExtendsProperty: parsedCommandLine.raw["extends"] !== undefined,
1354-
configHasFilesProperty: parsedCommandLine.raw["files"] !== undefined,
1355-
configHasIncludeProperty: parsedCommandLine.raw["include"] !== undefined,
1356-
configHasExcludeProperty: parsedCommandLine.raw["exclude"] !== undefined,
1353+
configHasExtendsProperty: parsedCommandLine.raw.extends !== undefined,
1354+
configHasFilesProperty: parsedCommandLine.raw.files !== undefined,
1355+
configHasIncludeProperty: parsedCommandLine.raw.include !== undefined,
1356+
configHasExcludeProperty: parsedCommandLine.raw.exclude !== undefined,
13571357
wildcardDirectories: createMapFromTemplate(parsedCommandLine.wildcardDirectories),
13581358
typeAcquisition: parsedCommandLine.typeAcquisition,
13591359
compileOnSave: parsedCommandLine.compileOnSave

src/server/server.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ namespace ts.server {
626626
function createLogger() {
627627
const cmdLineLogFileName = findArgument("--logFile");
628628
const cmdLineVerbosity = getLogLevel(findArgument("--logVerbosity"));
629-
const envLogOptions = parseLoggingEnvironmentString(process.env["TSS_LOG"]);
629+
const envLogOptions = parseLoggingEnvironmentString(process.env.TSS_LOG);
630630

631631
const logFileName = cmdLineLogFileName
632632
? stripQuotes(cmdLineLogFileName)

0 commit comments

Comments
 (0)