Skip to content

Commit

Permalink
lint: no-reserved-keywords, part of #54 (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenWeatherford authored and Stephen Weatherford committed Apr 19, 2018
1 parent 94cf3f0 commit 1ddb740
Show file tree
Hide file tree
Showing 20 changed files with 178 additions and 173 deletions.
20 changes: 10 additions & 10 deletions src/AzureRMTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,22 +520,22 @@ export class AzureRMTools {
completionToAdd.detail = completion.detail;
completionToAdd.documentation = completion.description;

switch (completion.type) {
case Completion.Type.Function:
switch (completion.kind) {
case Completion.CompletionKind.Function:
completionToAdd.kind = vscode.CompletionItemKind.Function;
break;

case Completion.Type.Parameter:
case Completion.Type.Variable:
case Completion.CompletionKind.Parameter:
case Completion.CompletionKind.Variable:
completionToAdd.kind = vscode.CompletionItemKind.Variable;
break;

case Completion.Type.Property:
case Completion.CompletionKind.Property:
completionToAdd.kind = vscode.CompletionItemKind.Field;
break;

default:
assert.fail(`Unrecognized Completion.Type: ${completion.type}`);
assert.fail(`Unrecognized Completion.Type: ${completion.kind}`);
break;
}

Expand Down Expand Up @@ -597,17 +597,17 @@ export class AzureRMTools {
const references: Reference.List = context.references;
if (references && references.length > 0) {
let referenceType: string;
switch (references.type) {
case Reference.Type.Parameter:
switch (references.kind) {
case Reference.ReferenceKind.Parameter:
referenceType = "parameter";
break;

case Reference.Type.Variable:
case Reference.ReferenceKind.Variable:
referenceType = "variable";
break;

default:
assert.fail(`Unrecognized Reference.Type: ${references.type}`);
assert.fail(`Unrecognized Reference.Kind: ${references.kind}`);
referenceType = "no reference type";
break;
}
Expand Down
26 changes: 13 additions & 13 deletions src/Completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,40 @@ import * as tle from "./TLE";
* A completion item in the list of completion suggestions that appear when a user invokes auto-completion (Ctrl + Space).
*/
export class Item {
constructor(private _name: string, private _insertText: string, private _insertSpan: language.Span, private _detail: string, private _description: string, private _type: Type) {
constructor(private _name: string, private _insertText: string, private _insertSpan: language.Span, private _detail: string, private _description: string, private _type: CompletionKind) {
}

public get name(): string {
return this._name;
}

public get insertText(): string {
return this._insertText;
}

public get insertSpan(): language.Span {
return this._insertSpan;
}

public get detail(): string {
return this._detail;
}

public get description(): string {
return this._description;
}
public get type(): Type {

public get kind(): CompletionKind {
return this._type;
}
}

export enum Type {
export enum CompletionKind {
Function,

Parameter,

Variable,

Property
}
}
12 changes: 6 additions & 6 deletions src/DeploymentTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,14 @@ export class DeploymentTemplate {
this._warnings = [];

for (const parameterDefinition of this.parameterDefinitions) {
const parameterReferences: Reference.List = this.findReferences(Reference.Type.Parameter, parameterDefinition.name.toString());
const parameterReferences: Reference.List = this.findReferences(Reference.ReferenceKind.Parameter, parameterDefinition.name.toString());
if (parameterReferences.length === 1) {
this._warnings.push(new language.Issue(parameterDefinition.name.span, `The parameter '${parameterDefinition.name.toString()}' is never used.`));
}
}

for (const variableDefinition of this.variableDefinitions) {
const variableReferences: Reference.List = this.findReferences(Reference.Type.Variable, variableDefinition.name.toString());
const variableReferences: Reference.List = this.findReferences(Reference.ReferenceKind.Variable, variableDefinition.name.toString());
if (variableReferences.length === 1) {
this._warnings.push(new language.Issue(variableDefinition.name.span, `The variable '${variableDefinition.name.toString()}' is never used.`));
}
Expand Down Expand Up @@ -415,27 +415,27 @@ export class DeploymentTemplate {
return result;
}

public findReferences(referenceType: Reference.Type, referenceName: string): Reference.List {
public findReferences(referenceType: Reference.ReferenceKind, referenceName: string): Reference.List {
const result: Reference.List = new Reference.List(referenceType);

if (referenceName) {
switch (referenceType) {
case Reference.Type.Parameter:
case Reference.ReferenceKind.Parameter:
const parameterDefinition: ParameterDefinition = this.getParameterDefinition(referenceName);
if (parameterDefinition) {
result.add(parameterDefinition.name.unquotedSpan);
}
break;

case Reference.Type.Variable:
case Reference.ReferenceKind.Variable:
const variableDefinition: Json.Property = this.getVariableDefinition(referenceName);
if (variableDefinition) {
result.add(variableDefinition.name.unquotedSpan);
}
break;

default:
assert.fail(`Unrecognized Reference.Type: ${referenceType}`);
assert.fail(`Unrecognized Reference.Kind: ${referenceType}`);
break;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Histogram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ export class Histogram {
}
else {
for (let rhsKey of key.keys) {
this.add(rhsKey, key.get(rhsKey));
this.add(rhsKey, key.getCount(rhsKey));
}
}
}

public get(key: string): number {
public getCount(key: string): number {
let result: number;
if (key === null) {
result = this._nullCounts;
Expand All @@ -56,4 +56,4 @@ export class Histogram {
}
return result;
}
}
}
10 changes: 5 additions & 5 deletions src/HttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as http from "http";
import * as https from "https";

export class HttpClient {
public static get(url: string): Promise<string> {
public static request(url: string): Promise<string> {
assert(url, "Cannot make a HTTP request for a null, undefined, or empty url.");

if (!url.startsWith("http")) {
Expand All @@ -19,14 +19,14 @@ export class HttpClient {

function callback(response: http.IncomingMessage): void {
if (300 <= response.statusCode && response.statusCode < 400 && response.headers["location"]) {
resolve(HttpClient.get(response.headers["location"].toString()));
resolve(HttpClient.request(response.headers["location"].toString()));
}
else if (200 <= response.statusCode && response.statusCode < 400) {
let responseContent: string = "";
let encoding: string;

response.on("data", (dataChunk: string|Buffer) => {
const buffer: Buffer = dataChunk instanceof Buffer? dataChunk: new Buffer(dataChunk);
response.on("data", (dataChunk: string | Buffer) => {
const buffer: Buffer = dataChunk instanceof Buffer ? dataChunk : new Buffer(dataChunk);
let byteOrderMarkLength: number = 0;
if (!encoding) {
if (dataChunk[0] == 0xFF &&
Expand Down Expand Up @@ -73,4 +73,4 @@ export class HttpClient {
});
});
}
}
}
1 change: 1 addition & 0 deletions src/JSON.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class Token extends Segment {
super(_startIndex);
}

// tslint:disable-next-line:no-reserved-keywords // Not worth risk to change
public get type(): TokenType {
return this._type;
}
Expand Down
20 changes: 10 additions & 10 deletions src/PositionContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,25 +307,25 @@ export class PositionContext {
}

private static createPropertyCompletionItem(propertyName: string, replaceSpan: language.Span): Completion.Item {
return new Completion.Item(propertyName, `${propertyName}$0`, replaceSpan, "(property)", "", Completion.Type.Property);
return new Completion.Item(propertyName, `${propertyName}$0`, replaceSpan, "(property)", "", Completion.CompletionKind.Property);
}

public get references(): Reference.List {
if (this._references === undefined) {
this._references = null;

let referenceName: string = null;
let referenceType: Reference.Type = null;
let referenceType: Reference.ReferenceKind = null;

const tleStringValue: TLE.StringValue = TLE.asStringValue(this.tleValue);
if (tleStringValue) {
referenceName = tleStringValue.toString();

if (tleStringValue.isParametersArgument()) {
referenceType = Reference.Type.Parameter;
referenceType = Reference.ReferenceKind.Parameter;
}
else if (tleStringValue.isVariablesArgument()) {
referenceType = Reference.Type.Variable;
referenceType = Reference.ReferenceKind.Variable;
}
}

Expand All @@ -336,12 +336,12 @@ export class PositionContext {

const parameterDefinition: ParameterDefinition = this._deploymentTemplate.getParameterDefinition(referenceName);
if (parameterDefinition && parameterDefinition.name === jsonStringValue) {
referenceType = Reference.Type.Parameter;
referenceType = Reference.ReferenceKind.Parameter;
}
else {
const variableDefinition: Json.Property = this._deploymentTemplate.getVariableDefinition(referenceName);
if (variableDefinition && variableDefinition.name === jsonStringValue) {
referenceType = Reference.Type.Variable;
referenceType = Reference.ReferenceKind.Variable;
}
}
}
Expand Down Expand Up @@ -461,7 +461,7 @@ export class PositionContext {
insertText += "($0)";
}

completionItems.push(new Completion.Item(name, insertText, replaceSpan, `(function) ${functionMetadata.usage}`, functionMetadata.description, Completion.Type.Function));
completionItems.push(new Completion.Item(name, insertText, replaceSpan, `(function) ${functionMetadata.usage}`, functionMetadata.description, Completion.CompletionKind.Function));
}
return completionItems;
});
Expand All @@ -474,7 +474,7 @@ export class PositionContext {
const parameterDefinitionMatches: ParameterDefinition[] = this._deploymentTemplate.findParameterDefinitionsWithPrefix(prefix);
for (const parameterDefinition of parameterDefinitionMatches) {
const name: string = `'${parameterDefinition.name}'`;
parameterCompletions.push(new Completion.Item(name, `${name}${replaceSpanInfo.includeRightParenthesisInCompletion ? ")" : ""}$0`, replaceSpanInfo.replaceSpan, `(parameter)`, parameterDefinition.description, Completion.Type.Parameter));
parameterCompletions.push(new Completion.Item(name, `${name}${replaceSpanInfo.includeRightParenthesisInCompletion ? ")" : ""}$0`, replaceSpanInfo.replaceSpan, `(parameter)`, parameterDefinition.description, Completion.CompletionKind.Parameter));
}
return parameterCompletions;
}
Expand All @@ -486,7 +486,7 @@ export class PositionContext {
const variableDefinitionMatches: Json.Property[] = this._deploymentTemplate.findVariableDefinitionsWithPrefix(prefix);
for (const variableDefinition of variableDefinitionMatches) {
const variableName: string = `'${variableDefinition.name.toString()}'`;
variableCompletions.push(new Completion.Item(variableName, `${variableName}${replaceSpanInfo.includeRightParenthesisInCompletion ? ")" : ""}$0`, replaceSpanInfo.replaceSpan, `(variable)`, "", Completion.Type.Variable));
variableCompletions.push(new Completion.Item(variableName, `${variableName}${replaceSpanInfo.includeRightParenthesisInCompletion ? ")" : ""}$0`, replaceSpanInfo.replaceSpan, `(variable)`, "", Completion.CompletionKind.Variable));
}
return variableCompletions;
}
Expand Down Expand Up @@ -536,4 +536,4 @@ export class PositionContext {
interface ReplaceSpanInfo {
includeRightParenthesisInCompletion: boolean;
replaceSpan: language.Span;
}
}
10 changes: 5 additions & 5 deletions src/Reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import * as language from "./Language";
* A list of references that have been found.
*/
export class List {
constructor(private _type: Type, private _spans: language.Span[] = []) {
constructor(private _type: ReferenceKind, private _spans: language.Span[] = []) {
assert(_type !== null, "Cannot create a reference list a null type.");
assert(_type !== undefined, "Cannot create a reference list an undefined type.");
assert(_spans, "Cannot create a reference list with a null spans array.");
Expand All @@ -24,7 +24,7 @@ export class List {
return this._spans;
}

public get type(): Type {
public get kind(): ReferenceKind {
return this._type;
}

Expand All @@ -36,7 +36,7 @@ export class List {

public addAll(list: List): void {
assert(list, "Cannot add all of the references from a null or undefined list.");
assert.deepStrictEqual(this._type, list.type, "Cannot add references from a list of a different reference type.");
assert.deepStrictEqual(this._type, list.kind, "Cannot add references from a list of a different reference type.");

for (const span of list.spans) {
this.add(span);
Expand All @@ -57,8 +57,8 @@ export class List {
}
}

export enum Type {
export enum ReferenceKind {
Parameter,

Variable
}
}
4 changes: 2 additions & 2 deletions src/SurveyMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class SurveyMetadata {
}

public static fromUrl(metadataUrl: string): Promise<SurveyMetadata> {
return HttpClient.get(metadataUrl).then((content: string) => {
return HttpClient.request(metadataUrl).then((content: string) => {
return SurveyMetadata.fromString(content);
});
}
Expand Down Expand Up @@ -101,4 +101,4 @@ interface SurveyMetadataContract {
daysBetweenSurveys?: number;
surveyLink?: string;
}
}
}
Loading

0 comments on commit 1ddb740

Please sign in to comment.