mirror of
https://github.com/pezkuwichain/pezkuwi-dev.git
synced 2026-10-24 12:35:08 +00:00
Move the toolchain to eslint 10, typescript-eslint 8 and current plugins
eslint 8 and typescript-eslint 6 are past their support, and the webpack dev server chain carried the dependency alerts every repository using this package inherited. Upstream @polkadot/dev still pins the same versions, so this leaves it on purpose. The rules are carried over with their options, so the lint means what it meant: - eslint-config-standard 17 (written for eslint 8) is replaced by its 161 rules in config/eslint.standard.js, with their options. Its 48 formatting rules, deprecated in eslint core, are the same rules in @stylistic; no-new-object and no-new-symbol are no-object-constructor and no-new-native-nonconstructor; import/* is import-x/*. - eslint-plugin-import (eslint <= 9) is eslint-plugin-import-x; eslint-plugin-deprecation is @typescript-eslint/no-deprecated; the formatting rules of core, typescript-eslint and eslint-plugin-react used in eslint.rules.js are their @stylistic versions with the same options. - typescript-eslint 8's preset swaps core no-unused-expressions for its own with default options; standard's (short circuit, ternary and tagged templates allowed) are carried over to it. - eslint-plugin-react and eslint-plugin-header still call context methods eslint 10 removed; @eslint/compat's fixupPluginRules supplies them. The header rule also gets `schema: false`, as eslint 9+ rejects options for a rule with no schema. The original header plugin stays rather than its fork: it reports at the first token after leading comments, so a generated file's /* eslint-disable */ still covers it, as it always has. The effective config was compared rule by rule (--print-config) for .ts, .tsx, .spec.ts and .mjs files before and after. Every rule that left has its successor active; option differences are eslint 10 spelling out defaults. New rules come from the eslint 10, typescript-eslint 8 and react-hooks 7 presets. no-inner-declarations left eslint's preset upstream. Also current: webpack-dev-server 6, webpack-cli 7, webpack-merge 6, rollup plugins, madge 8, gh-release 8, globals 17, espree 11; Node >= 20.19 for the dev package, which eslint 10 requires. In this repository the new rules found: Function types now named by no-unsafe-function-type; optional chains, includes() and RegExp#exec where they say the same thing; createWrapper returns Describe, so its three casts were redundant; rootCjs.spec casts through unknown, so the lint result does not depend on whether build/ exists. lint, build and test (149 passed) pass, and lint leaves the tree unchanged with and without a build.
This commit is contained in:
1 parent
e73c5c953c
commit
bda5d06bac
17 files changed
+3401
-3570
No files matched your search
Vendored
+4
-4
@@ -164,7 +164,7 @@ function assertMatchStr (value: unknown, check: string | RegExp): void {
|
||||
*
|
||||
* @see https://github.com/facebook/jest/blob/a49c88610e49a3242576160740a32a2fe11161e1/packages/expect/src/asymmetricMatchers.ts#L103-L133
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
||||
function assertInstanceOf (value: unknown, Clazz: Function): void {
|
||||
assert.ok(
|
||||
(Clazz === Array && Array.isArray(value)) ||
|
||||
@@ -188,7 +188,7 @@ function assertInstanceOf (value: unknown, Clazz: Function): void {
|
||||
* @param {string | unknown[]} value
|
||||
* @param {string} check
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
||||
function assertIncludes (value: string | unknown[], [check, Clazz]: [string, Function]): void {
|
||||
assertInstanceOf(value, Clazz);
|
||||
assert.ok(value?.includes(check), `${value as string} does not include ${check}`);
|
||||
@@ -201,7 +201,7 @@ function assertIncludes (value: string | unknown[], [check, Clazz]: [string, Fun
|
||||
**/
|
||||
export function expect () {
|
||||
const rootMatchers = {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
||||
any: (Clazz: Function) => new Matcher(assertInstanceOf, Clazz),
|
||||
anything: () => new Matcher(assertNonNullish),
|
||||
arrayContaining: (check: string) => new Matcher(assertIncludes, [check, Array]),
|
||||
@@ -229,7 +229,7 @@ export function expect () {
|
||||
toBe: (other: unknown) => assert.strictEqual(value, other),
|
||||
toBeDefined: () => assert.ok(value !== undefined),
|
||||
toBeFalsy: () => assert.ok(!value),
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
||||
toBeInstanceOf: (Clazz: Function) => assertInstanceOf(value, Clazz),
|
||||
toBeNull: (value: unknown) => assert.ok(value === null),
|
||||
toBeTruthy: () => assert.ok(value),
|
||||
|
||||
Vendored
+1
-1
@@ -32,7 +32,7 @@ function extendMock <F extends AnyFn> (mocked: WithMock<F>) {
|
||||
//
|
||||
// Effectively the casts below ensure that our WithMock<*> aligns
|
||||
// on a high-level to what we use via private type...
|
||||
const spy = (mocked as unknown as ReturnType<typeof mock['fn']>);
|
||||
const spy = mocked as unknown as ReturnType<typeof mock['fn']>;
|
||||
|
||||
return enhanceObj(enhanceObj(mocked, {
|
||||
mockImplementation: <F extends AnyFn> (fn: F): void => {
|
||||
|
||||
Vendored
+6
-6
@@ -35,10 +35,10 @@ const MINUTE = 60 * 1000;
|
||||
* Wraps either describe or it with relevant .only, .skip, .todo & .each helpers,
|
||||
* shimming it into a Jest-compatible environment.
|
||||
*
|
||||
* @param {} fn
|
||||
* Describe and It have the same shape, so one return type serves both.
|
||||
*/
|
||||
function createWrapper <T extends WrapFn> (fn: T, defaultTimeout: number): Describe | It {
|
||||
const wrap = (opts: WrapOpts) => (name: string, exec: () => void | Promise<void>, timeout?: number) => fn(name, { ...opts, timeout: (timeout || defaultTimeout) }, exec) as unknown as void;
|
||||
function createWrapper (fn: WrapFn, defaultTimeout: number): Describe {
|
||||
const wrap = (opts: WrapOpts): TestFn => (name: string, exec: () => void | Promise<void>, timeout?: number) => fn(name, { ...opts, timeout: (timeout || defaultTimeout) }, exec) as unknown as void;
|
||||
|
||||
// Ensure that we have consistent helpers on the function. These are not consistently
|
||||
// applied accross all node:test versions, latest has all, so always apply ours.
|
||||
@@ -47,7 +47,7 @@ function createWrapper <T extends WrapFn> (fn: T, defaultTimeout: number): Descr
|
||||
only: wrap({ only: true }),
|
||||
skip: wrap({ skip: true }),
|
||||
todo: wrap({ todo: true })
|
||||
}) as Describe | It;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,7 +56,7 @@ function createWrapper <T extends WrapFn> (fn: T, defaultTimeout: number): Descr
|
||||
**/
|
||||
export function suite (): { describe: Describe; it: It } {
|
||||
return {
|
||||
describe: createWrapper(describe, 60 * MINUTE) as Describe,
|
||||
it: createWrapper(it, 2 * MINUTE) as It
|
||||
describe: createWrapper(describe, 60 * MINUTE),
|
||||
it: createWrapper(it, 2 * MINUTE)
|
||||
};
|
||||
}
|
||||
Vendored
-2
@@ -1,8 +1,6 @@
|
||||
// Copyright 2017-2026 @pezkuwi/dev-test authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/* eslint-disable no-var */
|
||||
|
||||
import type { expect } from './env/expect.js';
|
||||
import type { jest } from './env/jest.js';
|
||||
import type { lifecycle } from './env/lifecycle.js';
|
||||
|
||||
@@ -6,7 +6,7 @@ export type AnyFn = (...args: any[]) => any;
|
||||
|
||||
export type BaseObj = Record<string, unknown>;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
||||
export type BaseFn = Function;
|
||||
|
||||
export type StubFn = (...args: unknown[]) => unknown;
|
||||
@@ -25,4 +25,4 @@ export type WithMock<F extends AnyFn> = F & {
|
||||
resetCalls: () => void;
|
||||
restore: () => void;
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -27,7 +27,7 @@ function createStub <N extends readonly string[]> (keys: N, creator: (key: strin
|
||||
obj[key] ??= creator(key);
|
||||
|
||||
return obj;
|
||||
}, {}) as unknown as { [K in N[number]]: StubFn };
|
||||
}, {}) as unknown as Record<N[number], StubFn>;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user