From 4b2aed7bb27be82d9ef92ce71401b9a6cc3f0c2a Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Thu, 4 Oct 2018 14:04:23 -0700 Subject: [PATCH] let -> const --- build/lib/bundle.ts | 142 +++++++++--------- build/lib/compilation.ts | 2 +- build/lib/extensions.ts | 10 +- build/lib/nls.ts | 4 +- build/lib/stats.ts | 8 +- build/lib/test/i18n.test.ts | 2 +- build/lib/tslint/layeringRule.ts | 4 +- .../lib/tslint/noUnexternalizedStringsRule.ts | 30 ++-- 8 files changed, 101 insertions(+), 101 deletions(-) diff --git a/build/lib/bundle.ts b/build/lib/bundle.ts index e6ff3d85e3f..b83e4637892 100644 --- a/build/lib/bundle.ts +++ b/build/lib/bundle.ts @@ -98,12 +98,12 @@ export interface ILoaderConfig { * Bundle `entryPoints` given config `config`. */ export function bundle(entryPoints: IEntryPoint[], config: ILoaderConfig, callback: (err: any, result: IBundleResult | null) => void): void { - let entryPointsMap: IEntryPointMap = {}; + const entryPointsMap: IEntryPointMap = {}; entryPoints.forEach((module: IEntryPoint) => { entryPointsMap[module.name] = module; }); - let allMentionedModulesMap: { [modules: string]: boolean; } = {}; + const allMentionedModulesMap: { [modules: string]: boolean; } = {}; entryPoints.forEach((module: IEntryPoint) => { allMentionedModulesMap[module.name] = true; (module.include || []).forEach(function (includedModule) { @@ -128,15 +128,15 @@ export function bundle(entryPoints: IEntryPoint[], config: ILoaderConfig, callba loader.config(config); loader(['require'], (localRequire: any) => { - let resolvePath = (path: string) => { - let r = localRequire.toUrl(path); + const resolvePath = (path: string) => { + const r = localRequire.toUrl(path); if (!/\.js/.test(r)) { return r + '.js'; } return r; }; - for (let moduleId in entryPointsMap) { - let entryPoint = entryPointsMap[moduleId]; + for (const moduleId in entryPointsMap) { + const entryPoint = entryPointsMap[moduleId]; if (entryPoint.append) { entryPoint.append = entryPoint.append.map(resolvePath); } @@ -147,9 +147,9 @@ export function bundle(entryPoints: IEntryPoint[], config: ILoaderConfig, callba }); loader(Object.keys(allMentionedModulesMap), () => { - let modules = loader.getBuildInfo(); - let partialResult = emitEntryPoints(modules, entryPointsMap); - let cssInlinedResources = loader('vs/css').getInlinedResources(); + const modules = loader.getBuildInfo(); + const partialResult = emitEntryPoints(modules, entryPointsMap); + const cssInlinedResources = loader('vs/css').getInlinedResources(); callback(null, { files: partialResult.files, cssInlinedResources: cssInlinedResources, @@ -159,45 +159,45 @@ export function bundle(entryPoints: IEntryPoint[], config: ILoaderConfig, callba } function emitEntryPoints(modules: IBuildModuleInfo[], entryPoints: IEntryPointMap): IPartialBundleResult { - let modulesMap: IBuildModuleInfoMap = {}; + const modulesMap: IBuildModuleInfoMap = {}; modules.forEach((m: IBuildModuleInfo) => { modulesMap[m.id] = m; }); - let modulesGraph: IGraph = {}; + const modulesGraph: IGraph = {}; modules.forEach((m: IBuildModuleInfo) => { modulesGraph[m.id] = m.dependencies; }); - let sortedModules = topologicalSort(modulesGraph); + const sortedModules = topologicalSort(modulesGraph); let result: IConcatFile[] = []; - let usedPlugins: IPluginMap = {}; - let bundleData: IBundleData = { + const usedPlugins: IPluginMap = {}; + const bundleData: IBundleData = { graph: modulesGraph, bundles: {} }; Object.keys(entryPoints).forEach((moduleToBundle: string) => { - let info = entryPoints[moduleToBundle]; - let rootNodes = [moduleToBundle].concat(info.include || []); - let allDependencies = visit(rootNodes, modulesGraph); - let excludes: string[] = ['require', 'exports', 'module'].concat(info.exclude || []); + const info = entryPoints[moduleToBundle]; + const rootNodes = [moduleToBundle].concat(info.include || []); + const allDependencies = visit(rootNodes, modulesGraph); + const excludes: string[] = ['require', 'exports', 'module'].concat(info.exclude || []); excludes.forEach((excludeRoot: string) => { - let allExcludes = visit([excludeRoot], modulesGraph); + const allExcludes = visit([excludeRoot], modulesGraph); Object.keys(allExcludes).forEach((exclude: string) => { delete allDependencies[exclude]; }); }); - let includedModules = sortedModules.filter((module: string) => { + const includedModules = sortedModules.filter((module: string) => { return allDependencies[module]; }); bundleData.bundles[moduleToBundle] = includedModules; - let res = emitEntryPoint( + const res = emitEntryPoint( modulesMap, modulesGraph, moduleToBundle, @@ -208,15 +208,15 @@ function emitEntryPoints(modules: IBuildModuleInfo[], entryPoints: IEntryPointMa ); result = result.concat(res.files); - for (let pluginName in res.usedPlugins) { + for (const pluginName in res.usedPlugins) { usedPlugins[pluginName] = usedPlugins[pluginName] || res.usedPlugins[pluginName]; } }); Object.keys(usedPlugins).forEach((pluginName: string) => { - let plugin = usedPlugins[pluginName]; + const plugin = usedPlugins[pluginName]; if (typeof plugin.finishBuild === 'function') { - let write = (filename: string, contents: string) => { + const write = (filename: string, contents: string) => { result.push({ dest: filename, sources: [{ @@ -237,8 +237,8 @@ function emitEntryPoints(modules: IBuildModuleInfo[], entryPoints: IEntryPointMa } function extractStrings(destFiles: IConcatFile[]): IConcatFile[] { - let parseDefineCall = (moduleMatch: string, depsMatch: string) => { - let module = moduleMatch.replace(/^"|"$/g, ''); + const parseDefineCall = (moduleMatch: string, depsMatch: string) => { + const module = moduleMatch.replace(/^"|"$/g, ''); let deps = depsMatch.split(','); deps = deps.map((dep) => { dep = dep.trim(); @@ -246,7 +246,7 @@ function extractStrings(destFiles: IConcatFile[]): IConcatFile[] { dep = dep.replace(/^'|'$/g, ''); let prefix: string | null = null; let _path: string | null = null; - let pieces = dep.split('!'); + const pieces = dep.split('!'); if (pieces.length > 1) { prefix = pieces[0] + '!'; _path = pieces[1]; @@ -256,7 +256,7 @@ function extractStrings(destFiles: IConcatFile[]): IConcatFile[] { } if (/^\.\//.test(_path) || /^\.\.\//.test(_path)) { - let res = path.join(path.dirname(module), _path).replace(/\\/g, '/'); + const res = path.join(path.dirname(module), _path).replace(/\\/g, '/'); return prefix + res; } return prefix + _path; @@ -276,33 +276,33 @@ function extractStrings(destFiles: IConcatFile[]): IConcatFile[] { } // Do one pass to record the usage counts for each module id - let useCounts: { [moduleId: string]: number; } = {}; + const useCounts: { [moduleId: string]: number; } = {}; destFile.sources.forEach((source) => { - let matches = source.contents.match(/define\(("[^"]+"),\s*\[(((, )?("|')[^"']+("|'))+)\]/); + const matches = source.contents.match(/define\(("[^"]+"),\s*\[(((, )?("|')[^"']+("|'))+)\]/); if (!matches) { return; } - let defineCall = parseDefineCall(matches[1], matches[2]); + const defineCall = parseDefineCall(matches[1], matches[2]); useCounts[defineCall.module] = (useCounts[defineCall.module] || 0) + 1; defineCall.deps.forEach((dep) => { useCounts[dep] = (useCounts[dep] || 0) + 1; }); }); - let sortedByUseModules = Object.keys(useCounts); + const sortedByUseModules = Object.keys(useCounts); sortedByUseModules.sort((a, b) => { return useCounts[b] - useCounts[a]; }); - let replacementMap: { [moduleId: string]: number; } = {}; + const replacementMap: { [moduleId: string]: number; } = {}; sortedByUseModules.forEach((module, index) => { replacementMap[module] = index; }); destFile.sources.forEach((source) => { source.contents = source.contents.replace(/define\(("[^"]+"),\s*\[(((, )?("|')[^"']+("|'))+)\]/, (_, moduleMatch, depsMatch) => { - let defineCall = parseDefineCall(moduleMatch, depsMatch); + const defineCall = parseDefineCall(moduleMatch, depsMatch); return `define(__m[${replacementMap[defineCall.module]}/*${defineCall.module}*/], __M([${defineCall.deps.map(dep => replacementMap[dep] + '/*' + dep + '*/').join(',')}])`; }); }); @@ -332,7 +332,7 @@ function extractStrings(destFiles: IConcatFile[]): IConcatFile[] { function removeDuplicateTSBoilerplate(destFiles: IConcatFile[]): IConcatFile[] { // Taken from typescript compiler => emitFiles - let BOILERPLATE = [ + const BOILERPLATE = [ { start: /^var __extends/, end: /^}\)\(\);$/ }, { start: /^var __assign/, end: /^};$/ }, { start: /^var __decorate/, end: /^};$/ }, @@ -343,14 +343,14 @@ function removeDuplicateTSBoilerplate(destFiles: IConcatFile[]): IConcatFile[] { ]; destFiles.forEach((destFile) => { - let SEEN_BOILERPLATE: boolean[] = []; + const SEEN_BOILERPLATE: boolean[] = []; destFile.sources.forEach((source) => { - let lines = source.contents.split(/\r\n|\n|\r/); - let newLines: string[] = []; + const lines = source.contents.split(/\r\n|\n|\r/); + const newLines: string[] = []; let IS_REMOVING_BOILERPLATE = false, END_BOILERPLATE: RegExp; for (let i = 0; i < lines.length; i++) { - let line = lines[i]; + const line = lines[i]; if (IS_REMOVING_BOILERPLATE) { newLines.push(''); if (END_BOILERPLATE!.test(line)) { @@ -358,7 +358,7 @@ function removeDuplicateTSBoilerplate(destFiles: IConcatFile[]): IConcatFile[] { } } else { for (let j = 0; j < BOILERPLATE.length; j++) { - let boilerplate = BOILERPLATE[j]; + const boilerplate = BOILERPLATE[j]; if (boilerplate.start.test(line)) { if (SEEN_BOILERPLATE[j]) { IS_REMOVING_BOILERPLATE = true; @@ -403,14 +403,14 @@ function emitEntryPoint( if (!dest) { dest = entryPoint + '.js'; } - let mainResult: IConcatFile = { + const mainResult: IConcatFile = { sources: [], dest: dest }, results: IConcatFile[] = [mainResult]; - let usedPlugins: IPluginMap = {}; - let getLoaderPlugin = (pluginName: string): ILoaderPlugin => { + const usedPlugins: IPluginMap = {}; + const getLoaderPlugin = (pluginName: string): ILoaderPlugin => { if (!usedPlugins[pluginName]) { usedPlugins[pluginName] = modulesMap[pluginName].exports; } @@ -418,22 +418,22 @@ function emitEntryPoint( }; includedModules.forEach((c: string) => { - let bangIndex = c.indexOf('!'); + const bangIndex = c.indexOf('!'); if (bangIndex >= 0) { - let pluginName = c.substr(0, bangIndex); - let plugin = getLoaderPlugin(pluginName); + const pluginName = c.substr(0, bangIndex); + const plugin = getLoaderPlugin(pluginName); mainResult.sources.push(emitPlugin(entryPoint, plugin, pluginName, c.substr(bangIndex + 1))); return; } - let module = modulesMap[c]; + const module = modulesMap[c]; if (module.path === 'empty:') { return; } - let contents = readFileAndRemoveBOM(module.path); + const contents = readFileAndRemoveBOM(module.path); if (module.shim) { mainResult.sources.push(emitShimmedModule(c, deps[c], module.shim, module.path, contents)); @@ -443,14 +443,14 @@ function emitEntryPoint( }); Object.keys(usedPlugins).forEach((pluginName: string) => { - let plugin = usedPlugins[pluginName]; + const plugin = usedPlugins[pluginName]; if (typeof plugin.writeFile === 'function') { - let req: ILoaderPluginReqFunc = (() => { + const req: ILoaderPluginReqFunc = (() => { throw new Error('no-no!'); }); req.toUrl = something => something; - let write = (filename: string, contents: string) => { + const write = (filename: string, contents: string) => { results.push({ dest: filename, sources: [{ @@ -463,16 +463,16 @@ function emitEntryPoint( } }); - let toIFile = (path: string): IFile => { - let contents = readFileAndRemoveBOM(path); + const toIFile = (path: string): IFile => { + const contents = readFileAndRemoveBOM(path); return { path: path, contents: contents }; }; - let toPrepend = (prepend || []).map(toIFile); - let toAppend = (append || []).map(toIFile); + const toPrepend = (prepend || []).map(toIFile); + const toAppend = (append || []).map(toIFile); mainResult.sources = toPrepend.concat(mainResult.sources).concat(toAppend); @@ -495,7 +495,7 @@ function readFileAndRemoveBOM(path: string): string { function emitPlugin(entryPoint: string, plugin: ILoaderPlugin, pluginName: string, moduleName: string): IFile { let result = ''; if (typeof plugin.write === 'function') { - let write: ILoaderPluginWriteFunc = ((what: string) => { + const write: ILoaderPluginWriteFunc = ((what: string) => { result += what; }); write.getEntryPoint = () => { @@ -516,12 +516,12 @@ function emitPlugin(entryPoint: string, plugin: ILoaderPlugin, pluginName: strin function emitNamedModule(moduleId: string, defineCallPosition: IPosition, path: string, contents: string): IFile { // `defineCallPosition` is the position in code: |define() - let defineCallOffset = positionToOffset(contents, defineCallPosition.line, defineCallPosition.col); + const defineCallOffset = positionToOffset(contents, defineCallPosition.line, defineCallPosition.col); // `parensOffset` is the position in code: define|() - let parensOffset = contents.indexOf('(', defineCallOffset); + const parensOffset = contents.indexOf('(', defineCallOffset); - let insertStr = '"' + moduleId + '", '; + const insertStr = '"' + moduleId + '", '; return { path: path, @@ -530,8 +530,8 @@ function emitNamedModule(moduleId: string, defineCallPosition: IPosition, path: } function emitShimmedModule(moduleId: string, myDeps: string[], factory: string, path: string, contents: string): IFile { - let strDeps = (myDeps.length > 0 ? '"' + myDeps.join('", "') + '"' : ''); - let strDefine = 'define("' + moduleId + '", [' + strDeps + '], ' + factory + ');'; + const strDeps = (myDeps.length > 0 ? '"' + myDeps.join('", "') + '"' : ''); + const strDefine = 'define("' + moduleId + '", [' + strDeps + '], ' + factory + ');'; return { path: path, contents: contents + '\n;\n' + strDefine @@ -546,8 +546,8 @@ function positionToOffset(str: string, desiredLine: number, desiredCol: number): return desiredCol - 1; } - let line = 1, - lastNewLineOffset = -1; + let line = 1; + let lastNewLineOffset = -1; do { if (desiredLine === line) { @@ -565,16 +565,16 @@ function positionToOffset(str: string, desiredLine: number, desiredCol: number): * Return a set of reachable nodes in `graph` starting from `rootNodes` */ function visit(rootNodes: string[], graph: IGraph): INodeSet { - let result: INodeSet = {}, - queue = rootNodes; + const result: INodeSet = {}; + const queue = rootNodes; rootNodes.forEach((node) => { result[node] = true; }); while (queue.length > 0) { - let el = queue.shift(); - let myEdges = graph[el!] || []; + const el = queue.shift(); + const myEdges = graph[el!] || []; myEdges.forEach((toNode) => { if (!result[toNode]) { result[toNode] = true; @@ -591,7 +591,7 @@ function visit(rootNodes: string[], graph: IGraph): INodeSet { */ function topologicalSort(graph: IGraph): string[] { - let allNodes: INodeSet = {}, + const allNodes: INodeSet = {}, outgoingEdgeCount: { [node: string]: number; } = {}, inverseEdges: IGraph = {}; @@ -609,7 +609,7 @@ function topologicalSort(graph: IGraph): string[] { }); // https://en.wikipedia.org/wiki/Topological_sorting - let S: string[] = [], + const S: string[] = [], L: string[] = []; Object.keys(allNodes).forEach((node: string) => { @@ -623,10 +623,10 @@ function topologicalSort(graph: IGraph): string[] { // Ensure the exact same order all the time with the same inputs S.sort(); - let n: string = S.shift()!; + const n: string = S.shift()!; L.push(n); - let myInverseEdges = inverseEdges[n] || []; + const myInverseEdges = inverseEdges[n] || []; myInverseEdges.forEach((m: string) => { outgoingEdgeCount[m]--; if (outgoingEdgeCount[m] === 0) { diff --git a/build/lib/compilation.ts b/build/lib/compilation.ts index 27bce9ff38c..e945859bc56 100644 --- a/build/lib/compilation.ts +++ b/build/lib/compilation.ts @@ -135,7 +135,7 @@ function monacodtsTask(out: string, isWatch: boolean): NodeJS.ReadWriteStream { }); const inputFiles: { [file: string]: string; } = {}; - for (let filePath in neededFiles) { + for (const filePath in neededFiles) { if (/\bsrc(\/|\\)vs\b/.test(filePath)) { // This file is needed from source => simply read it now inputFiles[filePath] = fs.readFileSync(filePath).toString(); diff --git a/build/lib/extensions.ts b/build/lib/extensions.ts index 18020bb63ad..7d3bc6630d1 100644 --- a/build/lib/extensions.ts +++ b/build/lib/extensions.ts @@ -35,11 +35,11 @@ function fromLocal(extensionPath: string, sourceMappingURLBase?: string): Stream } function fromLocalWebpack(extensionPath: string, sourceMappingURLBase: string | undefined): Stream { - let result = es.through(); + const result = es.through(); - let packagedDependencies: string[] = []; - let packageJsonConfig = require(path.join(extensionPath, 'package.json')); - let webpackRootConfig = require(path.join(extensionPath, 'extension.webpack.config.js')); + const packagedDependencies: string[] = []; + const packageJsonConfig = require(path.join(extensionPath, 'package.json')); + const webpackRootConfig = require(path.join(extensionPath, 'extension.webpack.config.js')); for (const key in webpackRootConfig.externals) { if (key in packageJsonConfig.dependencies) { packagedDependencies.push(key); @@ -107,7 +107,7 @@ function fromLocalWebpack(extensionPath: string, sourceMappingURLBase: string | ...require(webpackConfigPath), ...{ mode: 'production' } }; - let relativeOutputPath = path.relative(extensionPath, webpackConfig.output.path); + const relativeOutputPath = path.relative(extensionPath, webpackConfig.output.path); return webpackGulp(webpackConfig, webpack, webpackDone) .pipe(es.through(function (data) { diff --git a/build/lib/nls.ts b/build/lib/nls.ts index e15f6a100d4..4e63abbd85a 100644 --- a/build/lib/nls.ts +++ b/build/lib/nls.ts @@ -26,7 +26,7 @@ function collect(node: ts.Node, fn: (node: ts.Node) => CollectStepResult): ts.No const result: ts.Node[] = []; function loop(node: ts.Node) { - let stepResult = fn(node); + const stepResult = fn(node); if (stepResult === CollectStepResult.Yes || stepResult === CollectStepResult.YesAndRecurse) { result.push(node); @@ -43,7 +43,7 @@ function collect(node: ts.Node, fn: (node: ts.Node) => CollectStepResult): ts.No function clone(object: T): T { const result = {}; - for (let id in object) { + for (const id in object) { result[id] = object[id]; } return result; diff --git a/build/lib/stats.ts b/build/lib/stats.ts index d56fe7486ae..7f5548dc1c4 100644 --- a/build/lib/stats.ts +++ b/build/lib/stats.ts @@ -25,7 +25,7 @@ class Entry { return `Stats for '${util.colors.grey(this.name)}': ${Math.round(this.totalSize / 1204)}KB`; } else { - let count = this.totalCount < 100 + const count = this.totalCount < 100 ? util.colors.green(this.totalCount.toString()) : util.colors.red(this.totalCount.toString()); @@ -43,7 +43,7 @@ export function createStatsStream(group: string, log?: boolean): es.ThroughStrea _entries.set(entry.name, entry); return es.through(function (data) { - let file = data as File; + const file = data as File; if (typeof file.path === 'string') { entry.totalCount += 1; if (Buffer.isBuffer(file.contents)) { @@ -61,7 +61,7 @@ export function createStatsStream(group: string, log?: boolean): es.ThroughStrea util.log(`Stats for '${util.colors.grey(entry.name)}': ${Math.round(entry.totalSize / 1204)}KB`); } else { - let count = entry.totalCount < 100 + const count = entry.totalCount < 100 ? util.colors.green(entry.totalCount.toString()) : util.colors.red(entry.totalCount.toString()); @@ -75,7 +75,7 @@ export function createStatsStream(group: string, log?: boolean): es.ThroughStrea export function submitAllStats(productJson: any, commit: string): Promise { - let sorted: Entry[] = []; + const sorted: Entry[] = []; // move entries for single files to the front _entries.forEach(value => { if (value.totalCount === 1) { diff --git a/build/lib/test/i18n.test.ts b/build/lib/test/i18n.test.ts index bf85d091b08..cfc1041974b 100644 --- a/build/lib/test/i18n.test.ts +++ b/build/lib/test/i18n.test.ts @@ -15,7 +15,7 @@ suite('XLF Parser Tests', () => { const translatedMessages = { key1: 'Кнопка #1', key2: 'Кнопка #2 &' }; test('Keys & messages to XLF conversion', () => { - let xlf = new i18n.XLF('vscode-workbench'); + const xlf = new i18n.XLF('vscode-workbench'); xlf.addFile(originalFilePath, keys, messages); const xlfString = xlf.toString(); diff --git a/build/lib/tslint/layeringRule.ts b/build/lib/tslint/layeringRule.ts index 6b28270dabc..dc0053fe8de 100644 --- a/build/lib/tslint/layeringRule.ts +++ b/build/lib/tslint/layeringRule.ts @@ -16,7 +16,7 @@ export class Rule extends Lint.Rules.AbstractRule { public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { const parts = dirname(sourceFile.fileName).split(/\\|\//); - let ruleArgs = this.getOptions().ruleArguments[0]; + const ruleArgs = this.getOptions().ruleArguments[0]; let config: Config | undefined; for (let i = parts.length - 1; i >= 0; i--) { @@ -98,7 +98,7 @@ class LayeringRule extends Lint.RuleWalker { } static _print(set: Set): string { - let r: string[] = []; + const r: string[] = []; set.forEach(e => r.push(e)); return r.join(', '); } diff --git a/build/lib/tslint/noUnexternalizedStringsRule.ts b/build/lib/tslint/noUnexternalizedStringsRule.ts index ce7913279eb..91112582ff1 100644 --- a/build/lib/tslint/noUnexternalizedStringsRule.ts +++ b/build/lib/tslint/noUnexternalizedStringsRule.ts @@ -63,8 +63,8 @@ class NoUnexternalizedStringsRuleWalker extends Lint.RuleWalker { this.messageIndex = undefined; this.keyIndex = undefined; this.usedKeys = Object.create(null); - let options: any[] = this.getOptions(); - let first: UnexternalizedStringsOptions = options && options.length > 0 ? options[0] : null; + const options: any[] = this.getOptions(); + const first: UnexternalizedStringsOptions = options && options.length > 0 ? options[0] : null; if (first) { if (Array.isArray(first.signatures)) { first.signatures.forEach((signature: string) => this.signatures[signature] = true); @@ -84,7 +84,7 @@ class NoUnexternalizedStringsRuleWalker extends Lint.RuleWalker { protected visitSourceFile(node: ts.SourceFile): void { super.visitSourceFile(node); Object.keys(this.usedKeys).forEach(key => { - let occurrences = this.usedKeys[key]; + const occurrences = this.usedKeys[key]; if (occurrences.length > 1) { occurrences.forEach(occurrence => { this.addFailure((this.createFailure(occurrence.key.getStart(), occurrence.key.getWidth(), `Duplicate key ${occurrence.key.getText()} with different message value.`))); @@ -99,9 +99,9 @@ class NoUnexternalizedStringsRuleWalker extends Lint.RuleWalker { } private checkStringLiteral(node: ts.StringLiteral): void { - let text = node.getText(); - let doubleQuoted = text.length >= 2 && text[0] === NoUnexternalizedStringsRuleWalker.DOUBLE_QUOTE && text[text.length - 1] === NoUnexternalizedStringsRuleWalker.DOUBLE_QUOTE; - let info = this.findDescribingParent(node); + const text = node.getText(); + const doubleQuoted = text.length >= 2 && text[0] === NoUnexternalizedStringsRuleWalker.DOUBLE_QUOTE && text[text.length - 1] === NoUnexternalizedStringsRuleWalker.DOUBLE_QUOTE; + const info = this.findDescribingParent(node); // Ignore strings in import and export nodes. if (info && info.isImport && doubleQuoted) { const fix = [ @@ -115,8 +115,8 @@ class NoUnexternalizedStringsRuleWalker extends Lint.RuleWalker { ); return; } - let callInfo = info ? info.callInfo : null; - let functionName = callInfo ? callInfo.callExpression.expression.getText() : null; + const callInfo = info ? info.callInfo : null; + const functionName = callInfo ? callInfo.callExpression.expression.getText() : null; if (functionName && this.ignores[functionName]) { return; } @@ -134,7 +134,7 @@ class NoUnexternalizedStringsRuleWalker extends Lint.RuleWalker { return; } // We have a string that is a direct argument into the localize call. - let keyArg: ts.Expression | null = callInfo && callInfo.argIndex === this.keyIndex + const keyArg: ts.Expression | null = callInfo && callInfo.argIndex === this.keyIndex ? callInfo.callExpression.arguments[this.keyIndex] : null; if (keyArg) { @@ -142,11 +142,11 @@ class NoUnexternalizedStringsRuleWalker extends Lint.RuleWalker { this.recordKey(keyArg, this.messageIndex && callInfo ? callInfo.callExpression.arguments[this.messageIndex] : undefined); } else if (isObjectLiteral(keyArg)) { for (let i = 0; i < keyArg.properties.length; i++) { - let property = keyArg.properties[i]; + const property = keyArg.properties[i]; if (isPropertyAssignment(property)) { - let name = property.name.getText(); + const name = property.name.getText(); if (name === 'key') { - let initializer = property.initializer; + const initializer = property.initializer; if (isStringLiteral(initializer)) { this.recordKey(initializer, this.messageIndex && callInfo ? callInfo.callExpression.arguments[this.messageIndex] : undefined); } @@ -168,7 +168,7 @@ class NoUnexternalizedStringsRuleWalker extends Lint.RuleWalker { } private recordKey(keyNode: ts.StringLiteral, messageNode: ts.Node | undefined) { - let text = keyNode.getText(); + const text = keyNode.getText(); // We have an empty key if (text.match(/(['"]) *\1/)) { if (messageNode) { @@ -194,9 +194,9 @@ class NoUnexternalizedStringsRuleWalker extends Lint.RuleWalker { private findDescribingParent(node: ts.Node): { callInfo?: { callExpression: ts.CallExpression, argIndex: number }, isImport?: boolean; } | null { let parent: ts.Node; while ((parent = node.parent)) { - let kind = parent.kind; + const kind = parent.kind; if (kind === ts.SyntaxKind.CallExpression) { - let callExpression = parent as ts.CallExpression; + const callExpression = parent as ts.CallExpression; return { callInfo: { callExpression: callExpression, argIndex: callExpression.arguments.indexOf(node) } }; } else if (kind === ts.SyntaxKind.ImportEqualsDeclaration || kind === ts.SyntaxKind.ImportDeclaration || kind === ts.SyntaxKind.ExportDeclaration) { return { isImport: true };