Skip to content

Commit 6ed3ad1

Browse files
committed
Reduce XO exceptions
1 parent 5a48893 commit 6ed3ad1

File tree

26 files changed

+122
-139
lines changed

26 files changed

+122
-139
lines changed

.xo-config.cjs

Lines changed: 13 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -28,69 +28,40 @@ module.exports = {
2828
},
2929
overrides: [
3030
{
31-
files: [
32-
'index.d.ts',
33-
'types/*.d.ts',
34-
],
31+
files: '**/*.d.ts',
3532
rules: {
3633
'import/extensions': 'off',
3734
},
3835
},
3936
{
40-
files: 'plugin.d.ts',
41-
rules: {
42-
'node/prefer-global/url': 'off',
43-
},
44-
},
45-
{
46-
files: '{test,test-{d,tap}}/**/*.ts',
37+
files: 'examples/**',
4738
rules: {
48-
'@typescript-eslint/explicit-function-return-type': 'off',
49-
'@typescript-eslint/no-empty-function': 'off',
50-
'@typescript-eslint/no-unsafe-assignment': 'off',
51-
'@typescript-eslint/no-unsafe-call': 'off',
52-
'@typescript-eslint/no-unsafe-member-access': 'off',
53-
'@typescript-eslint/no-unsafe-return': 'off',
54-
'@typescript-eslint/no-unused-vars': 'off',
55-
'@typescript-eslint/prefer-readonly-parameter-types': 'off',
39+
'ava/no-only-test': 'off',
40+
'unicorn/prefer-module': 'off',
5641
},
5742
},
5843
{
59-
files: '{test,test-{d,tap}}/**',
44+
// TODO: Update tests.
45+
files: 'test/**',
6046
rules: {
6147
'import/no-anonymous-default-export': 'off',
62-
'node/prefer-global/buffer': 'off',
6348
'node/prefer-global/process': 'off',
6449
},
6550
},
6651
{
67-
files: 'test-tap/**',
68-
rules: {
69-
'promise/prefer-await-to-then': 'off',
70-
'unicorn/error-message': 'off',
71-
'unicorn/no-array-reduce': 'off',
72-
'unicorn/prevent-abbreviations': 'off',
73-
},
74-
},
75-
{
76-
files: 'test/macros/fixtures/macros.js',
77-
rules: {
78-
'ava/no-identical-title': 'off',
79-
},
80-
},
81-
{
82-
files: [
83-
'examples/**',
84-
'test/snapshot-*/fixtures/**',
85-
],
52+
// TODO: Update tests.
53+
files: 'test/snapshot-*/fixtures/**',
8654
rules: {
8755
'unicorn/prefer-module': 'off',
8856
},
8957
},
9058
{
91-
files: 'examples/**',
59+
// TODO: Update tests.
60+
files: 'test-tap/**',
9261
rules: {
93-
'ava/no-only-test': 'off',
62+
'import/no-anonymous-default-export': 'off',
63+
'node/prefer-global/process': 'off',
64+
'unicorn/error-message': 'off',
9465
},
9566
},
9667
],

test-d/context.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function */
12
import {expectError, expectType} from 'tsd';
23

34
import anyTest, {ExecutionContext, TestFn} from '..';

test-d/implementation-result.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function */
12
import test from '..';
23

