Skip to content

Commit

Permalink
Use ESlint instead of TSlint (#7719)
Browse files Browse the repository at this point in the history
Migrated TSlint configs to ESlint ones using [tslint-to-eslint-config](https://github.com/typescript-eslint/tslint-to-eslint-config) tool, and refined the configs to better match the current coding style.

Changes:
- [member-delimiter-style](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/member-delimiter-style.md#options) that as suggested default for type definition to be  with `semicolon`
- Indentation fixes that is enforced by [eslint-indent](https://eslint.org/docs/rules/indent#options)
- Added dependencies for ESlint with Typescript
- Removed TSlint
  • Loading branch information
horacehylee committed Aug 10, 2021
1 parent 9c501b5 commit a92a005
Show file tree
Hide file tree
Showing 51 changed files with 777 additions and 699 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@

- [auto/nodejs] - Fix a case where inline programs could exit with outstanding async work.
[#7704](https://github.com/pulumi/pulumi/pull/7704)

- [sdk/nodejs] - Use ESlint instead of TSlint
[#7719](https://github.com/pulumi/pulumi/pull/7719)
191 changes: 191 additions & 0 deletions sdk/nodejs/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
module.exports = {
"env": {
"es6": true,
"node": true
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "tsconfig.json",
"sourceType": "module"
},
"plugins": [
"eslint-plugin-import",
"@typescript-eslint",
"header"
],
"ignorePatterns": [
"**/bin/**/*.ts",
"tests/automation/data/tcfg/*.ts",
"tests/sxs_ts_3.6/*.ts",
"tests/sxs_ts_latest/*.ts",
],
"rules": {
"header/header": [
2,
"line",
[
{
"pattern": "Copyright \\d{4}-\\d{4}, Pulumi Corporation."
}
]
],
"@typescript-eslint/dot-notation": "off",
"@typescript-eslint/explicit-member-accessibility": [
"off",
{
"accessibility": "explicit"
}
],
"@typescript-eslint/indent": [
"error",
4,
{
"FunctionDeclaration": {
"parameters": "first"
},
"FunctionExpression": {
"parameters": "first"
}
}
],
"@typescript-eslint/member-delimiter-style": [
"error",
{
"multiline": {
"delimiter": "semi",
"requireLast": true
},
"singleline": {
"delimiter": "semi",
"requireLast": false
}
}
],
"@typescript-eslint/member-ordering": [
"error",
{
"default": [
"static-field",
"instance-field",
"static-method",
"instance-method"
]
}
],
"@typescript-eslint/naming-convention": [
"error",
{
"selector": "default",
"format": null
}
],
"@typescript-eslint/no-empty-function": "error",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-parameter-properties": "off",
"@typescript-eslint/no-require-imports": "off",
"@typescript-eslint/no-shadow": [
"error",
{
"hoist": "all"
}
],
"@typescript-eslint/no-unused-expressions": "error",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/prefer-namespace-keyword": "error",
"@typescript-eslint/quotes": [
"error",
"double",
{
"avoidEscape": true,
"allowTemplateLiterals": true
}
],
"@typescript-eslint/semi": [
"error"
],
"@typescript-eslint/type-annotation-spacing": "error",
"brace-style": "off",
"comma-dangle": [
"error",
"always-multiline"
],
"curly": "error",
"default-case": "error",
"dot-notation": "off",
"eol-last": "error",
"eqeqeq": [
"error",
"smart"
],
"guard-for-in": "error",
"id-blacklist": [
"error",
"any",
"Number",
"number",
"String",
"string",
"Boolean",
"boolean",
"Undefined",
"undefined"
],
"id-match": "error",
"import/order": "off",
"indent": "off",
"no-bitwise": "off",
"no-caller": "error",
"no-cond-assign": "off",
"no-console": [
"error",
{
"allow": [
"log",
"warn",
"dir",
"timeLog",
"assert",
"clear",
"count",
"countReset",
"group",
"groupEnd",
"table",
"dirxml",
"error",
"groupCollapsed",
"Console",
"profile",
"profileEnd",
"timeStamp",
"context"
]
}
],
"no-debugger": "error",
"no-empty": "error",
"no-empty-function": "off",
"no-eval": "error",
"no-fallthrough": "error",
"no-multiple-empty-lines": "off",
"no-new-wrappers": "error",
"no-redeclare": "off",
"no-shadow": "off",
"no-trailing-spaces": "error",
"no-underscore-dangle": "off",
"no-unused-expressions": "error",
"no-unused-labels": "error",
"no-use-before-define": "off",
"no-var": "error",
"prefer-const": "error",
"quotes": "off",
"radix": "error",
"semi": "off",
"spaced-comment": "off",
"@typescript-eslint/no-redeclare": [
"error"
]
}
};
2 changes: 1 addition & 1 deletion sdk/nodejs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ include ../../build/common.mk
export PATH:=$(shell yarn bin 2>/dev/null):$(PATH)

lint::
./node_modules/.bin/tslint -c tslint.json -p tsconfig.json
./node_modules/.bin/eslint -c .eslintrc.js --ext .ts .

build_package::
./node_modules/.bin/tsc
Expand Down
2 changes: 1 addition & 1 deletion sdk/nodejs/asset/archive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export abstract class Archive {
* A private field to help with RTTI that works in SxS scenarios.
* @internal
*/
// tslint:disable-next-line:variable-name
// eslint-disable-next-line @typescript-eslint/naming-convention,no-underscore-dangle,id-blacklist,id-match
public readonly __pulumiArchive: boolean = true;

/**
Expand Down
2 changes: 1 addition & 1 deletion sdk/nodejs/asset/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export abstract class Asset {
* A private field to help with RTTI that works in SxS scenarios.
* @internal
*/
// tslint:disable-next-line:variable-name
// eslint-disable-next-line @typescript-eslint/naming-convention,no-underscore-dangle,id-blacklist,id-match
public readonly __pulumiAsset: boolean = true;

/**
Expand Down
6 changes: 3 additions & 3 deletions sdk/nodejs/automation/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ export function createCommandError(result: CommandResult): CommandError {
const stderr = result.stderr;
return (
notFoundRegex.test(stderr) ? new StackNotFoundError(result) :
alreadyExistsRegex.test(stderr) ? new StackAlreadyExistsError(result) :
stderr.indexOf(conflictText) >= 0 ? new ConcurrentUpdateError(result) :
new CommandError(result)
alreadyExistsRegex.test(stderr) ? new StackAlreadyExistsError(result) :
stderr.indexOf(conflictText) >= 0 ? new ConcurrentUpdateError(result) :
new CommandError(result)
);
}
1 change: 0 additions & 1 deletion sdk/nodejs/automation/projectSettings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

// Copyright 2016-2020, Pulumi Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
2 changes: 1 addition & 1 deletion sdk/nodejs/automation/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class LanguageServer<T> implements grpc.UntypedServiceImplementation {
const engineAddr = args && args.length > 0 ? args[0] : "";

runtime.resetOptions(req.getProject(), req.getStack(), req.getParallel(), engineAddr,
req.getMonitorAddress(), req.getDryrun());
req.getMonitorAddress(), req.getDryrun());

const config: {[key: string]: string} = {};
for (const [k, v] of req.getConfigMap()?.entries() || []) {
Expand Down
60 changes: 30 additions & 30 deletions sdk/nodejs/automation/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,22 @@ export class Stack {
this.workspace = workspace;

switch (mode) {
case "create":
this.ready = workspace.createStack(name);
return this;
case "select":
this.ready = workspace.selectStack(name);
return this;
case "createOrSelect":
this.ready = workspace.createStack(name).catch((err) => {
if (err instanceof StackAlreadyExistsError) {
return workspace.selectStack(name);
}
throw err;
});
return this;
default:
throw new Error(`unexpected Stack creation mode: ${mode}`);
case "create":
this.ready = workspace.createStack(name);
return this;
case "select":
this.ready = workspace.selectStack(name);
return this;
case "createOrSelect":
this.ready = workspace.createStack(name).catch((err) => {
if (err instanceof StackAlreadyExistsError) {
return workspace.selectStack(name);
}
throw err;
});
return this;
default:
throw new Error(`unexpected Stack creation mode: ${mode}`);
}
}
private async readLines(logPath: string, callback: (event: EngineEvent) => void): Promise<ReadlineResult> {
Expand Down Expand Up @@ -659,20 +659,20 @@ export type UpdateResult = "not-started" | "in-progress" | "succeeded" | "failed
* The granular CRUD operation performed on a particular resource during an update.
*/
export type OpType = "same"
| "create"
| "update"
| "delete"
| "replace"
| "create-replacement"
| "delete-replaced"
| "read"
| "read-replacement"
| "refresh"
| "discard"
| "discard-replaced"
| "remove-pending-replace"
| "import"
| "import-replacement";
| "create"
| "update"
| "delete"
| "replace"
| "create-replacement"
| "delete-replaced"
| "read"
| "read-replacement"
| "refresh"
| "discard"
| "discard-replaced"
| "remove-pending-replace"
| "import"
| "import-replacement";

/**
* A map of operation types and their corresponding counts.
Expand Down
2 changes: 1 addition & 1 deletion sdk/nodejs/cmd/dynamic-provider/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ function resultIncludingProvider(result: any, props: any): any {
// rejected the resource, or an initialization error, where the API server has accepted the
// resource, but it failed to initialize (e.g., the app code is continually crashing and the
// resource has failed to become alive).
function grpcResponseFromError(e: {id: string, properties: any, message: string, reasons?: string[]}) {
function grpcResponseFromError(e: {id: string; properties: any; message: string; reasons?: string[]}) {
// Create response object.
const resp = new statusproto.Status();
resp.setCode(grpc.status.UNKNOWN);
Expand Down
2 changes: 2 additions & 0 deletions sdk/nodejs/cmd/run/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ function printErrorUsageAndExit(message: string): never {
function main(args: string[]): void {
// See usage above for the intended usage of this program, including flags and required args.
const argv: minimist.ParsedArgs = minimist(args, {
// eslint-disable-next-line id-blacklist
boolean: [ "dry-run", "query-mode" ],
// eslint-disable-next-line id-blacklist
string: [ "project", "stack", "parallel", "pwd", "monitor", "engine", "tracing" ],
unknown: (arg: string) => {
return true;
Expand Down
2 changes: 1 addition & 1 deletion sdk/nodejs/cmd/run/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export function run(argv: minimist.ParsedArgs,
}
else {
log.error(
`Running program '${program}' failed with an unhandled exception:
`Running program '${program}' failed with an unhandled exception:
${defaultMessage}`);
}

Expand Down
6 changes: 3 additions & 3 deletions sdk/nodejs/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ class ConfigTypeError extends RunError {
class ConfigEnumError extends RunError {
constructor(key: string, v: any, values: any[]) {
super(`Configuration '${key}' value '${v}' is not a legal enum value (${JSON.stringify(values)})`);
}
}
}

/**
Expand All @@ -459,7 +459,7 @@ class ConfigRangeError extends RunError {
range += " chars";
}
super(`Configuration '${key}' value '${v}' is outside of the legal range (${range}, inclusive)`);
}
}
}

/**
Expand All @@ -468,7 +468,7 @@ class ConfigRangeError extends RunError {
class ConfigPatternError extends RunError {
constructor(key: string, v: string, regexp: RegExp) {
super(`Configuration '${key}' value '${v}' does not match the regular expression ${regexp.toString()}`);
}
}
}

/**
Expand Down
4 changes: 2 additions & 2 deletions sdk/nodejs/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class RunError extends Error {
* A private field to help with RTTI that works in SxS scenarios.
* @internal
*/
// tslint:disable-next-line:variable-name
// eslint-disable-next-line @typescript-eslint/naming-convention,no-underscore-dangle,id-blacklist,id-match
public readonly __pulumiRunError: boolean = true;

/**
Expand All @@ -55,7 +55,7 @@ export class ResourceError extends Error {
* A private field to help with RTTI that works in SxS scenarios.
* @internal
*/
// tslint:disable-next-line:variable-name
// eslint-disable-next-line @typescript-eslint/naming-convention, no-underscore-dangle, id-blacklist, id-match
public readonly __pulumResourceError: boolean = true;

/**
Expand Down

0 comments on commit a92a005

Please sign in to comment.