Enable 'use const' linter rule. (#405)

* Enable 'use const' linter rule.
This commit is contained in:
CyrusNajmabadi 2017-10-10 14:50:55 -07:00 committed by GitHub
parent 21812ef4b5
commit b713990b5e
8 changed files with 98 additions and 92 deletions

View file

@ -1,7 +1,7 @@
PROCCNT=$(shell nproc --all)
.PHONY: default
default: banner build test install
default: banner build lint test install
.PHONY: banner
banner:

View file

@ -15,14 +15,14 @@ export function main(args: string[]): void {
process.exit(-1);
return;
}
let monitorAddr: string = args[0];
const monitorAddr: string = args[0];
let serverAddr: string | undefined;
if (args.length > 1) {
serverAddr = args[1];
}
// Finally connect up the gRPC client/server and listen for incoming requests.
let { server, port } = runtime.serveLanguageHost(monitorAddr, serverAddr);
const { server, port } = runtime.serveLanguageHost(monitorAddr, serverAddr);
// Emit the address so the monitor can read it to connect. The gRPC server will keep the message loop alive.
console.log(port);

View file

@ -8,10 +8,10 @@ import { RunError } from "../../errors";
import * as log from "../../log";
import * as runtime from "../../runtime";
let grpc = require("grpc");
let engrpc = require("../../proto/engine_grpc_pb.js");
let langproto = require("../../proto/languages_pb.js");
let langrpc = require("../../proto/languages_grpc_pb.js");
const grpc = require("grpc");
const engrpc = require("../../proto/engine_grpc_pb.js");
const langproto = require("../../proto/languages_pb.js");
const langrpc = require("../../proto/languages_grpc_pb.js");
function usage(): void {
console.error(`usage: RUN <flags> [program] <[arg]...>`);
@ -29,16 +29,16 @@ function usage(): void {
export function main(args: string[]): void {
// See usage above for the intended usage of this program, including flags and required args.
let config: {[key: string]: string} = {};
let argv: minimist.ParsedArgs = minimist(args, {
const config: {[key: string]: string} = {};
const argv: minimist.ParsedArgs = minimist(args, {
boolean: [ "dry-run" ],
string: [ "parallel", "pwd", "monitor", "engine" ],
unknown: (arg: string) => {
// If unknown, first see if it's a --config.k=v flag.
let cix = arg.indexOf("-config");
const cix = arg.indexOf("-config");
if (cix === 0 || cix === 1) {
let kix = arg.indexOf(".");
let vix = arg.indexOf("=");
const kix = arg.indexOf(".");
const vix = arg.indexOf("=");
if (kix === -1 || vix === -1) {
console.error(`fatal: --config flag malformed (expected '--config.key=val')`);
usage();
@ -58,12 +58,12 @@ export function main(args: string[]): void {
});
// Set any configuration keys/values that were found.
for (let key of Object.keys(config)) {
for (const key of Object.keys(config)) {
runtime.setConfig(key, config[key]);
}
// If there is a --pwd directive, switch directories.
let pwd: string | undefined = argv["pwd"];
const pwd: string | undefined = argv["pwd"];
if (pwd) {
process.chdir(pwd);
}
@ -80,18 +80,18 @@ export function main(args: string[]): void {
}
// If ther is a --dry-run directive, flip the switch. This controls whether we are planning vs. really doing it.
let dryRun: boolean = !!(argv["dry-run"]);
const dryRun: boolean = !!(argv["dry-run"]);
// If there is a monitor argument, connect to it.
let monitor: Object | undefined;
let monitorAddr: string | undefined = argv["monitor"];
const monitorAddr: string | undefined = argv["monitor"];
if (monitorAddr) {
monitor = new langrpc.ResourceMonitorClient(monitorAddr, grpc.credentials.createInsecure());
}
// If there is an engine argument, connect to it too.
let engine: Object | undefined;
let engineAddr: string | undefined = argv["engine"];
const engineAddr: string | undefined = argv["engine"];
if (engineAddr) {
engine = new engrpc.EngineClient(engineAddr, grpc.credentials.createInsecure());
}
@ -124,7 +124,7 @@ export function main(args: string[]): void {
}
// Now fake out the process-wide argv, to make the program think it was run normally.
let programArgs: string[] = argv._.slice(1);
const programArgs: string[] = argv._.slice(1);
process.argv = [ process.argv[0], process.argv[1], ...programArgs ];
// Now go ahead and execute the code. This keeps the process alive until the message loop exits.

View file

@ -36,7 +36,7 @@ export class Config {
* @param key The key to lookup.
*/
public getBoolean(key: string): boolean | undefined {
let v: string | undefined = this.get(key);
const v: string | undefined = this.get(key);
if (v === undefined) {
return undefined;
} else if (v === "true") {
@ -54,11 +54,11 @@ export class Config {
* @param key The key to lookup.
*/
public getNumber(key: string): number | undefined {
let v: string | undefined = this.get(key);
const v: string | undefined = this.get(key);
if (v === undefined) {
return undefined;
}
let f: number = parseFloat(v);
const f: number = parseFloat(v);
if (isNaN(f)) {
throw new ConfigTypeError(this.fullKey(key), v, "number");
}
@ -72,7 +72,7 @@ export class Config {
* @param key The key to lookup.
*/
public getObject<T>(key: string): T | undefined {
let v: string | undefined = this.get(key);
const v: string | undefined = this.get(key);
if (v === undefined) {
return undefined;
}
@ -90,7 +90,7 @@ export class Config {
* @param key The key to lookup.
*/
public require(key: string): string {
let v: string | undefined = this.get(key);
const v: string | undefined = this.get(key);
if (v === undefined) {
throw new ConfigMissingError(this.fullKey(key));
}
@ -104,7 +104,7 @@ export class Config {
* @param key The key to lookup.
*/
public requireBoolean(key: string): boolean {
let v: boolean | undefined = this.getBoolean(key);
const v: boolean | undefined = this.getBoolean(key);
if (v === undefined) {
throw new ConfigMissingError(this.fullKey(key));
}
@ -118,7 +118,7 @@ export class Config {
* @param key The key to lookup.
*/
public requireNumber(key: string): number {
let v: number | undefined = this.getNumber(key);
const v: number | undefined = this.getNumber(key);
if (v === undefined) {
throw new ConfigMissingError(this.fullKey(key));
}
@ -132,7 +132,7 @@ export class Config {
* @param key The key to lookup.
*/
public requireObject<T>(key: string): T {
let v: T | undefined = this.getObject<T>(key);
const v: T | undefined = this.getObject<T>(key);
if (v === undefined) {
throw new ConfigMissingError(this.fullKey(key));
}
@ -165,7 +165,7 @@ class ConfigMissingError extends RunError {
constructor(public key: string) {
super(
`Missing required configuration variable '${key}'\n` +
`\tplease set a value using the command \`pulumi config ${key} <value>\``
`\tplease set a value using the command \`pulumi config ${key} <value>\``,
);
}
}

View file

@ -7,7 +7,7 @@
"clean": "rm -rf bin/ && rm -rf runtime/native/build",
"build": "yarn run copyprotos && yarn run buildnative && tsc && yarn run binplace && yarn run lint",
"buildnative": "cd runtime/native/ && node-gyp build",
"lint": "tslint '{,!(node_modules|bin)/!(bin|node_modules)**/}(*.d).ts'",
"lint": "tslint -c tslint.json '{,!(bin|doc|node_modules|vendor)/!(bin|node_modules)**/}!(*.d).ts'",
"copyprotos": "cp -R ../proto/nodejs/. proto/",
"binplaceprotos": "cp -R proto/. bin/proto/",
"binplacenative": "mkdir -p bin/runtime/native/ && cp -R runtime/native/build/. bin/runtime/native/build/",

View file

@ -1,8 +1,8 @@
// Copyright 2016-2017, Pulumi Corporation. All rights reserved.
import * as assert from "assert";
import { asyncTest, assertAsyncThrows } from "../util";
import { runtime } from "../../index";
import { assertAsyncThrows, asyncTest } from "../util";
interface ClosureCase {
title: string; // a title banner for the test case.
@ -16,134 +16,134 @@ interface ClosureCase {
describe("closure", () => {
describe("hash", () => {
it("is affected by code.", () => {
let closure1: runtime.Closure = {
const closure1: runtime.Closure = {
code: "",
runtime: "",
environment: { }
environment: { },
};
let closure2: runtime.Closure = {
const closure2: runtime.Closure = {
code: "1",
runtime: "",
environment: { }
environment: { },
};
let hash1 = runtime.getClosureHash_forTestingPurposes(closure1);
let hash2 = runtime.getClosureHash_forTestingPurposes(closure2);
const hash1 = runtime.getClosureHash_forTestingPurposes(closure1);
const hash2 = runtime.getClosureHash_forTestingPurposes(closure2);
assert.notEqual(hash1, hash2);
});
it("is affected by runtime.", () => {
let closure1: runtime.Closure = {
const closure1: runtime.Closure = {
code: "",
runtime: "",
environment: { }
environment: { },
};
let closure2: runtime.Closure = {
const closure2: runtime.Closure = {
code: "",
runtime: "1",
environment: { }
environment: { },
};
let hash1 = runtime.getClosureHash_forTestingPurposes(closure1);
let hash2 = runtime.getClosureHash_forTestingPurposes(closure2);
const hash1 = runtime.getClosureHash_forTestingPurposes(closure1);
const hash2 = runtime.getClosureHash_forTestingPurposes(closure2);
assert.notEqual(hash1, hash2);
});
it("is affected by module.", () => {
let closure1: runtime.Closure = {
const closure1: runtime.Closure = {
code: "",
runtime: "",
environment: { cap1: { module: "m1" } }
environment: { cap1: { module: "m1" } },
};
let closure2: runtime.Closure = {
const closure2: runtime.Closure = {
code: "",
runtime: "",
environment: { cap1: { module: "m2" } }
environment: { cap1: { module: "m2" } },
};
let hash1 = runtime.getClosureHash_forTestingPurposes(closure1);
let hash2 = runtime.getClosureHash_forTestingPurposes(closure2);
const hash1 = runtime.getClosureHash_forTestingPurposes(closure1);
const hash2 = runtime.getClosureHash_forTestingPurposes(closure2);
assert.notEqual(hash1, hash2);
});
it("is affected by environment values.", () => {
let closure1: runtime.Closure = {
const closure1: runtime.Closure = {
code: "",
runtime: "",
environment: { }
environment: { },
};
let closure2: runtime.Closure = {
const closure2: runtime.Closure = {
code: "",
runtime: "",
environment: { cap1: { json: 100 } }
environment: { cap1: { json: 100 } },
};
let hash1 = runtime.getClosureHash_forTestingPurposes(closure1);
let hash2 = runtime.getClosureHash_forTestingPurposes(closure2);
const hash1 = runtime.getClosureHash_forTestingPurposes(closure1);
const hash2 = runtime.getClosureHash_forTestingPurposes(closure2);
assert.notEqual(hash1, hash2);
});
it("is affected by environment names.", () => {
let closure1: runtime.Closure = {
const closure1: runtime.Closure = {
code: "",
runtime: "",
environment: { cap1: { json: 100 } }
environment: { cap1: { json: 100 } },
};
let closure2: runtime.Closure = {
const closure2: runtime.Closure = {
code: "",
runtime: "",
environment: { cap2: { json: 100 } }
environment: { cap2: { json: 100 } },
};
let hash1 = runtime.getClosureHash_forTestingPurposes(closure1);
let hash2 = runtime.getClosureHash_forTestingPurposes(closure2);
const hash1 = runtime.getClosureHash_forTestingPurposes(closure1);
const hash2 = runtime.getClosureHash_forTestingPurposes(closure2);
assert.notEqual(hash1, hash2);
});
it("is not affected by environment order.", () => {
let closure1: runtime.Closure = {
const closure1: runtime.Closure = {
code: "",
runtime: "",
environment: { cap1: { json: 100 }, cap2: { json: 200 } }
environment: { cap1: { json: 100 }, cap2: { json: 200 } },
};
let closure2: runtime.Closure = {
const closure2: runtime.Closure = {
code: "",
runtime: "",
environment: { cap2: { json: 200 }, cap1: { json: 100 } }
environment: { cap2: { json: 200 }, cap1: { json: 100 } },
};
let hash1 = runtime.getClosureHash_forTestingPurposes(closure1);
let hash2 = runtime.getClosureHash_forTestingPurposes(closure2);
const hash1 = runtime.getClosureHash_forTestingPurposes(closure1);
const hash2 = runtime.getClosureHash_forTestingPurposes(closure2);
assert.equal(hash1, hash2);
});
it("is different with cyclic and non-cyclic environments.", () => {
let closure1: runtime.Closure = {
const closure1: runtime.Closure = {
code: "",
runtime: "",
environment: { cap1: { json: 100 } }
environment: { cap1: { json: 100 } },
};
closure1.environment.cap1.closure = closure1;
let closure2: runtime.Closure = {
const closure2: runtime.Closure = {
code: "",
runtime: "",
environment: { cap1: { json: 100 } }
environment: { cap1: { json: 100 } },
};
let hash1 = runtime.getClosureHash_forTestingPurposes(closure1);
let hash2 = runtime.getClosureHash_forTestingPurposes(closure2);
const hash1 = runtime.getClosureHash_forTestingPurposes(closure1);
const hash2 = runtime.getClosureHash_forTestingPurposes(closure2);
assert.notEqual(hash1, hash2);
});
});
let cases: ClosureCase[] = [];
const cases: ClosureCase[] = [];
// A few simple positive cases for functions/arrows (no captures).
cases.push({
@ -228,10 +228,10 @@ return (function () { })
closureHash: "__47ac0033692c3101b014a1a3c17a4318cf7d4330",
});
{
let wcap = "foo";
let xcap = 97;
let ycap = [ true, -1, "yup" ];
let zcap = {
const wcap = "foo";
const xcap = 97;
const ycap = [ true, -1, "yup" ];
const zcap = {
a: "a",
b: false,
c: [ 0 ],
@ -270,10 +270,14 @@ return (function () { })
});
}
{
let nocap1 = 1, nocap2 = 2, nocap3 = 3, nocap4 = 4, nocap5 = 5, nocap6 = 6, nocap7 = 7,
nocap8 = 8, nocap9 = 9, nocap10 = 10;
// tslint:disable-next-line
let nocap1 = 1, nocap2 = 2, nocap3 = 3, nocap4 = 4, nocap5 = 5, nocap6 = 6, nocap7 = 7;
// tslint:disable-next-line
let nocap8 = 8, nocap9 = 9, nocap10 = 10;
// tslint:disable-next-line
let cap1 = 100, cap2 = 200, cap3 = 300, cap4 = 400;
let functext = `((nocap1, nocap2) => {
const functext = `((nocap1, nocap2) => {
let zz = nocap1 + nocap2; // not a capture: args
let yy = nocap3; // not a capture: var later on
if (zz) {
@ -332,7 +336,7 @@ return (function () { })
closureHash: "__fa1c10acee8dd79b39d0f8109d2bc3252b19619a",
});
{
let os = require("os");
const os = require("os");
cases.push({
title: "Capture built-in modules as stable references, not serialized values",
func: () => os,
@ -349,7 +353,7 @@ return (function () { })
});
}
{
let util = require("../util");
const util = require("../util");
cases.push({
title: "Capture user-defined modules as stable references, not serialized values",
func: () => util,
@ -379,16 +383,16 @@ return (function () { })
// Recursive function serialization.
{
let fff = "fff!";
let ggg = "ggg!";
let xcap = {
const fff = "fff!";
const ggg = "ggg!";
const xcap = {
fff: function () { console.log(fff); },
ggg: () => { console.log(ggg); },
zzz: {
a: [ (a1: any, a2: any) => { console.log(a1 + a2); } ],
},
};
let functext = `(() => {
const functext = `(() => {
xcap.fff();
xcap.ggg();
xcap.zzz.a[0]("x", "y");
@ -449,8 +453,8 @@ return (function () { })
}
// Closing over 'this'. This yields a circular closure.
let cap: any = new CapCap();
let env: runtime.Environment = { "this": {} };
const cap: any = new CapCap();
const env: runtime.Environment = { "this": {} };
env["this"].obj = {
f: {
closure: {
@ -488,17 +492,17 @@ return (function () { })
});
// Now go ahead and run the test cases, each as its own case.
for (let test of cases) {
for (const test of cases) {
it(test.title, asyncTest(async () => {
if (test.expect) {
let closure: runtime.Closure = await runtime.serializeClosure(test.func);
const closure: runtime.Closure = await runtime.serializeClosure(test.func);
assert.deepEqual(closure, test.expect);
if (test.expectText) {
let text = runtime.serializeJavaScriptText(closure);
const text = runtime.serializeJavaScriptText(closure);
assert.equal(text, test.expectText);
}
let closureHash = runtime.getClosureHash_forTestingPurposes(closure);
const closureHash = runtime.getClosureHash_forTestingPurposes(closure);
assert.equal(closureHash, test.closureHash);
} else {
await assertAsyncThrows(async () => {

View file

@ -73,6 +73,7 @@
"check-whitespace"
],
"ordered-imports": true,
"prefer-const": true,
"quotemark": [
true,
"double",

View file

@ -69,6 +69,7 @@
"check-whitespace"
],
"ordered-imports": true,
"prefer-const": true,
"quotemark": [
true,
"double",
@ -122,4 +123,4 @@
]
}
}
}