Skip to content

Commit

Permalink
Upgrade xo to v0.57.0
Browse files Browse the repository at this point in the history
* Upgrade xo to v0.57.0 and lint sources, tests, and examples

Disabled `unicorn/prevent-abbreviations` because it introduces too many
opinionated changes.

* Update reporter logs which are sensitive to line numbers changing

---------

Co-authored-by: Mark Wubben <[email protected]>
  • Loading branch information
1 parent 2e0c2b1 commit 1d62caf
Show file tree
Hide file tree
Showing 20 changed files with 439 additions and 473 deletions.
1 change: 1 addition & 0 deletions .xo-config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module.exports = {
'import/newline-after-import': 'error',
'unicorn/require-post-message-target-origin': 'off',
'unicorn/prefer-event-target': 'off',
'unicorn/prevent-abbreviations': 'off',
},
overrides: [
{
Expand Down
2 changes: 1 addition & 1 deletion examples/macros/test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const test = require('ava');

const {sum} = require('.');
const {sum} = require('./index.js');

function macro(t, a, b, expected) {
t.is(sum(a, b), expected);
Expand Down
2 changes: 1 addition & 1 deletion examples/timeouts/test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
const test = require('ava');

const {fetchUsers, fetchPosts, createPost} = require('.');
const {fetchUsers, fetchPosts, createPost} = require('./index.js');

test('retrieve users', async t => {
t.timeout(100);
Expand Down
4 changes: 3 additions & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,9 @@ export default async function loadCli() { // eslint-disable-line complexity

let globs;
try {
globs = normalizeGlobs({files: conf.files, ignoredByWatcher: conf.watchMode?.ignoreChanges, extensions, providers});
globs = normalizeGlobs({
files: conf.files, ignoredByWatcher: conf.watchMode?.ignoreChanges, extensions, providers,
});
} catch (error) {
exit(error.message);
}
Expand Down
8 changes: 4 additions & 4 deletions lib/create-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ function startChain(name, call, defaults) {
}

function extendChain(previous, name, flag) {
if (!flag) {
flag = name;
}
flag ||= name;

const fn = (...args) => {
callWithFlag(previous, flag, args);
Expand Down Expand Up @@ -89,7 +87,9 @@ export default function createChain(fn, defaults, meta) {
// "todo" tests cannot be chained. Allow todo tests to be flagged as needing
// to be serial.
root.todo = startChain('test.todo', fn, {...defaults, type: 'test', todo: true});
root.serial.todo = startChain('test.serial.todo', fn, {...defaults, serial: true, type: 'test', todo: true});
root.serial.todo = startChain('test.serial.todo', fn, {
...defaults, serial: true, type: 'test', todo: true,
});

root.macro = options => {
if (typeof options === 'function') {
Expand Down
4 changes: 3 additions & 1 deletion lib/eslint-plugin-helper-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ const resolveGlobs = async (projectDir, overrideExtensions, overrideFiles) => {
}

const {conf, providers} = await configCache.get(projectDir);
return buildGlobs({conf, providers, projectDir, overrideExtensions, overrideFiles});
return buildGlobs({
conf, providers, projectDir, overrideExtensions, overrideFiles,
});
};

const data = new Uint8Array(workerData.dataBuffer);
Expand Down
6 changes: 4 additions & 2 deletions lib/load-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const loadConfigFile = async ({projectDir, configFile}) => {

function resolveConfigFile(configFile) {
if (configFile) {
configFile = path.resolve(configFile); // Relative to CWD
return path.resolve(configFile); // Relative to CWD
}

return configFile;
Expand Down Expand Up @@ -153,7 +153,9 @@ export async function loadConfig({configFile, resolveFrom = process.cwd(), defau
}
}

const config = {...defaults, nonSemVerExperiments: {}, ...fileConf, ...packageConf, projectDir, configFile};
const config = {
...defaults, nonSemVerExperiments: {}, ...fileConf, ...packageConf, projectDir, configFile,
};

const {nonSemVerExperiments: experiments} = config;
if (!isPlainObject(experiments)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/plugin-support/shared-worker-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ try {
},
});
} catch (error) {
fatal = fatal ?? error;
fatal ??= error;
} finally {
if (fatal !== undefined) {
process.nextTick(() => {
Expand Down
20 changes: 8 additions & 12 deletions lib/snapshot-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,9 @@ export function extractCompressedSnapshot(buffer, snapPath) {
const compressedOffset = sha256sumOffset + SHA_256_HASH_LENGTH;
const compressed = buffer.slice(compressedOffset);

return {version, compressed, sha256sumOffset, compressedOffset};
return {
version, compressed, sha256sumOffset, compressedOffset,
};
}

function decodeSnapshots(buffer, snapPath) {
Expand Down Expand Up @@ -290,11 +292,7 @@ class Manager {
}

recordSerialized({data, label, belongsTo, index}) {
let block = this.newBlocksByTitle.get(belongsTo);
if (!block) {
block = {snapshots: []};
}

const block = this.newBlocksByTitle.get(belongsTo) ?? {snapshots: []};
const {snapshots} = block;

if (index > snapshots.length) {
Expand All @@ -319,7 +317,9 @@ class Manager {

return () => { // Must be called in order!
this.hasChanges = true;
this.recordSerialized({data, label, belongsTo, index});
this.recordSerialized({
data, label, belongsTo, index,
});
};
}

Expand All @@ -338,11 +338,7 @@ class Manager {

skipSnapshot({belongsTo, index, deferRecording}) {
const oldBlock = this.oldBlocksByTitle.get(belongsTo);
let snapshot = oldBlock?.snapshots[index];

if (!snapshot) {
snapshot = {};
}
const snapshot = oldBlock?.snapshots[index] ?? {};

// Retain the label from the old snapshot, so as not to assume that the
// snapshot.skip() arguments are well-formed.
Expand Down
8 changes: 6 additions & 2 deletions lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import concordance from 'concordance';
import isPromise from 'is-promise';
import plur from 'plur';

import {AssertionError, Assertions, checkAssertionMessage, getAssertionStack} from './assert.js';
import {
AssertionError, Assertions, checkAssertionMessage, getAssertionStack,
} from './assert.js';
import concordanceOptions from './concordance-options.js';
import nowAndTimers from './now-and-timers.cjs';
import parseTestArgs from './parse-test-args.js';
Expand Down Expand Up @@ -277,7 +279,9 @@ export default class Test {

const {deferredSnapshotRecordings, error, logs, passed, assertCount, snapshotCount} = await attempt.run();
const errors = error ? [error] : [];
return {assertCount, deferredSnapshotRecordings, errors, logs, passed, snapshotCount, startingSnapshotCount};
return {
assertCount, deferredSnapshotRecordings, errors, logs, passed, snapshotCount, startingSnapshotCount,
};
};

this.assertCount = 0;
Expand Down
12 changes: 9 additions & 3 deletions lib/watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import {nodeFileTrace} from '@vercel/nft';
import createDebug from 'debug';

import {chalk} from './chalk.js';
import {applyTestFileFilter, classify, buildIgnoreMatcher, findTests} from './globs.js';
import {
applyTestFileFilter, classify, buildIgnoreMatcher, findTests,
} from './globs.js';
import {levels as providerLevels} from './provider-manager.js';

const debug = createDebug('ava:watcher');
Expand All @@ -34,7 +36,9 @@ export function available(projectDir) {

export async function start({api, filter, globs, projectDir, providers, reporter, stdin, signal}) {
providers = providers.filter(({level}) => level >= providerLevels.ava6);
for await (const {files, ...runtimeOptions} of plan({api, filter, globs, projectDir, providers, stdin, abortSignal: signal})) {
for await (const {files, ...runtimeOptions} of plan({
api, filter, globs, projectDir, providers, stdin, abortSignal: signal,
})) {
await api.run({files, filter, runtimeOptions});
reporter.endRun();
reporter.lineWriter.writeLine(END_MESSAGE);
Expand Down Expand Up @@ -62,7 +66,9 @@ async function * plan({api, filter, globs, projectDir, providers, stdin, abortSi
const changeFromPath = path => {
const {isTest} = classify(path, cwdAndGlobs);
const stats = fileStats(path);
return {path, isTest, exists: stats !== undefined, isFile: stats?.isFile() ?? false};
return {
path, isTest, exists: stats !== undefined, isFile: stats?.isFile() ?? false,
};
};

// Begin a file trace in the background.
Expand Down
Loading

0 comments on commit 1d62caf

Please sign in to comment.