Skip to content

Commit

Permalink
ci: Fix Lint -- Workflow Bot (#5642)
Browse files Browse the repository at this point in the history
Co-authored-by: Jason3S <3740137+Jason3S@users.noreply.github.com>
  • Loading branch information
1 parent 27b8b9a commit 81baa44
Show file tree
Hide file tree
Showing 18 changed files with 45 additions and 45 deletions.
4 changes: 2 additions & 2 deletions packages/cspell-eslint-plugin/src/worker/spellCheck.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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));
});
});

Expand Down
6 changes: 3 additions & 3 deletions packages/cspell-io/src/VirtualFs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down
8 changes: 4 additions & 4 deletions packages/cspell-io/src/errors/error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/cspell-io/src/errors/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
4 changes: 2 additions & 2 deletions packages/cspell-io/src/node/file/FetchError.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/cspell-io/src/node/file/FetchError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
Original file line number Diff line number Diff line change
Expand Up @@ -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}"`));
});
});

Expand Down
8 changes: 4 additions & 4 deletions packages/cspell-lib/src/lib/util/errors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/cspell-service-bus/src/SystemServiceBus.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
14 changes: 7 additions & 7 deletions packages/cspell-service-bus/src/assert.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/cspell-service-bus/src/assert.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
6 changes: 3 additions & 3 deletions packages/cspell-service-bus/src/bus.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
4 changes: 2 additions & 2 deletions packages/cspell-tools/src/shasum/shasum.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.'),
);
});

Expand Down
4 changes: 2 additions & 2 deletions packages/cspell-tools/src/shasum/shasum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ export async function checkShasumFile(

async function tryToCheckFile(filename: string, root: string, checksum: string | undefined): Promise<CheckFileResult> {
if (!checksum) {
return { filename, passed: false, error: Error('Missing Checksum.') };
return { filename, passed: false, error: new Error('Missing Checksum.') };
}

const file = resolve(root, filename);
try {
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.') };
}
}

Expand Down
8 changes: 4 additions & 4 deletions packages/cspell-tools/src/util/errors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/cspell/src/app/util/reporters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down

0 comments on commit 81baa44

Please sign in to comment.