Skip to content

Commit 0a7b7e0

Browse files
author
Andy
authored
Apply 'variable-name' tslint rule (microsoft#19743)
1 parent 8d5b052 commit 0a7b7e0

36 files changed

+349
-331
lines changed

Gulpfile.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,12 @@ const lclDirectory = "src/loc/lcl";
9999

100100
const builtDirectory = "built/";
101101
const builtLocalDirectory = "built/local/";
102-
const LKGDirectory = "lib/";
102+
const lkgDirectory = "lib/";
103103

104104
const copyright = "CopyrightNotice.txt";
105105

106106
const compilerFilename = "tsc.js";
107-
const LKGCompiler = path.join(LKGDirectory, compilerFilename);
107+
const lkgCompiler = path.join(lkgDirectory, compilerFilename);
108108
const builtLocalCompiler = path.join(builtLocalDirectory, compilerFilename);
109109

110110
const nodeModulesPathPrefix = path.resolve("./node_modules/.bin/");
@@ -589,7 +589,7 @@ gulp.task("VerifyLKG", /*help*/ false, [], () => {
589589
". The following files are missing:\n" + missingFiles.join("\n"));
590590
}
591591
// Copy all the targets into the LKG directory
592-
return gulp.src([...expectedFiles, path.join(builtLocalDirectory, "**"), `!${path.join(builtLocalDirectory, "tslint")}`, `!${path.join(builtLocalDirectory, "*.*")}`]).pipe(gulp.dest(LKGDirectory));
592+
return gulp.src([...expectedFiles, path.join(builtLocalDirectory, "**"), `!${path.join(builtLocalDirectory, "tslint")}`, `!${path.join(builtLocalDirectory, "*.*")}`]).pipe(gulp.dest(lkgDirectory));
593593
});
594594

