Skip to content

Commit 617827b

Browse files
committed
chore: make eslint happy
1 parent c16628e commit 617827b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+250
-237
lines changed

create.ts

+20-20
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { PathScurry } from 'path-scurry';
77
import colors from 'picocolors';
88
import { dequal } from 'dequal';
99
import { fileExists, compareAndWriteFile } from '@nolyfill/internal';
10-
import type { Options as SwcOptions } from '@swc/core';
1110

1211
import type { PackageJson } from '@package-json/types';
1312

@@ -180,7 +179,7 @@ const nonNolyfillPackagesList = [
180179
};
181180

182181
const cliAllPackagesTs = `/* Generated by create.ts */
183-
/* eslint-disable */
182+
/* eslint-disable -- codegen */
184183
export const allPackages = ${JSON.stringify(allPackagesList, null, 2)};\n`;
185184

186185
await Promise.all([
@@ -219,23 +218,23 @@ const defaultExportInterop = `
219218
((typeof exports.default === 'object' && exports.default !== null) || typeof exports.default === 'function') && (Object.assign(exports.default,exports), module.exports = exports.default);
220219
`;
221220

222-
const sharedSwcOption: SwcOptions = {
223-
isModule: true,
224-
jsc: {
225-
parser: {
226-
syntax: 'typescript'
227-
},
228-
target: 'es2018',
229-
minify: {
230-
compress: true,
231-
mangle: true,
232-
module: true,
233-
sourceMap: false
234-
}
235-
},
236-
minify: true,
237-
module: { type: 'commonjs' }
238-
};
221+
// const sharedSwcOption: SwcOptions = {
222+
// isModule: true,
223+
// jsc: {
224+
// parser: {
225+
// syntax: 'typescript'
226+
// },
227+
// target: 'es2018',
228+
// minify: {
229+
// compress: true,
230+
// mangle: true,
231+
// module: true,
232+
// sourceMap: false
233+
// }
234+
// },
235+
// minify: true,
236+
// module: { type: 'commonjs' }
237+
// };
239238

240239
const sharedEsmLikeFiles = {
241240
'implementation.js': '\'use strict\';\nmodule.exports = require(\'./entry.js\').implementation;\n',
@@ -403,7 +402,8 @@ async function writePackage(pkg: VirtualPackage) {
403402
const existingPackageJson = (
404403
existingFileFullpaths.has(packageJsonPath)
405404
|| await fileExists(packageJsonPath)
406-
) ? JSON.parse(await fsPromises.readFile(packageJsonPath, 'utf8'))
405+
)
406+
? JSON.parse(await fsPromises.readFile(packageJsonPath, 'utf8'))
407407
: {};
408408

409409
// exclude version from comparison

eslint.config.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ module.exports = require('eslint-config-sukka').sukka({
99
'packages/es-iterator-helpers/**/*.js',
1010
'packages/tools/cli/bin/nolyfill.js',
1111
'packages/generated/**/*.js',
12-
'packages/generated/*/package.json'
12+
'packages/generated/**/*.d.ts',
13+
'packages/generated/*/package.json',
14+
'packages/tools/cli/src/all-packages.ts',
15+
'packages/manual/is-core-module/index.js'
1316
]
1417
}, {
1518
rules: {
@@ -19,8 +22,10 @@ module.exports = require('eslint-config-sukka').sukka({
1922
}, {
2023
files: ['packages/data/**/*'],
2124
rules: {
25+
'@typescript-eslint/no-use-before-define': 'off',
2226
'@typescript-eslint/unbound-method': 'off',
2327
'sukka/unicorn/new-for-builtins': 'off',
24-
'sukka/unicorn/no-useless-undefined': 'off' // polyfill match real behavior
28+
'sukka/unicorn/no-useless-undefined': 'off', // polyfill match real behavior
29+
'@typescript-eslint/no-unsafe-function-type': 'off' // we are doing low level stuff
2530
}
2631
});
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
import { defineEsShim } from '@nolyfill/shared';
2+
23
export default defineEsShim(globalThis, true, () => globalThis);

packages/data/es-shim-like/src/promise.allsettled.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import { defineEsShim } from '@nolyfill/shared';
22

3-
const implementation = Promise.allSettled || function allSettled<T>(this: typeof Promise, iterable: Iterable<T | PromiseLike<T>>): Promise<Array<PromiseSettledResult<Awaited<T>>>> {
3+
const implementation = Promise.allSettled || function allSettled<T>(this: typeof Promise, iterable: Iterable<T | PromiseLike<T>>): Promise<Array<PromiseSettledResult<Awaited<T>> | PromiseRejectedResult>> {
44
const $reject = Promise.reject.bind(this);
55
const $resolve = Promise.resolve.bind(this);
66
const $all = Promise.all.bind(this);
77
return $all(Array.from(iterable).map((item) => {
88
const p: Promise<Awaited<T>> = $resolve(item);
9+
// eslint-disable-next-line sukka/no-try-promise -- this is only catch when something goes horibbly wrong
910
try {
1011
return p.then(
11-
(value): PromiseFulfilledResult<Awaited<T>> => ({ status: 'fulfilled', value }),
12-
(reason): PromiseRejectedResult => ({ status: 'rejected', reason })
12+
(value): PromiseFulfilledResult<Awaited<T>> => ({ status: 'fulfilled', value })
13+
).catch(
14+
(error): PromiseRejectedResult => ({ status: 'rejected', reason: error })
1315
);
1416
} catch (e) {
1517
return $reject(e);

packages/data/es-shim-like/src/promise.any.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ const implementation = Promise.any || function any<T>(this: typeof Promise, iter
1010
try {
1111
return $all(
1212
Array.from(iterable)
13-
.map((item) => $resolve(item).then(x => $reject(x), x => x))
14-
).then(
13+
.map((item) => $resolve(item).catch(error => error).then(x => $reject(x)))
14+
).catch(error => error).then(
1515
(errors) => {
1616
throw new AggregateError(errors, 'Every promise rejected');
17-
},
18-
x => x
17+
}
1918
);
2019
} catch (e) {
2120
return $reject(e);

packages/data/es-shim-like/src/util.promisify.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
'use strict';
22

3-
import type { CustomPromisify } from 'util';
3+
import type { CustomPromisify } from 'node:util';
44

55
import { defineEsShim } from '@nolyfill/shared';
66
import safeConcat from '@nolyfill/safe-array-concat';
77

88
const kCustomPromisifiedSymbol = Symbol.for('nodejs.util.promisify.custom');
99
const kCustomPromisifyArgsSymbol = Symbol('customPromisifyArgs');
1010

11-
// eslint-disable-next-line @typescript-eslint/ban-types -- overload signature
1211
function promisify<TCustom extends Function>(fn: CustomPromisify<TCustom>): TCustom;
1312

1413
function promisify<TResult>(
@@ -49,7 +48,6 @@ function promisify<T1, T2, T3, T4, T5>(
4948
fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (err?: any) => void) => void,
5049
): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise<void>;
5150

52-
// eslint-disable-next-line @typescript-eslint/ban-types -- overload signature
5351
function promisify(orig: Function): Function {
5452
if (typeof orig !== 'function') {
5553
const error = new TypeError('The "original" argument must be of type function') as NodeJS.ErrnoException;
@@ -63,7 +61,7 @@ function promisify(orig: Function): Function {
6361
if (kCustomPromisifiedSymbol in orig && orig[kCustomPromisifiedSymbol]) {
6462
const customFunction = orig[kCustomPromisifiedSymbol];
6563
if (typeof customFunction !== 'function') {
66-
const customError = TypeError('The [util.promisify.custom] property must be of type function.') as NodeJS.ErrnoException;
64+
const customError = new TypeError('The [util.promisify.custom] property must be of type function.') as NodeJS.ErrnoException;
6765
customError.code = 'ERR_INVALID_ARG_TYPE';
6866
customError.toString = function value() {
6967
return `${this.name}[${this.code}]: ${this.message}`;
@@ -90,7 +88,7 @@ function promisify(orig: Function): Function {
9088
orig.apply(self, safeConcat(args, (err: any) => {
9189
const values = args.length > 1 ? args.slice(1) : [];
9290
if (err) {
93-
reject(err);
91+
reject(err as Error);
9492
} else if (argumentNames && typeof argumentNames !== 'undefined' && values.length > 1) {
9593
const obj: Record<string, unknown> = {};
9694
Array.prototype.forEach.call(argumentNames, (name: string, index: number) => {

packages/data/single-file/src/abab.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export {
2-
atob,
3-
btoa
4-
}
2+
atob,
3+
btoa
4+
};

packages/data/single-file/src/array-buffer-byte-length.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { uncurryThis } from '@nolyfill/shared';
22
import isArrayBuffer from '@nolyfill/is-array-buffer';
33

44
const bL = uncurryThis<(this: ArrayBuffer) => number>(
5-
Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'byteLength')!.get!,
5+
Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'byteLength')!.get!
66
);
7-
const byteLength = (ab: unknown) => {
7+
function byteLength(ab: unknown) {
88
if (!isArrayBuffer(ab)) return Number.NaN;
99
return bL(ab);
10-
};
10+
}
1111

1212
export default byteLength;

packages/data/single-file/src/define-properties.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const defineProperty = (object: any, name: string | number | symbol, value: any, predicate: (() => boolean) | true | undefined) => {
1+
function defineProperty(object: any, name: string | number | symbol, value: any, predicate: (() => boolean) | true | undefined) {
22
if (name in object) {
33
if (predicate === true) {
44
if (object[name] === value) {
@@ -17,18 +17,16 @@ const defineProperty = (object: any, name: string | number | symbol, value: any,
1717
value,
1818
writable: true
1919
});
20-
};
20+
}
2121

22-
const defineProperties = <M extends object>(
23-
object: object,
22+
function defineProperties<M extends object>(object: object,
2423
map: M & ThisType<any>,
25-
predicates?: Partial<Record<keyof M, () => boolean>>
26-
) => {
24+
predicates?: Partial<Record<keyof M, () => boolean>>) {
2725
const props: Array<keyof M> = Array.prototype.concat.call(Object.keys(map), Object.getOwnPropertySymbols(map));
2826
for (let i = 0, l = props.length; i < l; i++) {
2927
const k = props[i];
3028
defineProperty(object, k, map[k], predicates?.[k]);
3129
}
32-
};
30+
}
3331

3432
export default defineProperties;

packages/data/single-file/src/es-set-tostringtag.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ interface SetToStringTagOption {
22
force?: boolean
33
}
44

5-
const set = (object: any, value: any, options: SetToStringTagOption = {}) => {
5+
function set(object: any, value: any, options: SetToStringTagOption = {}) {
66
if (options.force || !Object.hasOwn(object, Symbol.toStringTag)) {
77
Object.defineProperty(object, Symbol.toStringTag, {
88
configurable: true,
@@ -11,6 +11,6 @@ const set = (object: any, value: any, options: SetToStringTagOption = {}) => {
1111
writable: false
1212
});
1313
}
14-
};
14+
}
1515

1616
export default set;
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
import { uncurryThis } from '@nolyfill/shared';
2-
export default uncurryThis<(this: Symbol) => string | undefined>(Object.getOwnPropertyDescriptor(Symbol.prototype, 'description')!.get!);
2+
3+
export default uncurryThis<(this: symbol) => string | undefined>(Object.getOwnPropertyDescriptor(Symbol.prototype, 'description')!.get!);
+10-10
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
const channel = new WeakMap();
2-
const check = (O: WeakKey, slot: string) => {
2+
function check(O: WeakKey, slot: string) {
33
if (!O || (typeof O !== 'object' && typeof O !== 'function')) {
44
throw new TypeError('`O` is not an object');
55
}
66
if (typeof slot !== 'string') {
77
throw new TypeError('`slot` must be a string');
88
}
9-
};
10-
const has = (O: WeakKey, slot: string) => {
9+
}
10+
function has(O: WeakKey, slot: string) {
1111
check(O, slot);
1212
const slots = channel.get(O);
1313
return !!slots && Object.hasOwn(slots, `$${slot}`);
14-
};
15-
const get = (O: WeakKey, slot: string) => {
14+
}
15+
function get(O: WeakKey, slot: string) {
1616
check(O, slot);
1717
const slots = channel.get(O);
1818
return slots?.[`$${slot}`];
19-
};
20-
const set = (O: WeakKey, slot: string, V: any) => {
19+
}
20+
function set(O: WeakKey, slot: string, V: any) {
2121
check(O, slot);
2222
let slots = channel.get(O);
2323
if (!slots) {
2424
slots = {};
2525
channel.set(O, slots);
2626
}
2727
slots[`$${slot}`] = V;
28-
};
29-
const assert = (O: WeakKey, slot: string) => {
28+
}
29+
function assert(O: WeakKey, slot: string) {
3030
check(O, slot);
3131
if (!channel.has(O)) {
3232
throw new TypeError('Side channel does not contain the given key');
3333
}
3434
if (!has(O, slot)) {
3535
throw new TypeError(`"${slot}" is not present on "O"`);
3636
}
37-
};
37+
}
3838
module.exports = Object.freeze({ has, get, set, assert });
+18-15
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1-
const isStandardArguments = (value: unknown): value is IArguments => ((value && typeof value === 'object' && Symbol.toStringTag in value)
2-
? false
3-
: Object.prototype.toString.call(value) === '[object Arguments]');
1+
function isStandardArguments(value: unknown): value is IArguments {
2+
return (value && typeof value === 'object' && Symbol.toStringTag in value)
3+
? false
4+
: Object.prototype.toString.call(value) === '[object Arguments]';
5+
}
46

5-
const isLegacyArguments = (value: unknown) => (isStandardArguments(value)
6-
? true
7-
: (
8-
value !== null
9-
&& typeof value === 'object'
10-
&& 'length' in value
11-
&& typeof value.length === 'number'
12-
&& value.length >= 0
13-
&& Object.prototype.toString.call(value) !== '[object Array]'
14-
&& 'callee' in value
15-
&& Object.prototype.toString.call(value.callee) === '[object Function]')
16-
);
7+
function isLegacyArguments(value: unknown) {
8+
return isStandardArguments(value)
9+
? true
10+
: (
11+
value !== null
12+
&& typeof value === 'object'
13+
&& 'length' in value
14+
&& typeof value.length === 'number'
15+
&& value.length >= 0
16+
&& Object.prototype.toString.call(value) !== '[object Array]'
17+
&& 'callee' in value
18+
&& Object.prototype.toString.call(value.callee) === '[object Function]');
19+
}
1720
// isStandardArguments.isLegacyArguments = isLegacyArguments; // for tests
1821
// eslint-disable-next-line prefer-rest-params -- detect arguments object
1922
export default (function () { return isStandardArguments(arguments); }()) ? isStandardArguments : isLegacyArguments;
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { uncurryThis } from '@nolyfill/shared';
22

33
const bL = uncurryThis(Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'byteLength')!.get!);
4-
const is = (obj: unknown): obj is ArrayBuffer => {
4+
function is(obj: unknown): obj is ArrayBuffer {
55
if (!obj || typeof obj !== 'object') {
66
return false;
77
}
@@ -11,6 +11,6 @@ const is = (obj: unknown): obj is ArrayBuffer => {
1111
} catch {
1212
return false;
1313
}
14-
};
14+
}
1515

1616
export default is;
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
const is = (value: unknown): value is Date => {
1+
function is(value: unknown): value is Date {
22
if (typeof value !== 'object' || value === null) return false;
33
try {
44
Date.prototype.getDay.call(value);
55
return true;
66
} catch {
77
return false;
88
}
9-
};
9+
}
1010

1111
export default is;

packages/data/single-file/src/is-generator-function.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const isFnRegex = /^\s*(?:function)?\*/;
22
// Node.js has full native support for generators since Node.js 6.4.0, so we don't need eval
33
const GeneratorFunction = Object.getPrototypeOf(function *() { /** noop */ });
4-
// eslint-disable-next-line @typescript-eslint/ban-types -- any function
54
function isGeneratorFunction(fn: unknown): fn is Function {
65
if (typeof fn !== 'function') return false;
76
if (isFnRegex.test(Function.prototype.toString.call(fn))) return true;
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const is = (value: unknown): value is RegExp => {
1+
function is(value: unknown): value is RegExp {
22
if (!value || (typeof value !== 'object' && typeof value !== 'function')) return false;
33
return Object.prototype.toString.call(value) === '[object RegExp]';
4-
};
4+
}
55

66
export default is;

0 commit comments

Comments
 (0)