Skip to content

Commit

Permalink
Apply 'variable-name' tslint rule (microsoft#19743)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy authored Nov 6, 2017
1 parent 8d5b052 commit 0a7b7e0
Show file tree
Hide file tree
Showing 36 changed files with 349 additions and 331 deletions.
8 changes: 4 additions & 4 deletions Gulpfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ const lclDirectory = "src/loc/lcl";

const builtDirectory = "built/";
const builtLocalDirectory = "built/local/";
const LKGDirectory = "lib/";
const lkgDirectory = "lib/";

const copyright = "CopyrightNotice.txt";

const compilerFilename = "tsc.js";
const LKGCompiler = path.join(LKGDirectory, compilerFilename);
const lkgCompiler = path.join(lkgDirectory, compilerFilename);
const builtLocalCompiler = path.join(builtLocalDirectory, compilerFilename);

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

gulp.task("LKGInternal", /*help*/ false, ["lib", "local"]);
Expand Down Expand Up @@ -992,7 +992,7 @@ gulp.task(loggedIOJsPath, /*help*/ false, [], (done) => {
const temp = path.join(builtLocalDirectory, "temp");
mkdirP(temp, (err) => {
if (err) { console.error(err); done(err); process.exit(1); }
exec(host, [LKGCompiler, "--types", "--target es5", "--lib es5", "--outdir", temp, loggedIOpath], () => {
exec(host, [lkgCompiler, "--types", "--target es5", "--lib es5", "--outdir", temp, loggedIOpath], () => {
fs.renameSync(path.join(temp, "/harness/loggedIO.js"), loggedIOJsPath);
del(temp).then(() => done(), done);
}, done);
Expand Down
8 changes: 4 additions & 4 deletions scripts/generateLocalizedDiagnosticMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ function main(): void {
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];
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") {
if (typeof ItemId !== "string" || typeof val !== "string") {
console.error("Unexpected XML file structure");
process.exit(1);
}
Expand All @@ -98,8 +98,8 @@ function main(): void {
ItemId = ItemId.slice(1); // remove leading semicolon
}

Val = Val.replace(/]5D;/, "]"); // unescape `]`
out[ItemId] = Val;
val = val.replace(/]5D;/, "]"); // unescape `]`
out[ItemId] = val;
}
return JSON.stringify(out, undefined, 2);
}
Expand Down
3 changes: 2 additions & 1 deletion scripts/processDiagnosticMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ function buildInfoFileOutput(messageTable: InputDiagnosticMessageTable): string
" function diag(code: number, category: DiagnosticCategory, key: string, message: string): DiagnosticMessage {\r\n" +
" return { code, category, key, message };\r\n" +
" }\r\n" +
' export const Diagnostics = {\r\n';
" // tslint:disable-next-line variable-name\r\n" +
" export const Diagnostics = {\r\n";
messageTable.forEach(({ code, category }, name) => {
const propName = convertPropertyName(name);
result += ` ${propName}: diag(${code}, DiagnosticCategory.${category}, "${createKey(propName, code)}", ${JSON.stringify(name)}),\r\n`;
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ namespace ts {

let symbolCount = 0;

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

const unreachableFlow: FlowNode = { flags: FlowFlags.Unreachable };
Expand Down
85 changes: 46 additions & 39 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ namespace ts {
let requestedExternalEmitHelpers: ExternalEmitHelpers;
let externalHelpersModule: Symbol;

// tslint:disable variable-name
const Symbol = objectAllocator.getSymbolConstructor();
const Type = objectAllocator.getTypeConstructor();
const Signature = objectAllocator.getSignatureConstructor();
// tslint:enable variable-name

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

const JsxNames = {
JSX: "JSX" as __String,
IntrinsicElements: "IntrinsicElements" as __String,
ElementClass: "ElementClass" as __String,
ElementAttributesPropertyNameContainer: "ElementAttributesProperty" as __String,
ElementChildrenAttributeNameContainer: "ElementChildrenAttribute" as __String,
Element: "Element" as __String,
IntrinsicAttributes: "IntrinsicAttributes" as __String,
IntrinsicClassAttributes: "IntrinsicClassAttributes" as __String
};

const subtypeRelation = createMap<RelationComparisonResult>();
const assignableRelation = createMap<RelationComparisonResult>();
const comparableRelation = createMap<RelationComparisonResult>();
Expand Down Expand Up @@ -25103,11 +25094,13 @@ namespace ts {
}

function checkGrammarObjectLiteralExpression(node: ObjectLiteralExpression, inDestructuring: boolean) {
const seen = createUnderscoreEscapedMap<SymbolFlags>();
const Property = 1;
const GetAccessor = 2;
const SetAccessor = 4;
const GetOrSetAccessor = GetAccessor | SetAccessor;
const enum Flags {
Property = 1,
GetAccessor = 2,
SetAccessor = 4,
GetOrSetAccessor = GetAccessor | SetAccessor,
}
const seen = createUnderscoreEscapedMap<Flags>();

for (const prop of node.properties) {
if (prop.kind === SyntaxKind.SpreadAssignment) {
Expand Down Expand Up @@ -25142,26 +25135,27 @@ namespace ts {
// c.IsAccessorDescriptor(previous) is true and IsDataDescriptor(propId.descriptor) is true.
// d.IsAccessorDescriptor(previous) is true and IsAccessorDescriptor(propId.descriptor) is true
// and either both previous and propId.descriptor have[[Get]] fields or both previous and propId.descriptor have[[Set]] fields
let currentKind: number;
if (prop.kind === SyntaxKind.PropertyAssignment || prop.kind === SyntaxKind.ShorthandPropertyAssignment) {
// Grammar checking for computedPropertyName and shorthandPropertyAssignment
checkGrammarForInvalidQuestionMark((<PropertyAssignment>prop).questionToken, Diagnostics.An_object_member_cannot_be_declared_optional);
if (name.kind === SyntaxKind.NumericLiteral) {
checkGrammarNumericLiteral(<NumericLiteral>name);
}
currentKind = Property;
}
else if (prop.kind === SyntaxKind.MethodDeclaration) {
currentKind = Property;
}
else if (prop.kind === SyntaxKind.GetAccessor) {
currentKind = GetAccessor;
}
else if (prop.kind === SyntaxKind.SetAccessor) {
currentKind = SetAccessor;
}
else {
Debug.assertNever(prop, "Unexpected syntax kind:" + (<Node>prop).kind);
let currentKind: Flags;
switch (prop.kind) {
case SyntaxKind.PropertyAssignment:
case SyntaxKind.ShorthandPropertyAssignment:
// Grammar checking for computedPropertyName and shorthandPropertyAssignment
checkGrammarForInvalidQuestionMark((<PropertyAssignment>prop).questionToken, Diagnostics.An_object_member_cannot_be_declared_optional);
if (name.kind === SyntaxKind.NumericLiteral) {
checkGrammarNumericLiteral(<NumericLiteral>name);
}
// falls through
case SyntaxKind.MethodDeclaration:
currentKind = Flags.Property;
break;
case SyntaxKind.GetAccessor:
currentKind = Flags.GetAccessor;
break;
case SyntaxKind.SetAccessor:
currentKind = Flags.SetAccessor;
break;
default:
Debug.assertNever(prop, "Unexpected syntax kind:" + (<Node>prop).kind);
}

const effectiveName = getPropertyNameForPropertyNameNode(name);
Expand All @@ -25174,11 +25168,11 @@ namespace ts {
seen.set(effectiveName, currentKind);
}
else {
if (currentKind === Property && existingKind === Property) {
if (currentKind === Flags.Property && existingKind === Flags.Property) {
grammarErrorOnNode(name, Diagnostics.Duplicate_identifier_0, getTextOfNode(name));
}
else if ((currentKind & GetOrSetAccessor) && (existingKind & GetOrSetAccessor)) {
if (existingKind !== GetOrSetAccessor && currentKind !== existingKind) {
else if ((currentKind & Flags.GetOrSetAccessor) && (existingKind & Flags.GetOrSetAccessor)) {
if (existingKind !== Flags.GetOrSetAccessor && currentKind !== existingKind) {
seen.set(effectiveName, currentKind | existingKind);
}
else {
Expand Down Expand Up @@ -25806,4 +25800,17 @@ namespace ts {
return false;
}
}

namespace JsxNames {
// tslint:disable variable-name
export const JSX = "JSX" as __String;
export const IntrinsicElements = "IntrinsicElements" as __String;
export const ElementClass = "ElementClass" as __String;
export const ElementAttributesPropertyNameContainer = "ElementAttributesProperty" as __String;
export const ElementChildrenAttributeNameContainer = "ElementChildrenAttribute" as __String;
export const Element = "Element" as __String;
export const IntrinsicAttributes = "IntrinsicAttributes" as __String;
export const IntrinsicClassAttributes = "IntrinsicClassAttributes" as __String;
// tslint:enable variable-name
}
}
2 changes: 1 addition & 1 deletion src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ namespace ts {
// The global Map object. This may not be available, so we must test for it.
declare const Map: { new<T>(): Map<T> } | undefined;
// Internet Explorer's Map doesn't support iteration, so don't use it.
// tslint:disable-next-line:no-in-operator
// tslint:disable-next-line no-in-operator variable-name
const MapCtr = typeof Map !== "undefined" && "entries" in Map.prototype ? Map : shimMap();

// Keep the class inside a function so it doesn't get compiled if it's not used.
Expand Down
1 change: 1 addition & 0 deletions src/compiler/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2654,6 +2654,7 @@ namespace ts {
return node;
}

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

/**
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ namespace ts {
JSDoc = 1 << 5,
}

// tslint:disable variable-name
let NodeConstructor: new (kind: SyntaxKind, pos: number, end: number) => Node;
let TokenConstructor: new (kind: SyntaxKind, pos: number, end: number) => Node;
let IdentifierConstructor: new (kind: SyntaxKind, pos: number, end: number) => Node;
let SourceFileConstructor: new (kind: SyntaxKind, pos: number, end: number) => Node;
// tslint:enable variable-name

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

// capture constructors in 'initializeState' to avoid null checks
// tslint:disable variable-name
let NodeConstructor: new (kind: SyntaxKind, pos: number, end: number) => Node;
let TokenConstructor: new (kind: SyntaxKind, pos: number, end: number) => Node;
let IdentifierConstructor: new (kind: SyntaxKind, pos: number, end: number) => Node;
let SourceFileConstructor: new (kind: SyntaxKind, pos: number, end: number) => Node;
// tslint:enable variable-name

let sourceFile: SourceFile;
let parseDiagnostics: Diagnostic[];
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1404,8 +1404,8 @@ namespace ts {
return charCode === CharacterCodes.singleQuote || charCode === CharacterCodes.doubleQuote;
}

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

/**
Expand Down
6 changes: 3 additions & 3 deletions src/harness/fourslash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ namespace FourSlash {
// 0 - cancelled
// >0 - not cancelled
// <0 - not cancelled and value denotes number of isCancellationRequested after which token become cancelled
private static readonly NotCanceled: number = -1;
private numberOfCallsBeforeCancellation: number = TestCancellationToken.NotCanceled;
private static readonly notCanceled = -1;
private numberOfCallsBeforeCancellation = TestCancellationToken.notCanceled;

public isCancellationRequested(): boolean {
if (this.numberOfCallsBeforeCancellation < 0) {
Expand All @@ -148,7 +148,7 @@ namespace FourSlash {
}

public resetCancelled(): void {
this.numberOfCallsBeforeCancellation = TestCancellationToken.NotCanceled;
this.numberOfCallsBeforeCancellation = TestCancellationToken.notCanceled;
}
}

Expand Down
18 changes: 9 additions & 9 deletions src/harness/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1113,11 +1113,11 @@ namespace Harness {
case "string":
return value;
case "number": {
const number = parseInt(value, 10);
if (isNaN(number)) {
const numverValue = parseInt(value, 10);
if (isNaN(numverValue)) {
throw new Error(`Value must be a number, got: ${JSON.stringify(value)}`);
}
return number;
return numverValue;
}
// If not a primitive, the possible types are specified in what is effectively a map of options.
case "list":
Expand Down Expand Up @@ -1964,7 +1964,7 @@ namespace Harness {

/** Support class for baseline files */
export namespace Baseline {
const NoContent = "<no content>";
const noContent = "<no content>";

export interface BaselineOptions {
Subfolder?: string;
Expand Down Expand Up @@ -2023,7 +2023,7 @@ namespace Harness {
/* tslint:disable:no-null-keyword */
if (actual === null) {
/* tslint:enable:no-null-keyword */
actual = NoContent;
actual = noContent;
}

let expected = "<no content>";
Expand Down Expand Up @@ -2060,13 +2060,13 @@ namespace Harness {
IO.deleteFile(actualFileName);
}

const encoded_actual = Utils.encodeString(actual);
if (expected !== encoded_actual) {
if (actual === NoContent) {
const encodedActual = Utils.encodeString(actual);
if (expected !== encodedActual) {
if (actual === noContent) {
IO.writeFile(actualFileName + ".delete", "");
}
else {
IO.writeFile(actualFileName, encoded_actual);
IO.writeFile(actualFileName, encodedActual);
}
throw new Error(`The baseline file ${relativeFileName} has changed.`);
}
Expand Down
4 changes: 2 additions & 2 deletions src/harness/harnessLanguageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ namespace Harness.LanguageService {
}

class DefaultHostCancellationToken implements ts.HostCancellationToken {
public static readonly Instance = new DefaultHostCancellationToken();
public static readonly instance = new DefaultHostCancellationToken();

public isCancellationRequested() {
return false;
Expand All @@ -126,7 +126,7 @@ namespace Harness.LanguageService {
public typesRegistry: ts.Map<void> | undefined;
protected virtualFileSystem: Utils.VirtualFileSystem = new Utils.VirtualFileSystem(virtualFileSystemRoot, /*useCaseSensitiveFilenames*/false);

constructor(protected cancellationToken = DefaultHostCancellationToken.Instance,
constructor(protected cancellationToken = DefaultHostCancellationToken.instance,
protected settings = ts.getDefaultCompilerOptions()) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/harness/loggedIO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ namespace Playback {
let i = 0;
const getBase = () => recordLogFileNameBase + i;
while (underlying.fileExists(ts.combinePaths(getBase(), "test.json"))) i++;
const newLog = oldStyleLogIntoNewStyleLog(recordLog, (path, string) => underlying.writeFile(path, string), getBase());
const newLog = oldStyleLogIntoNewStyleLog(recordLog, (path, str) => underlying.writeFile(path, str), getBase());
underlying.writeFile(ts.combinePaths(getBase(), "test.json"), JSON.stringify(newLog, null, 4)); // tslint:disable-line:no-null-keyword
const syntheticTsconfig = generateTsconfig(newLog);
if (syntheticTsconfig) {
Expand Down
Loading

0 comments on commit 0a7b7e0

Please sign in to comment.