From 81baa44085e92847d6ae7007077a2ee3714fec3d Mon Sep 17 00:00:00 2001 From: "street-side-software-automation[bot]" <74785433+street-side-software-automation[bot]@users.noreply.github.com> Date: Tue, 21 May 2024 09:52:03 +0200 Subject: [PATCH] ci: Fix Lint -- Workflow Bot (#5642) Co-authored-by: Jason3S <3740137+Jason3S@users.noreply.github.com> --- .../cspell-eslint-plugin/src/worker/spellCheck.mts | 4 ++-- packages/cspell-io/src/VirtualFs.test.ts | 6 +++--- packages/cspell-io/src/errors/error.test.ts | 8 ++++---- packages/cspell-io/src/errors/error.ts | 2 +- .../cspell-io/src/node/file/FetchError.test.ts | 4 ++-- packages/cspell-io/src/node/file/FetchError.ts | 2 +- .../Controller/configLoader/configLoader.test.ts | 2 +- packages/cspell-lib/src/lib/util/errors.test.ts | 8 ++++---- .../src/SystemServiceBus.test.ts | 2 +- packages/cspell-service-bus/src/assert.test.ts | 14 +++++++------- packages/cspell-service-bus/src/assert.ts | 2 +- packages/cspell-service-bus/src/bus.test.ts | 6 +++--- packages/cspell-tools/src/shasum/shasum.test.ts | 4 ++-- packages/cspell-tools/src/shasum/shasum.ts | 4 ++-- packages/cspell-tools/src/util/errors.test.ts | 8 ++++---- packages/cspell/src/app/util/reporters.test.ts | 2 +- .../test-cspell-service-bus-esm/src/index.test.mts | 6 +++--- .../src/index.test.mts | 6 +++--- 18 files changed, 45 insertions(+), 45 deletions(-) diff --git a/packages/cspell-eslint-plugin/src/worker/spellCheck.mts b/packages/cspell-eslint-plugin/src/worker/spellCheck.mts index 23f6dac0ef5b..c92c1565fd82 100644 --- a/packages/cspell-eslint-plugin/src/worker/spellCheck.mts +++ b/packages/cspell-eslint-plugin/src/worker/spellCheck.mts @@ -471,7 +471,7 @@ async function reportConfigurationErrors(config: CSpellSettings, knownConfigErro const key = ref.error.toString(); if (knownConfigErrors.has(key)) return; knownConfigErrors.add(key); - errors.push(Error('Configuration Error: \n ' + ref.error.message)); + errors.push(new Error('Configuration Error: \n ' + ref.error.message)); }); const dictCollection = await getDictionary(config); @@ -483,7 +483,7 @@ async function reportConfigurationErrors(config: CSpellSettings, knownConfigErro if (knownConfigErrors.has(key)) return; knownConfigErrors.add(key); const errMsg = `${msg}: ${error.message}\n Source: ${dict.source}`; - errors.push(Error(errMsg)); + errors.push(new Error(errMsg)); }); }); diff --git a/packages/cspell-io/src/VirtualFs.test.ts b/packages/cspell-io/src/VirtualFs.test.ts index dddc719ad8d5..401575595002 100644 --- a/packages/cspell-io/src/VirtualFs.test.ts +++ b/packages/cspell-io/src/VirtualFs.test.ts @@ -147,21 +147,21 @@ describe('VirtualFs', () => { test('try unsupported readFile', async () => { const fs = virtualFs.fs; const result = fs.readFile(new URL('ftp://example.com/data.json')); - await expect(result).rejects.toEqual(Error('Unsupported request: readFile')); + await expect(result).rejects.toEqual(new Error('Unsupported request: readFile')); await expect(result).rejects.toBeInstanceOf(VFSErrorUnsupportedRequest); }); test('try unsupported stat', async () => { const fs = virtualFs.fs; const result = fs.stat(new URL('ftp://example.com/data.json')); - await expect(result).rejects.toEqual(Error('Unsupported request: stat')); + await expect(result).rejects.toEqual(new Error('Unsupported request: stat')); await expect(result).rejects.toBeInstanceOf(VFSErrorUnsupportedRequest); }); test('try unsupported readDirectory', async () => { const fs = virtualFs.fs; const result = fs.readDirectory(new URL('ftp://example.com/data.json')); - await expect(result).rejects.toEqual(Error('Unsupported request: readDirectory')); + await expect(result).rejects.toEqual(new Error('Unsupported request: readDirectory')); await expect(result).rejects.toBeInstanceOf(VFSErrorUnsupportedRequest); }); diff --git a/packages/cspell-io/src/errors/error.test.ts b/packages/cspell-io/src/errors/error.test.ts index a6f816757d00..5494abf31347 100644 --- a/packages/cspell-io/src/errors/error.test.ts +++ b/packages/cspell-io/src/errors/error.test.ts @@ -5,10 +5,10 @@ import { toError } from './error.js'; describe('errors', () => { test.each` err | expected - ${Error('test')} | ${Error('test')} - ${{ message: 'test' }} | ${Error('test')} - ${'test'} | ${Error('test')} - ${undefined} | ${Error()} + ${new Error('test')} | ${new Error('test')} + ${{ message: 'test' }} | ${new Error('test')} + ${'test'} | ${new Error('test')} + ${undefined} | ${new Error()} `('toError $err', ({ err, expected }) => { expect(toError(err)).toEqual(expected); }); diff --git a/packages/cspell-io/src/errors/error.ts b/packages/cspell-io/src/errors/error.ts index 97fb45944c06..abc476abb2ba 100644 --- a/packages/cspell-io/src/errors/error.ts +++ b/packages/cspell-io/src/errors/error.ts @@ -4,5 +4,5 @@ export function toError(e: unknown): Error { return new Error(e.message, { cause: e }); } // eslint-disable-next-line @typescript-eslint/no-explicit-any - return Error(e && (e as any).toString()); + return new Error(e && (e as any).toString()); } diff --git a/packages/cspell-io/src/node/file/FetchError.test.ts b/packages/cspell-io/src/node/file/FetchError.test.ts index aca4461e3ba3..bd5db8ee9173 100644 --- a/packages/cspell-io/src/node/file/FetchError.test.ts +++ b/packages/cspell-io/src/node/file/FetchError.test.ts @@ -33,8 +33,8 @@ describe('FetchError', () => { test.each` err | expected - ${new Error('Not good')} | ${Error('Not good')} - ${'hello'} | ${Error('Unknown Error')} + ${new Error('Not good')} | ${new Error('Not good')} + ${'hello'} | ${new Error('Unknown Error')} `('toError', ({ err, expected }) => { expect(toError(err)).toEqual(expected); }); diff --git a/packages/cspell-io/src/node/file/FetchError.ts b/packages/cspell-io/src/node/file/FetchError.ts index b856f85a0887..55e9ae836294 100644 --- a/packages/cspell-io/src/node/file/FetchError.ts +++ b/packages/cspell-io/src/node/file/FetchError.ts @@ -55,5 +55,5 @@ export function toFetchUrlError(err: unknown, url: URL): FetchUrlError { } export function toError(err: unknown): Error { - return err instanceof Error ? err : Error('Unknown Error', { cause: err }); + return err instanceof Error ? err : new Error('Unknown Error', { cause: err }); } diff --git a/packages/cspell-lib/src/lib/Settings/Controller/configLoader/configLoader.test.ts b/packages/cspell-lib/src/lib/Settings/Controller/configLoader/configLoader.test.ts index 27a78193933f..9f87ce160174 100644 --- a/packages/cspell-lib/src/lib/Settings/Controller/configLoader/configLoader.test.ts +++ b/packages/cspell-lib/src/lib/Settings/Controller/configLoader/configLoader.test.ts @@ -768,7 +768,7 @@ describe('ConfigLoader with VirtualFS', () => { expect(configFile).toBeInstanceOf(Error); assert(configFile instanceof Error); - expect(configFile.cause).toEqual(Error(`Untrusted URL: "${location?.href}"`)); + expect(configFile.cause).toEqual(new Error(`Untrusted URL: "${location?.href}"`)); }); }); diff --git a/packages/cspell-lib/src/lib/util/errors.test.ts b/packages/cspell-lib/src/lib/util/errors.test.ts index 35e052e00c42..de38d94bf2b7 100644 --- a/packages/cspell-lib/src/lib/util/errors.test.ts +++ b/packages/cspell-lib/src/lib/util/errors.test.ts @@ -58,10 +58,10 @@ describe('errors', () => { }); test.each` - err | expected - ${Error('hello')} | ${Error('hello')} - ${'hello'} | ${Error('hello')} - ${'hello'} | ${expect.any(UnknownError)} + err | expected + ${new Error('hello')} | ${new Error('hello')} + ${'hello'} | ${new Error('hello')} + ${'hello'} | ${expect.any(UnknownError)} `('toError', ({ err, expected }) => { expect(toError(err)).toEqual(expected); }); diff --git a/packages/cspell-service-bus/src/SystemServiceBus.test.ts b/packages/cspell-service-bus/src/SystemServiceBus.test.ts index 5295addc23a9..576e1383f5b4 100644 --- a/packages/cspell-service-bus/src/SystemServiceBus.test.ts +++ b/packages/cspell-service-bus/src/SystemServiceBus.test.ts @@ -76,7 +76,7 @@ describe('SystemServiceBus Behavior', () => { ${RequestFsReadFile.create({ uri: 'file://my_file.txt' })} | ${{ value: 'read file: file://my_file.txt' }} ${RequestFsReadFile.create({ uri: 'https://www.example.com/my_file.txt' })} | ${{ value: 'fetch http: https://www.example.com/my_file.txt' }} ${RequestFsReadFile.create({ uri: 'https://www.example.com/my_dict.trie.gz' })} | ${{ value: 'Inflate: fetch http: https://www.example.com/my_dict.trie.gz' }} - ${{ type: 'zlib:compress' }} | ${{ error: Error('Unhandled Request: zlib:compress') }} + ${{ type: 'zlib:compress' }} | ${{ error: new Error('Unhandled Request: zlib:compress') }} `('dispatch requests', ({ request, expected }) => { expect(serviceBus.dispatch(request)).toEqual(expected); }); diff --git a/packages/cspell-service-bus/src/assert.test.ts b/packages/cspell-service-bus/src/assert.test.ts index c55b8caa1165..0e79f885ab51 100644 --- a/packages/cspell-service-bus/src/assert.test.ts +++ b/packages/cspell-service-bus/src/assert.test.ts @@ -16,13 +16,13 @@ describe('assert', () => { ${true} | ${undefined} | ${undefined} ${1} | ${undefined} | ${undefined} ${'yes'} | ${undefined} | ${undefined} - ${undefined} | ${undefined} | ${Error('AssertionError')} - ${0} | ${undefined} | ${Error('AssertionError')} - ${null} | ${undefined} | ${Error('AssertionError')} - ${''} | ${undefined} | ${Error('AssertionError')} - ${false} | ${undefined} | ${Error('AssertionError')} - ${false} | ${'Must be true or fail'} | ${Error('Must be true or fail')} - ${false} | ${Error('my error')} | ${Error('my error')} + ${undefined} | ${undefined} | ${new Error('AssertionError')} + ${0} | ${undefined} | ${new Error('AssertionError')} + ${null} | ${undefined} | ${new Error('AssertionError')} + ${''} | ${undefined} | ${new Error('AssertionError')} + ${false} | ${undefined} | ${new Error('AssertionError')} + ${false} | ${'Must be true or fail'} | ${new Error('Must be true or fail')} + ${false} | ${new Error('my error')} | ${new Error('my error')} `('compare assert to node assert $value / $message', ({ value, message, expected }) => { expect(catchError(() => assert(value, message))).toEqual(expected); }); diff --git a/packages/cspell-service-bus/src/assert.ts b/packages/cspell-service-bus/src/assert.ts index 981c5c5a3792..0b8b8f0facd1 100644 --- a/packages/cspell-service-bus/src/assert.ts +++ b/packages/cspell-service-bus/src/assert.ts @@ -1,6 +1,6 @@ export function assert(value: unknown, message?: string | Error): asserts value { if (!value) { - const err = message instanceof Error ? message : Error(message ?? 'AssertionError'); + const err = message instanceof Error ? message : new Error(message ?? 'AssertionError'); throw err; } } diff --git a/packages/cspell-service-bus/src/bus.test.ts b/packages/cspell-service-bus/src/bus.test.ts index 9b459ba3a45a..c0e90c854c00 100644 --- a/packages/cspell-service-bus/src/bus.test.ts +++ b/packages/cspell-service-bus/src/bus.test.ts @@ -95,9 +95,9 @@ describe('Service Bus', () => { ${FibRequestFactory.create({ fib: 7 })} | ${response(13)} ${StringLengthRequestFactory.create({ str: 'hello' })} | ${response(5)} ${new StringToUpperRequest('hello')} | ${response('HELLO')} - ${new DoNotHandleRequest()} | ${{ error: Error('Unhandled Request: Do Not Handle') }} - ${new RetryAgainRequest()} | ${{ error: Error('Service Request Depth 10 Exceeded: Retry Again Request') }} - ${new ServiceRequestCls('throw', undefined)} | ${{ error: Error('Unhandled Error in Handler: handlerThrowErrorOnRequest') }} + ${new DoNotHandleRequest()} | ${{ error: new Error('Unhandled Request: Do Not Handle') }} + ${new RetryAgainRequest()} | ${{ error: new Error('Service Request Depth 10 Exceeded: Retry Again Request') }} + ${new ServiceRequestCls('throw', undefined)} | ${{ error: new Error('Unhandled Error in Handler: handlerThrowErrorOnRequest') }} `('serviceBus handle request: $request.type', ({ request, expected }) => { expect(bus.dispatch(request)).toEqual(expected); }); diff --git a/packages/cspell-tools/src/shasum/shasum.test.ts b/packages/cspell-tools/src/shasum/shasum.test.ts index c180dc5771c1..e52fd62db4b1 100644 --- a/packages/cspell-tools/src/shasum/shasum.test.ts +++ b/packages/cspell-tools/src/shasum/shasum.test.ts @@ -78,14 +78,14 @@ describe('shasum', () => { expect(result.passed).toBe(false); expect(result.results.filter((r) => !r.passed)).toHaveLength(1); const missingResult = result.results[0]; - expect(missingResult.error).toEqual(Error('Failed to read file.')); + expect(missingResult.error).toEqual(new Error('Failed to read file.')); }); test('checkShasumFile bad format', async () => { const root = resolvePathToFixture('dicts'); const filename = resolvePathToFixture('dicts/_checksum-bad-format.txt'); await expect(checkShasumFile(filename, [], root)).rejects.toEqual( - Error('Failed to parse line 3 of checksum file.'), + new Error('Failed to parse line 3 of checksum file.'), ); }); diff --git a/packages/cspell-tools/src/shasum/shasum.ts b/packages/cspell-tools/src/shasum/shasum.ts index d89ba399ac82..e9629395f7c2 100644 --- a/packages/cspell-tools/src/shasum/shasum.ts +++ b/packages/cspell-tools/src/shasum/shasum.ts @@ -59,7 +59,7 @@ export async function checkShasumFile( async function tryToCheckFile(filename: string, root: string, checksum: string | undefined): Promise { if (!checksum) { - return { filename, passed: false, error: Error('Missing Checksum.') }; + return { filename, passed: false, error: new Error('Missing Checksum.') }; } const file = resolve(root, filename); @@ -67,7 +67,7 @@ async function tryToCheckFile(filename: string, root: string, checksum: string | const passed = await checkFile(checksum, file); return { filename, passed }; } catch { - return { filename, passed: false, error: Error('Failed to read file.') }; + return { filename, passed: false, error: new Error('Failed to read file.') }; } } diff --git a/packages/cspell-tools/src/util/errors.test.ts b/packages/cspell-tools/src/util/errors.test.ts index 9609ae06d6de..a382930f1868 100644 --- a/packages/cspell-tools/src/util/errors.test.ts +++ b/packages/cspell-tools/src/util/errors.test.ts @@ -14,10 +14,10 @@ describe('errors', () => { test.each` err | expected - ${1} | ${Error('1')} - ${undefined} | ${Error('undefined')} - ${new Error('hello')} | ${Error('hello')} - ${{ name: 'Err' }} | ${Error('[object Object]')} + ${1} | ${new Error('1')} + ${undefined} | ${new Error('undefined')} + ${new Error('hello')} | ${new Error('hello')} + ${{ name: 'Err' }} | ${new Error('[object Object]')} `('toError', ({ err, expected }) => { expect(toError(err)).toEqual(expected); }); diff --git a/packages/cspell/src/app/util/reporters.test.ts b/packages/cspell/src/app/util/reporters.test.ts index 62b1b7ea54a6..85aa963f6425 100644 --- a/packages/cspell/src/app/util/reporters.test.ts +++ b/packages/cspell/src/app/util/reporters.test.ts @@ -42,7 +42,7 @@ describe('mergeReporters', () => { test.each` reporter | expected - ${['@cspell/cspell-json-reporter', false]} | ${Error('Failed to load reporter @cspell/cspell-json-reporter: cspell-json-reporter settings must be an object')} + ${['@cspell/cspell-json-reporter', false]} | ${new Error('Failed to load reporter @cspell/cspell-json-reporter: cspell-json-reporter settings must be an object')} ${['@cspell/cspell-unknown-reporter']} | ${oc({ message: sc("Failed to load reporter @cspell/cspell-unknown-reporter: Cannot find package '@cspell/cspell-unknown-reporter' imported from") })} ${'@cspell/cspell-unknown-reporter'} | ${oc({ message: sc("Failed to load reporter @cspell/cspell-unknown-reporter: Cannot find package '@cspell/cspell-unknown-reporter'") })} `('loadReporters fail $reporter', async ({ reporter, expected }) => { diff --git a/test-packages/cspell-service-bus/test-cspell-service-bus-esm/src/index.test.mts b/test-packages/cspell-service-bus/test-cspell-service-bus-esm/src/index.test.mts index 5e37725eab44..c8e369c03bbf 100644 --- a/test-packages/cspell-service-bus/test-cspell-service-bus-esm/src/index.test.mts +++ b/test-packages/cspell-service-bus/test-cspell-service-bus-esm/src/index.test.mts @@ -21,9 +21,9 @@ describe('Service Bus', () => { ${FibRequestFactory.create({ fib: 7 })} | ${createResponse(13)} ${StringLengthRequestFactory.create({ str: 'hello' })} | ${createResponse(5)} ${new StringToUpperRequest('hello')} | ${createResponse('HELLO')} - ${new DoNotHandleRequest()} | ${{ error: Error('Unhandled Request: Do Not Handle') }} - ${new RetryAgainRequest()} | ${{ error: Error('Service Request Depth 10 Exceeded: Retry Again Request') }} - ${new ServiceRequestCls('throw', undefined)} | ${{ error: Error('Unhandled Error in Handler: handlerThrowErrorOnRequest') }} + ${new DoNotHandleRequest()} | ${{ error: new Error('Unhandled Request: Do Not Handle') }} + ${new RetryAgainRequest()} | ${{ error: new Error('Service Request Depth 10 Exceeded: Retry Again Request') }} + ${new ServiceRequestCls('throw', undefined)} | ${{ error: new Error('Unhandled Error in Handler: handlerThrowErrorOnRequest') }} `('serviceBus handle request: $request.type', ({ request, expected }) => { expect(bus.dispatch(request)).toEqual(expected); }); diff --git a/test-packages/cspell-service-bus/test-cspell-service-bus-rollup/src/index.test.mts b/test-packages/cspell-service-bus/test-cspell-service-bus-rollup/src/index.test.mts index 5e37725eab44..c8e369c03bbf 100644 --- a/test-packages/cspell-service-bus/test-cspell-service-bus-rollup/src/index.test.mts +++ b/test-packages/cspell-service-bus/test-cspell-service-bus-rollup/src/index.test.mts @@ -21,9 +21,9 @@ describe('Service Bus', () => { ${FibRequestFactory.create({ fib: 7 })} | ${createResponse(13)} ${StringLengthRequestFactory.create({ str: 'hello' })} | ${createResponse(5)} ${new StringToUpperRequest('hello')} | ${createResponse('HELLO')} - ${new DoNotHandleRequest()} | ${{ error: Error('Unhandled Request: Do Not Handle') }} - ${new RetryAgainRequest()} | ${{ error: Error('Service Request Depth 10 Exceeded: Retry Again Request') }} - ${new ServiceRequestCls('throw', undefined)} | ${{ error: Error('Unhandled Error in Handler: handlerThrowErrorOnRequest') }} + ${new DoNotHandleRequest()} | ${{ error: new Error('Unhandled Request: Do Not Handle') }} + ${new RetryAgainRequest()} | ${{ error: new Error('Service Request Depth 10 Exceeded: Retry Again Request') }} + ${new ServiceRequestCls('throw', undefined)} | ${{ error: new Error('Unhandled Error in Handler: handlerThrowErrorOnRequest') }} `('serviceBus handle request: $request.type', ({ request, expected }) => { expect(bus.dispatch(request)).toEqual(expected); });