From b024cc52e788690e58b45a9cf55cd757451e7023 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Thu, 30 Nov 2023 13:22:27 +0100 Subject: [PATCH] ci: Fix lint warnings in `@n8n/chat` and `@n8n/nodes-langchain` (no-changelog) (#7884) Solve lint warnings shown on all PRs for `@n8n/chat` and `@n8n/nodes-langchain` Example: https://github.com/n8n-io/n8n/pull/7883/files --- packages/@n8n/chat/.eslintrc.cjs | 5 ++-- .../@n8n/chat/src/__tests__/index.spec.ts | 4 ++-- .../nodes/llms/LMOpenAi/LmOpenAi.node.ts | 12 ++++------ .../vector_store/shared/methods/listSearch.ts | 24 ++++++++++--------- 4 files changed, 22 insertions(+), 23 deletions(-) diff --git a/packages/@n8n/chat/.eslintrc.cjs b/packages/@n8n/chat/.eslintrc.cjs index 45e532bdee..58013559d5 100644 --- a/packages/@n8n/chat/.eslintrc.cjs +++ b/packages/@n8n/chat/.eslintrc.cjs @@ -9,6 +9,8 @@ module.exports = { ...sharedOptions(__dirname, 'frontend'), rules: { + 'n8n-local-rules/dangerously-use-html-string-missing': 'off', + // TODO: Remove these 'id-denylist': 'warn', 'import/extensions': 'warn', @@ -31,9 +33,7 @@ module.exports = { '@typescript-eslint/no-unnecessary-boolean-literal-compare': 'warn', '@typescript-eslint/no-unnecessary-type-assertion': 'warn', '@typescript-eslint/no-unsafe-argument': 'warn', - '@typescript-eslint/no-unsafe-assignment': 'warn', '@typescript-eslint/no-unsafe-call': 'warn', - '@typescript-eslint/no-unsafe-member-access': 'warn', '@typescript-eslint/no-unsafe-return': 'warn', '@typescript-eslint/no-unused-expressions': 'warn', '@typescript-eslint/no-unused-vars': 'warn', @@ -42,7 +42,6 @@ module.exports = { '@typescript-eslint/prefer-nullish-coalescing': 'warn', '@typescript-eslint/prefer-optional-chain': 'warn', '@typescript-eslint/restrict-plus-operands': 'warn', - '@typescript-eslint/restrict-template-expressions': 'warn', '@typescript-eslint/unbound-method': 'warn', '@typescript-eslint/ban-ts-comment': ['warn', { 'ts-ignore': true }], '@typescript-eslint/no-redundant-type-constituents': 'warn', diff --git a/packages/@n8n/chat/src/__tests__/index.spec.ts b/packages/@n8n/chat/src/__tests__/index.spec.ts index 6a63ae02f1..4dd82c53c6 100644 --- a/packages/@n8n/chat/src/__tests__/index.spec.ts +++ b/packages/@n8n/chat/src/__tests__/index.spec.ts @@ -86,7 +86,7 @@ describe('createChat()', () => { expect.objectContaining({ method: 'POST', headers: {}, - body: expect.stringMatching(/"action":"loadPreviousSession"/), + body: expect.stringContaining('"action":"loadPreviousSession"') as unknown, mode: 'cors', cache: 'no-cache', }), @@ -160,7 +160,7 @@ describe('createChat()', () => { expect.objectContaining({ method: 'POST', headers: {}, - body: expect.stringMatching(/"action":"sendMessage"/), + body: expect.stringMatching(/"action":"sendMessage"/) as unknown, mode: 'cors', cache: 'no-cache', }), diff --git a/packages/@n8n/nodes-langchain/nodes/llms/LMOpenAi/LmOpenAi.node.ts b/packages/@n8n/nodes-langchain/nodes/llms/LMOpenAi/LmOpenAi.node.ts index dcf020a9e4..3f6a94d65e 100644 --- a/packages/@n8n/nodes-langchain/nodes/llms/LMOpenAi/LmOpenAi.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/llms/LMOpenAi/LmOpenAi.node.ts @@ -192,13 +192,11 @@ export class LmOpenAi implements INodeType { uri = `${options.baseURL}/models`; } - const data = ( - await this.helpers.requestWithAuthentication.call(this, 'openAiApi', { - method: 'GET', - uri, - json: true, - }) - ).data as Array<{ owned_by: string; id: string }>; + const { data } = (await this.helpers.requestWithAuthentication.call(this, 'openAiApi', { + method: 'GET', + uri, + json: true, + })) as { data: Array<{ owned_by: string; id: string }> }; for (const model of data) { if (!model.owned_by?.startsWith('system')) continue; diff --git a/packages/@n8n/nodes-langchain/nodes/vector_store/shared/methods/listSearch.ts b/packages/@n8n/nodes-langchain/nodes/vector_store/shared/methods/listSearch.ts index 07bf6bd026..13ee71c273 100644 --- a/packages/@n8n/nodes-langchain/nodes/vector_store/shared/methods/listSearch.ts +++ b/packages/@n8n/nodes-langchain/nodes/vector_store/shared/methods/listSearch.ts @@ -1,4 +1,4 @@ -import type { IDataObject, ILoadOptionsFunctions } from 'n8n-workflow'; +import { ApplicationError, type IDataObject, type ILoadOptionsFunctions } from 'n8n-workflow'; import { Pinecone } from '@pinecone-database/pinecone'; export async function pineconeIndexSearch(this: ILoadOptionsFunctions) { @@ -24,16 +24,18 @@ export async function supabaseTableNameSearch(this: ILoadOptionsFunctions) { const results = []; - const paths = ( - await this.helpers.requestWithAuthentication.call(this, 'supabaseApi', { - headers: { - Prefer: 'return=representation', - }, - method: 'GET', - uri: `${credentials.host}/rest/v1/`, - json: true, - }) - ).paths as IDataObject; + if (typeof credentials.host !== 'string') { + throw new ApplicationError('Expected Supabase credentials host to be a string'); + } + + const { paths } = (await this.helpers.requestWithAuthentication.call(this, 'supabaseApi', { + headers: { + Prefer: 'return=representation', + }, + method: 'GET', + uri: `${credentials.host}/rest/v1/`, + json: true, + })) as { paths: IDataObject }; for (const path of Object.keys(paths)) { //omit introspection path