595595
gulp.task("LKGInternal", /*help*/ false, ["lib", "local"]);
@@ -992,7 +992,7 @@ gulp.task(loggedIOJsPath, /*help*/ false, [], (done) => {
992992
const temp = path.join(builtLocalDirectory, "temp");
993993
mkdirP(temp, (err) => {
994994
if (err) { console.error(err); done(err); process.exit(1); }
995-
exec(host, [LKGCompiler, "--types", "--target es5", "--lib es5", "--outdir", temp, loggedIOpath], () => {
995+
exec(host, [lkgCompiler, "--types", "--target es5", "--lib es5", "--outdir", temp, loggedIOpath], () => {
996996
fs.renameSync(path.join(temp, "/harness/loggedIO.js"), loggedIOJsPath);
997997
del(temp).then(() => done(), done);
998998
}, done);

scripts/generateLocalizedDiagnosticMessages.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ function main(): void {
8787
const out: any = {};
8888
for (const item of o.LCX.Item[0].Item[0].Item) {
8989
let ItemId = item.$.ItemId;
90-
let Val = item.Str[0].Tgt ? item.Str[0].Tgt[0].Val[0] : item.Str[0].Val[0];
90+
let val = item.Str[0].Tgt ? item.Str[0].Tgt[0].Val[0] : item.Str[0].Val[0];
9191

92-
if (typeof ItemId !== "string" || typeof Val !== "string") {
92+
if (typeof ItemId !== "string" || typeof val !== "string") {
9393
console.error("Unexpected XML file structure");
9494
process.exit(1);
9595
}
@@ -98,8 +98,8 @@ function main(): void {
9898
ItemId = ItemId.slice(1); // remove leading semicolon
9999
}
100100

101-
Val = Val.replace(/]5D;/, "]"); // unescape `]`
102-
out[ItemId] = Val;
101+
val = val.replace(/]5D;/, "]"); // unescape `]`
102+
out[ItemId] = val;
103103
}
104104
return JSON.stringify(out, undefined, 2);
105105
}

scripts/processDiagnosticMessages.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ function buildInfoFileOutput(messageTable: InputDiagnosticMessageTable): string
6363
" function diag(code: number, category: DiagnosticCategory, key: string, message: string): DiagnosticMessage {\r\n" +
6464
" return { code, category, key, message };\r\n" +
6565
" }\r\n" +
66-
' export const Diagnostics = {\r\n';
66+
" // tslint:disable-next-line variable-name\r\n" +
67+
" export const Diagnostics = {\r\n";
6768
messageTable.forEach(({ code, category }, name) => {
6869
const propName = convertPropertyName(name);
6970
result += ` ${propName}: diag(${code}, DiagnosticCategory.${category}, "${createKey(propName, code)}", ${JSON.stringify(name)}),\r\n`;

src/compiler/binder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ namespace ts {
133133

134134
let symbolCount = 0;
135135

136-
let Symbol: { new (flags: SymbolFlags, name: __String): Symbol };
136+
let Symbol: { new (flags: SymbolFlags, name: __String): Symbol }; // tslint:disable-line variable-name
137137
let classifiableNames: UnderscoreEscapedMap<true>;
138138

139139
const unreachableFlow: FlowNode = { flags: FlowFlags.Unreachable };

src/compiler/checker.ts

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@ namespace ts {
4848
let requestedExternalEmitHelpers: ExternalEmitHelpers;
4949
let externalHelpersModule: Symbol;
5050

51+
// tslint:disable variable-name
5152
const Symbol = objectAllocator.getSymbolConstructor();
5253
const Type = objectAllocator.getTypeConstructor();
5354
const Signature = objectAllocator.getSignatureConstructor();
55+
// tslint:enable variable-name
5456

5557
let typeCount = 0;
5658
let symbolCount = 0;
@@ -488,17 +490,6 @@ namespace ts {
488490
/** Things we lazy load from the JSX namespace */
489491
const jsxTypes = createUnderscoreEscapedMap<Type>();
490492

491-
const JsxNames = {
492-
JSX: "JSX" as __String,
493-
IntrinsicElements: "IntrinsicElements" as __String,
494-
ElementClass: "ElementClass" as __String,
495-
ElementAttributesPropertyNameContainer: "ElementAttributesProperty" as __String,
496-
ElementChildrenAttributeNameContainer: "ElementChildrenAttribute" as __String,
497-
Element: "Element" as __String,
498-
IntrinsicAttributes: "IntrinsicAttributes" as __String,
499-
IntrinsicClassAttributes: "IntrinsicClassAttributes" as __String
500-
};
501-
502493
const subtypeRelation = createMap<RelationComparisonResult>();
503494
const assignableRelation = createMap<RelationComparisonResult>();
504495
const comparableRelation = createMap<RelationComparisonResult>();
@@ -25103,11 +25094,13 @@ namespace ts {
2510325094
}
2510425095

2510525096
function checkGrammarObjectLiteralExpression(node: ObjectLiteralExpression, inDestructuring: boolean) {
25106-
const seen = createUnderscoreEscapedMap<SymbolFlags>();
25107-
const Property = 1;
25108-
const GetAccessor = 2;
25109-
const SetAccessor = 4;
25110-
const GetOrSetAccessor = GetAccessor | SetAccessor;
25097+
const enum Flags {
25098+
Property = 1,
25099+
GetAccessor = 2,
25100+
SetAccessor = 4,
25101+
GetOrSetAccessor = GetAccessor | SetAccessor,
25102+
}
25103+
const seen = createUnderscoreEscapedMap<Flags>();
2511125104

2511225105
for (const prop of node.properties) {
2511325106
if (prop.kind === SyntaxKind.SpreadAssignment) {
@@ -25142,26 +25135,27 @@ namespace ts {
2514225135
// c.IsAccessorDescriptor(previous) is true and IsDataDescriptor(propId.descriptor) is true.
2514325136
// d.IsAccessorDescriptor(previous) is true and IsAccessorDescriptor(propId.descriptor) is true
2514425137
// and either both previous and propId.descriptor have[[Get]] fields or both previous and propId.descriptor have[[Set]] fields
25145-
let currentKind: number;
25146-
if (prop.kind === SyntaxKind.PropertyAssignment || prop.kind === SyntaxKind.ShorthandPropertyAssignment) {
25147-
// Grammar checking for computedPropertyName and shorthandPropertyAssignment
25148-
checkGrammarForInvalidQuestionMark((<PropertyAssignment>prop).questionToken, Diagnostics.An_object_member_cannot_be_declared_optional);
25149-
if (name.kind === SyntaxKind.NumericLiteral) {
25150-
checkGrammarNumericLiteral(<NumericLiteral>name);
25151-
}
25152-
currentKind = Property;
25153-
}
25154-
else if (prop.kind === SyntaxKind.MethodDeclaration) {
25155-
currentKind = Property;
25156-
}
25157-
else if (prop.kind === SyntaxKind.GetAccessor) {
25158-
currentKind = GetAccessor;
25159-
}
25160-
else if (prop.kind === SyntaxKind.SetAccessor) {
25161-
currentKind = SetAccessor;
25162-
}
25163-
else {
25164-
Debug.assertNever(prop, "Unexpected syntax kind:" + (<Node>prop).kind);
25138+
let currentKind: Flags;
25139+
switch (prop.kind) {
25140+
case SyntaxKind.PropertyAssignment:
25141+
case SyntaxKind.ShorthandPropertyAssignment:
25142+
// Grammar checking for computedPropertyName and shorthandPropertyAssignment
25143+
checkGrammarForInvalidQuestionMark((<PropertyAssignment>prop).questionToken, Diagnostics.An_object_member_cannot_be_declared_optional);
25144+
if (name.kind === SyntaxKind.NumericLiteral) {
25145+
checkGrammarNumericLiteral(<NumericLiteral>name);
25146+
}
25147+
// falls through
25148+
case SyntaxKind.MethodDeclaration:
25149+
currentKind = Flags.Property;
25150+
break;
25151+
case SyntaxKind.GetAccessor:
25152+
currentKind = Flags.GetAccessor;
25153+
break;
25154+
case SyntaxKind.SetAccessor:
25155+
currentKind = Flags.SetAccessor;
25156+
break;
25157+
default:
25158+
Debug.assertNever(prop, "Unexpected syntax kind:" + (<Node>prop).kind);
2516525159
}
2516625160

2516725161
const effectiveName = getPropertyNameForPropertyNameNode(name);
@@ -25174,11 +25168,11 @@ namespace ts {
2517425168
seen.set(effectiveName, currentKind);
2517525169
}
2517625170
else {
25177-
if (currentKind === Property && existingKind === Property) {
25171+
if (currentKind === Flags.Property && existingKind === Flags.Property) {
2517825172
grammarErrorOnNode(name, Diagnostics.Duplicate_identifier_0, getTextOfNode(name));
2517925173
}
25180-
else if ((currentKind & GetOrSetAccessor) && (existingKind & GetOrSetAccessor)) {
25181-
if (existingKind !== GetOrSetAccessor && currentKind !== existingKind) {
25174+
else if ((currentKind & Flags.GetOrSetAccessor) && (existingKind & Flags.GetOrSetAccessor)) {
25175+
if (existingKind !== Flags.GetOrSetAccessor && currentKind !== existingKind) {
2518225176
seen.set(effectiveName, currentKind | existingKind);
2518325177
}
2518425178
else {
@@ -25806,4 +25800,17 @@ namespace ts {
2580625800
return false;
2580725801
}
2580825802
}
25803+
25804+
namespace JsxNames {
25805+
// tslint:disable variable-name
25806+
export const JSX = "JSX" as __String;
25807+
export const IntrinsicElements = "IntrinsicElements" as __String;
25808+
export const ElementClass = "ElementClass" as __String;
25809+
export const ElementAttributesPropertyNameContainer = "ElementAttributesProperty" as __String;
25810+
export const ElementChildrenAttributeNameContainer = "ElementChildrenAttribute" as __String;
25811+
export const Element = "Element" as __String;
25812+
export const IntrinsicAttributes = "IntrinsicAttributes" as __String;
25813+
export const IntrinsicClassAttributes = "IntrinsicClassAttributes" as __String;
25814+
// tslint:enable variable-name
25815+
}
2580925816
}

src/compiler/core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ namespace ts {
7676
// The global Map object. This may not be available, so we must test for it.
7777
declare const Map: { new<T>(): Map<T> } | undefined;
7878
// Internet Explorer's Map doesn't support iteration, so don't use it.
79-
// tslint:disable-next-line:no-in-operator
79+
// tslint:disable-next-line no-in-operator variable-name
8080
const MapCtr = typeof Map !== "undefined" && "entries" in Map.prototype ? Map : shimMap();
8181

8282
// Keep the class inside a function so it doesn't get compiled if it's not used.

src/compiler/factory.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2654,6 +2654,7 @@ namespace ts {
26542654
return node;
26552655
}
26562656

2657+
// tslint:disable-next-line variable-name
26572658
let SourceMapSource: new (fileName: string, text: string, skipTrivia?: (pos: number) => number) => SourceMapSource;
26582659

26592660
/**

src/compiler/parser.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ namespace ts {
1212
JSDoc = 1 << 5,
1313
}
1414

15+
// tslint:disable variable-name
1516
let NodeConstructor: new (kind: SyntaxKind, pos: number, end: number) => Node;
1617
let TokenConstructor: new (kind: SyntaxKind, pos: number, end: number) => Node;
1718
let IdentifierConstructor: new (kind: SyntaxKind, pos: number, end: number) => Node;
1819
let SourceFileConstructor: new (kind: SyntaxKind, pos: number, end: number) => Node;
20+
// tslint:enable variable-name
1921

2022
export function createNode(kind: SyntaxKind, pos?: number, end?: number): Node {
2123
if (kind === SyntaxKind.SourceFile) {
@@ -524,10 +526,12 @@ namespace ts {
524526
const disallowInAndDecoratorContext = NodeFlags.DisallowInContext | NodeFlags.DecoratorContext;
525527

526528
// capture constructors in 'initializeState' to avoid null checks
529+
// tslint:disable variable-name
527530
let NodeConstructor: new (kind: SyntaxKind, pos: number, end: number) => Node;
528531
let TokenConstructor: new (kind: SyntaxKind, pos: number, end: number) => Node;
529532
let IdentifierConstructor: new (kind: SyntaxKind, pos: number, end: number) => Node;
530533
let SourceFileConstructor: new (kind: SyntaxKind, pos: number, end: number) => Node;
534+
// tslint:enable variable-name
531535

532536
let sourceFile: SourceFile;
533537
let parseDiagnostics: Diagnostic[];

src/compiler/utilities.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,8 +1404,8 @@ namespace ts {
14041404
return charCode === CharacterCodes.singleQuote || charCode === CharacterCodes.doubleQuote;
14051405
}
14061406

1407-
export function isStringDoubleQuoted(string: StringLiteral, sourceFile: SourceFile): boolean {
1408-
return getSourceTextOfNodeFromSourceFile(sourceFile, string).charCodeAt(0) === CharacterCodes.doubleQuote;
1407+
export function isStringDoubleQuoted(str: StringLiteral, sourceFile: SourceFile): boolean {
1408+
return getSourceTextOfNodeFromSourceFile(sourceFile, str).charCodeAt(0) === CharacterCodes.doubleQuote;
14091409
}
14101410

14111411
/**

src/harness/fourslash.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ namespace FourSlash {
126126
// 0 - cancelled
127127
// >0 - not cancelled
128128
// <0 - not cancelled and value denotes number of isCancellationRequested after which token become cancelled
129-
private static readonly NotCanceled: number = -1;
130-
private numberOfCallsBeforeCancellation: number = TestCancellationToken.NotCanceled;
129+
private static readonly notCanceled = -1;
130+
private numberOfCallsBeforeCancellation = TestCancellationToken.notCanceled;
131131

132132
public isCancellationRequested(): boolean {
133133
if (this.numberOfCallsBeforeCancellation < 0) {
@@ -148,7 +148,7 @@ namespace FourSlash {
148148
}
149149

150150
public resetCancelled(): void {
151-
this.numberOfCallsBeforeCancellation = TestCancellationToken.NotCanceled;
151+
this.numberOfCallsBeforeCancellation = TestCancellationToken.notCanceled;
152152
}
153153
}
154154

0 commit comments

Comments
 (0)