Skip to content

Commit

Permalink
Reduce XO exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
novemberborn committed Nov 1, 2021
1 parent 5a48893 commit 6ed3ad1
Show file tree
Hide file tree
Showing 26 changed files with 122 additions and 139 deletions.
55 changes: 13 additions & 42 deletions .xo-config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,69 +28,40 @@ module.exports = {
},
overrides: [
{
files: [
'index.d.ts',
'types/*.d.ts',
],
files: '**/*.d.ts',
rules: {
'import/extensions': 'off',
},
},
{
files: 'plugin.d.ts',
rules: {
'node/prefer-global/url': 'off',
},
},
{
files: '{test,test-{d,tap}}/**/*.ts',
files: 'examples/**',
rules: {
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/prefer-readonly-parameter-types': 'off',
'ava/no-only-test': 'off',
'unicorn/prefer-module': 'off',
},
},
{
files: '{test,test-{d,tap}}/**',
// TODO: Update tests.
files: 'test/**',
rules: {
'import/no-anonymous-default-export': 'off',
'node/prefer-global/buffer': 'off',
'node/prefer-global/process': 'off',
},
},
{
files: 'test-tap/**',
rules: {
'promise/prefer-await-to-then': 'off',
'unicorn/error-message': 'off',
'unicorn/no-array-reduce': 'off',
'unicorn/prevent-abbreviations': 'off',
},
},
{
files: 'test/macros/fixtures/macros.js',
rules: {
'ava/no-identical-title': 'off',
},
},
{
files: [
'examples/**',
'test/snapshot-*/fixtures/**',
],
// TODO: Update tests.
files: 'test/snapshot-*/fixtures/**',
rules: {
'unicorn/prefer-module': 'off',
},
},
{
files: 'examples/**',
// TODO: Update tests.
files: 'test-tap/**',
rules: {
'ava/no-only-test': 'off',
'import/no-anonymous-default-export': 'off',
'node/prefer-global/process': 'off',
'unicorn/error-message': 'off',
},
},
],
Expand Down
1 change: 1 addition & 0 deletions test-d/context.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function */
import {expectError, expectType} from 'tsd';

import anyTest, {ExecutionContext, TestFn} from '..';
Expand Down
1 change: 1 addition & 0 deletions test-d/implementation-result.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function */
import test from '..';

test('return a promise-like', t => ({
Expand Down
2 changes: 1 addition & 1 deletion test-d/macros.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable no-lone-blocks */
/* eslint-disable no-lone-blocks, @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function */
import {expectType} from 'tsd';

import test, {ExecutionContext} from '..';
Expand Down
2 changes: 1 addition & 1 deletion test-d/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import * as plugin from '../plugin'; // eslint-disable-line import/extensions

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

const factory: plugin.SharedWorker.Factory = ({negotiateProtocol}) => {
const factory: plugin.SharedWorker.Factory = ({negotiateProtocol}) => { // eslint-disable-line @typescript-eslint/no-unused-vars
expectType<plugin.SharedWorker.Experimental.Protocol>(negotiateProtocol(['experimental']));
};
1 change: 1 addition & 0 deletions test-d/throws.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-empty-function */
import {expectType} from 'tsd';

import test from '..';
Expand Down
2 changes: 1 addition & 1 deletion test-d/try-commit.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {expectType} from 'tsd';

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

test('attempt', async t => {
const attempt = await t.try(
Expand Down
4 changes: 2 additions & 2 deletions test-tap/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ async function apiCreator(options = {}) {
return instance;
}

const opts = [
const options = [
{workerThreads: true},
{workerThreads: false},
];

for (const opt of opts) {
for (const opt of options) {
test(`fail-fast mode - workerThreads: ${opt.workerThreads} - single file & serial`, async t => {
const api = await apiCreator({
...opt,
Expand Down
42 changes: 21 additions & 21 deletions test-tap/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -795,8 +795,8 @@ test('.throws()', gather(t => {

// Fails because thrown exception is not an error
failsWith(t, () => assertions.throws(() => {
const err = 'foo';
throw err;
const error = 'foo';
throw error;
}), {
assertion: 'throws',
message: '',
Expand All @@ -812,10 +812,10 @@ test('.throws()', gather(t => {

// Passes because the correct error is thrown.
passes(t, () => {
const err = new Error('foo');
const error = new Error('foo');
return assertions.throws(() => {
throw err;
}, {is: err});
throw error;
}, {is: error});
});

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

// Fails because the thrown value is not the right one
fails(t, () => {
const err = new Error('foo');
const error = new Error('foo');
return assertions.throws(() => {
throw err;
throw error;
}, {is: {}});
});

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

// Fails because the thrown value is not an error
fails(t, () => assertions.throws(() => {
const err = {name: 'Bob'};
throw err;
const error = {name: 'Bob'};
throw error;
}, {name: 'Bob'}));

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

// Passes because the correct error is thrown.
passes(t, () => assertions.throws(() => {
const err = new TypeError();
err.code = 'ERR_TEST';
throw err;
const error = new TypeError();
error.code = 'ERR_TEST';
throw error;
}, {code: 'ERR_TEST'}));

// Passes because the correct error is thrown.
passes(t, () => assertions.throws(() => {
const err = new TypeError();
err.code = 42;
throw err;
const error = new TypeError();
error.code = 42;
throw error;
}, {code: 42}));

// Fails because the thrown value is not the right one
fails(t, () => assertions.throws(() => {
const err = new TypeError();
err.code = 'ERR_NOPE';
throw err;
const error = new TypeError();
error.code = 'ERR_NOPE';
throw error;
}, {code: 'ERR_TEST'}));

fails(t, () => assertions.throws(() => {
const err = new TypeError();
err.code = 1;
throw err;
const error = new TypeError();
error.code = 1;
throw error;
}, {code: 42}));

// Regression test for https://github.com/avajs/ava/issues/1676
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unsafe-call */
import test from '../../../../../../../entrypoints/main.cjs';

test('feature test title', t => {
Expand Down
1 change: 1 addition & 0 deletions test-tap/fixture/snapshots/test-sourcemaps/src/test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unsafe-call */
import test from '../../../../../entrypoints/main.cjs';

test('top level test title', t => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unsafe-call */
import test from '../../../../../../entrypoints/main.cjs';

test('test title', t => {
Expand Down
8 changes: 4 additions & 4 deletions test-tap/helper/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ export function execCli(args, options, cb) {

child.on('close', (code, signal) => {
if (code) {
const err = new Error(`test-worker exited with a non-zero exit code: ${code}`);
err.code = code;
err.signal = signal;
resolve(err);
const error = new Error(`test-worker exited with a non-zero exit code: ${code}`);
error.code = code;
error.signal = signal;
resolve(error);
return;
}

Expand Down
5 changes: 3 additions & 2 deletions test-tap/helper/tty-stream.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {Buffer} from 'node:buffer';
import stream from 'node:stream';

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

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

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

this.chunks.push(TTYStream.SEPARATOR);
Expand Down
Loading

0 comments on commit 6ed3ad1

Please sign in to comment.