34
test('return a promise-like', t => ({

test-d/macros.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* eslint-disable no-lone-blocks */
1+
/* eslint-disable no-lone-blocks, @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function */
22
import {expectType} from 'tsd';
33

44
import test, {ExecutionContext} from '..';

test-d/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ import * as plugin from '../plugin'; // eslint-disable-line import/extensions
44

55
expectType<plugin.SharedWorker.Plugin.Experimental.Protocol>(plugin.registerSharedWorker({filename: '', supportedProtocols: ['experimental']}));
66

7-
const factory: plugin.SharedWorker.Factory = ({negotiateProtocol}) => {
7+
const factory: plugin.SharedWorker.Factory = ({negotiateProtocol}) => { // eslint-disable-line @typescript-eslint/no-unused-vars
88
expectType<plugin.SharedWorker.Experimental.Protocol>(negotiateProtocol(['experimental']));
99
};

test-d/throws.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-empty-function */
12
import {expectType} from 'tsd';
23

34
import test from '..';

test-d/try-commit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {expectType} from 'tsd';
22

3-
import test, {ExecutionContext, Macro} from '..';
3+
import test, {ExecutionContext} from '..';
44

55
test('attempt', async t => {
66
const attempt = await t.try(

test-tap/api.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ async function apiCreator(options = {}) {
2323
return instance;
2424
}
2525

26-
const opts = [
26+
const options = [
2727
{workerThreads: true},
2828
{workerThreads: false},
2929
];
3030

31-
for (const opt of opts) {
31+
for (const opt of options) {
3232
test(`fail-fast mode - workerThreads: ${opt.workerThreads} - single file & serial`, async t => {
3333
const api = await apiCreator({
3434
...opt,

test-tap/assert.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -795,8 +795,8 @@ test('.throws()', gather(t => {
795795

796796
// Fails because thrown exception is not an error
797797
failsWith(t, () => assertions.throws(() => {
798-
const err = 'foo';
799-
throw err;
798+
const error = 'foo';
799+
throw error;
800800
}), {
801801
assertion: 'throws',
802802
message: '',
@@ -812,10 +812,10 @@ test('.throws()', gather(t => {
812812

813813
// Passes because the correct error is thrown.
814814
passes(t, () => {
815-
const err = new Error('foo');
815+
const error = new Error('foo');
816816
return assertions.throws(() => {
817-
throw err;
818-
}, {is: err});
817+
throw error;
818+
}, {is: error});
819819
});
820820

821821
// Fails because the thrown value is not an error
@@ -828,9 +828,9 @@ test('.throws()', gather(t => {
828828

829829
// Fails because the thrown value is not the right one
830830
fails(t, () => {
831-
const err = new Error('foo');
831+
const error = new Error('foo');
832832
return assertions.throws(() => {
833-
throw err;
833+
throw error;
834834
}, {is: {}});
835835
});
836836

@@ -841,8 +841,8 @@ test('.throws()', gather(t => {
841841

842842
// Fails because the thrown value is not an error
843843
fails(t, () => assertions.throws(() => {
844-
const err = {name: 'Bob'};
845-
throw err;
844+
const error = {name: 'Bob'};
845+
throw error;
846846
}, {name: 'Bob'}));
847847

848848
// Fails because the thrown value is not the right one
@@ -852,29 +852,29 @@ test('.throws()', gather(t => {
852852

853853
// Passes because the correct error is thrown.
854854
passes(t, () => assertions.throws(() => {
855-
const err = new TypeError();
856-
err.code = 'ERR_TEST';
857-
throw err;
855+
const error = new TypeError();
856+
error.code = 'ERR_TEST';
857+
throw error;
858858
}, {code: 'ERR_TEST'}));
859859

860860
// Passes because the correct error is thrown.
861861
passes(t, () => assertions.throws(() => {
862-
const err = new TypeError();
863-
err.code = 42;
864-
throw err;
862+
const error = new TypeError();
863+
error.code = 42;
864+
throw error;
865865
}, {code: 42}));
866866

867867
// Fails because the thrown value is not the right one
868868
fails(t, () => assertions.throws(() => {
869-
const err = new TypeError();
870-
err.code = 'ERR_NOPE';
871-
throw err;
869+
const error = new TypeError();
870+
error.code = 'ERR_NOPE';
871+
throw error;
872872
}, {code: 'ERR_TEST'}));
873873

874874
fails(t, () => assertions.throws(() => {
875-
const err = new TypeError();
876-
err.code = 1;
877-
throw err;
875+
const error = new TypeError();
876+
error.code = 1;
877+
throw error;
878878
}, {code: 42}));
879879

880880
// Regression test for https://github.com/avajs/ava/issues/1676

test-tap/fixture/snapshots/test-sourcemaps/src/feature/__tests__/test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-unsafe-call */
12
import test from '../../../../../../../entrypoints/main.cjs';
23

34
test('feature test title', t => {

test-tap/fixture/snapshots/test-sourcemaps/src/test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-unsafe-call */
12
import test from '../../../../../entrypoints/main.cjs';
23

34
test('top level test title', t => {

test-tap/fixture/snapshots/test-sourcemaps/src/test/test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-unsafe-call */
12
import test from '../../../../../../entrypoints/main.cjs';
23

34
test('test title', t => {

test-tap/helper/cli.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ export function execCli(args, options, cb) {
3838

3939
child.on('close', (code, signal) => {
4040
if (code) {
41-
const err = new Error(`test-worker exited with a non-zero exit code: ${code}`);
42-
err.code = code;
43-
err.signal = signal;
44-
resolve(err);
41+
const error = new Error(`test-worker exited with a non-zero exit code: ${code}`);
42+
error.code = code;
43+
error.signal = signal;
44+
resolve(error);
4545
return;
4646
}
4747

test-tap/helper/tty-stream.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {Buffer} from 'node:buffer';
12
import stream from 'node:stream';
23

34
import ansiEscapes from 'ansi-escapes';
@@ -20,7 +21,7 @@ export default class TTYStream extends stream.Writable {
2021
this.spinnerActivity = [];
2122
}
2223

23-
const string = this.sanitizers.reduce((string_, sanitizer) => sanitizer(string_), chunk.toString('utf8'));
24+
const string = this.sanitizers.reduce((string_, sanitizer) => sanitizer(string_), chunk.toString('utf8')); // eslint-disable-line unicorn/no-array-reduce
2425
// Ignore the chunk if it was scrubbed completely. Still count 0-length
2526
// chunks.
2627
if (string !== '' || chunk.length === 0) {
@@ -40,7 +41,7 @@ export default class TTYStream extends stream.Writable {
4041
}
4142

4243
for (const object of chunks) {
43-
this.chunks.push(Buffer.from(this.sanitizers.reduce((string, sanitizer) => sanitizer(string), object.chunk.toString('utf8')), 'utf8'));
44+
this.chunks.push(Buffer.from(this.sanitizers.reduce((string, sanitizer) => sanitizer(string), object.chunk.toString('utf8')), 'utf8')); // eslint-disable-line unicorn/no-array-reduce
4445
}
4546

4647
this.chunks.push(TTYStream.SEPARATOR);

0 commit comments

Comments
 (0)