From a6968ca0cada59f780a3751c57788759c0fb9e75 Mon Sep 17 00:00:00 2001 From: Shachar Langbeheim Date: Sun, 1 Oct 2023 15:15:43 +0000 Subject: [PATCH 1/2] add import sort and warnings as errors to TS lint. --- .eslintrc.cjs | 14 ++++++++++---- .github/workflows/lint-ts.yml | 2 +- node/tests/RedisClusterClient.test.ts | 4 ++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 407312ff32..1061ade06c 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -1,7 +1,12 @@ module.exports = { - extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"], + extends: [ + "eslint:recommended", + "plugin:@typescript-eslint/recommended", + "plugin:import/errors", + "plugin:import/warnings", + ], parser: "@typescript-eslint/parser", - plugins: ["@typescript-eslint", 'eslint-plugin-tsdoc'], + plugins: ["@typescript-eslint", "eslint-plugin-tsdoc", "import"], root: true, env: { browser: true, @@ -9,6 +14,7 @@ module.exports = { jest: true, }, rules: { - 'tsdoc/syntax': 'error' - } + "tsdoc/syntax": "error", + "import/no-unresolved": "off", + }, }; diff --git a/.github/workflows/lint-ts.yml b/.github/workflows/lint-ts.yml index 14b3ae712c..99fdef5c6d 100644 --- a/.github/workflows/lint-ts.yml +++ b/.github/workflows/lint-ts.yml @@ -24,4 +24,4 @@ jobs: run: | npm install @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint-plugin-tsdoc eslint typescript npm i - npx eslint . + npx eslint . --max-warnings=0 diff --git a/node/tests/RedisClusterClient.test.ts b/node/tests/RedisClusterClient.test.ts index 93c11fb981..5f56b88c52 100644 --- a/node/tests/RedisClusterClient.test.ts +++ b/node/tests/RedisClusterClient.test.ts @@ -7,12 +7,12 @@ import { it, } from "@jest/globals"; import { exec } from "child_process"; -import { ClusterTransaction } from "../"; import { + ClusterTransaction, ConnectionOptions, InfoOptions, RedisClusterClient, -} from "../build-ts"; +} from "../"; import { convertMultiNodeResponseToDict } from "../src/RedisClusterClient"; import { runBaseTests } from "./SharedTests"; import { flushallOnPort, transactionTest } from "./TestUtilities"; From eecccd0d4ec52773047614b630953491c50a868d Mon Sep 17 00:00:00 2001 From: Shachar Langbeheim Date: Sun, 1 Oct 2023 16:26:02 +0000 Subject: [PATCH 2/2] Run Eslint on each folder, and fail on warnings. --- .github/workflows/lint-ts.yml | 20 ++++++++++++++++++-- .github/workflows/lint-ts/action.yml | 23 +++++++++++++++++++++++ node/tests/RedisClientInternals.test.ts | 12 +++++++----- 3 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/lint-ts/action.yml diff --git a/.github/workflows/lint-ts.yml b/.github/workflows/lint-ts.yml index 99fdef5c6d..73231d450c 100644 --- a/.github/workflows/lint-ts.yml +++ b/.github/workflows/lint-ts.yml @@ -20,8 +20,24 @@ jobs: timeout-minutes: 10 steps: - uses: actions/checkout@v4 + + - uses: ./.github/workflows/lint-ts + with: + package-folder: ./node + name: lint node + + - uses: ./.github/workflows/lint-ts + with: + package-folder: ./benchmarks/node + name: lint benchmark + + - uses: ./.github/workflows/lint-ts + with: + package-folder: ./benchmarks/utilities + name: lint benchmark utilities + - name: lint ts run: | - npm install @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint-plugin-tsdoc eslint typescript + npm install @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint-plugin-tsdoc eslint typescript eslint-plugin-import@latest eslint-config-prettier npm i - npx eslint . --max-warnings=0 + npx eslint . diff --git a/.github/workflows/lint-ts/action.yml b/.github/workflows/lint-ts/action.yml new file mode 100644 index 0000000000..d2eff7f9e3 --- /dev/null +++ b/.github/workflows/lint-ts/action.yml @@ -0,0 +1,23 @@ +name: Lint TypeScript + +inputs: + package-folder: + description: "folder that contains the target Cargo.toml file" + required: true + type: string + +runs: + using: "composite" + + steps: + - uses: actions/checkout@v4 + + - run: cp .eslintrc.cjs ${{ inputs.package-folder }} + shell: bash + + - run: | + npm install @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint-plugin-tsdoc eslint typescript eslint-plugin-import@latest eslint-config-prettier + npm i + npx eslint . --max-warnings=0 + working-directory: ${{ inputs.package-folder }} + shell: bash diff --git a/node/tests/RedisClientInternals.test.ts b/node/tests/RedisClientInternals.test.ts index 5b122c3475..a85ab1ac44 100644 --- a/node/tests/RedisClientInternals.test.ts +++ b/node/tests/RedisClientInternals.test.ts @@ -50,7 +50,7 @@ function sendResponse( const new_response = response.Response.create(); new_response.callbackIdx = callbackIndex; if (responseType == ResponseType.Value) { - const pointer = createLeakedValue(message!); + const pointer = createLeakedValue(message ?? "fake value"); const pointer_number = Number(pointer.toString()); new_response.respPointer = pointer_number; } else if (responseType == ResponseType.ClosingError) { @@ -86,9 +86,7 @@ function getConnectionAndSocket( path.join(os.tmpdir(), `socket_listener`) ); const socketName = path.join(temporaryFolder, "read"); - let connectionPromise: - | Promise - | undefined = undefined; + let connectionPromise: Promise; // eslint-disable-line prefer-const const server = net .createServer(async (socket) => { socket.once("data", (data) => { @@ -105,7 +103,11 @@ function getConnectionAndSocket( sendResponse(socket, ResponseType.Null, 0); }); - const connection = await connectionPromise!; + if (!connectionPromise) { + throw new Error("connectionPromise wasn't set"); + } + + const connection = await connectionPromise; resolve({ connection, socket,