refactor: use eslint-config-neon for packages. (#8579)

Co-authored-by: Noel <buechler.noel@outlook.com>
This commit is contained in:
Suneet Tipirneni
2022-09-01 14:50:16 -04:00
committed by GitHub
parent 4bdb0593ae
commit edadb9fe5d
219 changed files with 2608 additions and 2053 deletions

View File

@@ -1,10 +1,12 @@
/* eslint-disable id-length */
/* eslint-disable no-param-reassign */
/* eslint-disable @typescript-eslint/restrict-template-expressions */
/**
* @internal
*/
export interface CollectionConstructor {
new (): Collection<unknown, unknown>;
new <K, V>(entries?: ReadonlyArray<readonly [K, V]> | null): Collection<K, V>;
new <K, V>(entries?: readonly (readonly [K, V])[] | null): Collection<K, V>;
new <K, V>(iterable: Iterable<readonly [K, V]>): Collection<K, V>;
readonly prototype: Collection<unknown, unknown>;
readonly [Symbol.species]: CollectionConstructor;
@@ -13,8 +15,11 @@ export interface CollectionConstructor {
/**
* Represents an immutable version of a collection
*/
export type ReadonlyCollection<K, V> = ReadonlyMap<K, V> &
Omit<Collection<K, V>, 'forEach' | 'ensure' | 'reverse' | 'sweep' | 'sort' | 'get' | 'set' | 'delete'>;
export type ReadonlyCollection<K, V> = Omit<
Collection<K, V>,
'delete' | 'ensure' | 'forEach' | 'get' | 'reverse' | 'set' | 'sort' | 'sweep'
> &
ReadonlyMap<K, V>;
/**
* Separate interface for the constructor so that emitted js does not have a constructor that overwrites itself
@@ -38,7 +43,6 @@ export class Collection<K, V> extends Map<K, V> {
*
* @param key - The key to get if it exists, or set otherwise
* @param defaultValueGenerator - A function that generates the default value
*
* @example
* ```ts
* collection.ensure(guildId, () => defaultGuildConfig);
@@ -56,7 +60,6 @@ export class Collection<K, V> extends Map<K, V> {
* Checks if all of the elements exist in the collection.
*
* @param keys - The keys of the elements to check for
*
* @returns `true` if all of the elements exist, `false` if at least one does not exist.
*/
public hasAll(...keys: K[]) {
@@ -67,7 +70,6 @@ export class Collection<K, V> extends Map<K, V> {
* Checks if any of the elements exist in the collection.
*
* @param keys - The keys of the elements to check for
*
* @returns `true` if any of the elements exist, `false` if none exist.
*/
public hasAny(...keys: K[]) {
@@ -78,7 +80,6 @@ export class Collection<K, V> extends Map<K, V> {
* Obtains the first value(s) in this collection.
*
* @param amount - Amount of values to obtain from the beginning
*
* @returns A single value if no amount is provided or an array of values, starting from the end if amount is negative
*/
public first(): V | undefined;
@@ -97,7 +98,6 @@ export class Collection<K, V> extends Map<K, V> {
* Obtains the first key(s) in this collection.
*
* @param amount - Amount of keys to obtain from the beginning
*
* @returns A single key if no amount is provided or an array of keys, starting from the end if
* amount is negative
*/
@@ -117,7 +117,6 @@ export class Collection<K, V> extends Map<K, V> {
* Obtains the last value(s) in this collection.
*
* @param amount - Amount of values to obtain from the end
*
* @returns A single value if no amount is provided or an array of values, starting from the start if
* amount is negative
*/
@@ -135,7 +134,6 @@ export class Collection<K, V> extends Map<K, V> {
* Obtains the last key(s) in this collection.
*
* @param amount - Amount of keys to obtain from the end
*
* @returns A single key if no amount is provided or an array of keys, starting from the start if
* amount is negative
*/
@@ -179,7 +177,6 @@ export class Collection<K, V> extends Map<K, V> {
* Obtains unique random value(s) from this collection.
*
* @param amount - Amount of values to obtain randomly
*
* @returns A single value if no amount is provided or an array of values
*/
public random(): V | undefined;
@@ -198,7 +195,6 @@ export class Collection<K, V> extends Map<K, V> {
* Obtains unique random key(s) from this collection.
*
* @param amount - Amount of keys to obtain randomly
*
* @returns A single key if no amount is provided or an array
*/
public randomKey(): K | undefined;
@@ -233,7 +229,6 @@ export class Collection<K, V> extends Map<K, V> {
*
* @param fn - The function to test with (should return boolean)
* @param thisArg - Value to use as `this` when executing function
*
* @example
* ```ts
* collection.find(user => user.username === 'Bob');
@@ -252,6 +247,7 @@ export class Collection<K, V> extends Map<K, V> {
for (const [key, val] of this) {
if (fn(val, key, this)) return val;
}
return undefined;
}
@@ -262,7 +258,6 @@ export class Collection<K, V> extends Map<K, V> {
*
* @param fn - The function to test with (should return boolean)
* @param thisArg - Value to use as `this` when executing function
*
* @example
* ```ts
* collection.findKey(user => user.username === 'Bob');
@@ -281,6 +276,7 @@ export class Collection<K, V> extends Map<K, V> {
for (const [key, val] of this) {
if (fn(val, key, this)) return key;
}
return undefined;
}
@@ -289,7 +285,6 @@ export class Collection<K, V> extends Map<K, V> {
*
* @param fn - Function used to test (should return a boolean)
* @param thisArg - Value to use as `this` when executing function
*
* @returns The number of removed entries
*/
public sweep(fn: (value: V, key: K, collection: this) => boolean): number;
@@ -301,6 +296,7 @@ export class Collection<K, V> extends Map<K, V> {
for (const [key, val] of this) {
if (fn(val, key, this)) this.delete(key);
}
return previousSize - this.size;
}
@@ -311,7 +307,6 @@ export class Collection<K, V> extends Map<K, V> {
*
* @param fn - The function to test with (should return boolean)
* @param thisArg - Value to use as `this` when executing function
*
* @example
* ```ts
* collection.filter(user => user.username === 'Bob');
@@ -336,6 +331,7 @@ export class Collection<K, V> extends Map<K, V> {
for (const [key, val] of this) {
if (fn(val, key, this)) results.set(key, val);
}
return results;
}
@@ -345,7 +341,6 @@ export class Collection<K, V> extends Map<K, V> {
*
* @param fn - Function used to test (should return a boolean)
* @param thisArg - Value to use as `this` when executing function
*
* @example
* ```ts
* const [big, small] = collection.partition(guild => guild.memberCount > 250);
@@ -387,6 +382,7 @@ export class Collection<K, V> extends Map<K, V> {
results[1].set(key, val);
}
}
return results;
}
@@ -396,7 +392,6 @@ export class Collection<K, V> extends Map<K, V> {
*
* @param fn - Function that produces a new Collection
* @param thisArg - Value to use as `this` when executing function
*
* @example
* ```ts
* collection.flatMap(guild => guild.members.cache);
@@ -408,6 +403,7 @@ export class Collection<K, V> extends Map<K, V> {
thisArg: This,
): Collection<K, T>;
public flatMap<T>(fn: (value: V, key: K, collection: this) => Collection<K, T>, thisArg?: unknown): Collection<K, T> {
// eslint-disable-next-line unicorn/no-array-method-this-argument
const collections = this.map(fn, thisArg);
return new this.constructor[Symbol.species]<K, T>().concat(...collections);
}
@@ -418,7 +414,6 @@ export class Collection<K, V> extends Map<K, V> {
*
* @param fn - Function that produces an element of the new array, taking three arguments
* @param thisArg - Value to use as `this` when executing function
*
* @example
* ```ts
* collection.map(user => user.tag);
@@ -444,7 +439,6 @@ export class Collection<K, V> extends Map<K, V> {
*
* @param fn - Function that produces an element of the new collection, taking three arguments
* @param thisArg - Value to use as `this` when executing function
*
* @example
* ```ts
* collection.mapValues(user => user.tag);
@@ -466,7 +460,6 @@ export class Collection<K, V> extends Map<K, V> {
*
* @param fn - Function used to test (should return a boolean)
* @param thisArg - Value to use as `this` when executing function
*
* @example
* ```ts
* collection.some(user => user.discriminator === '0000');
@@ -480,6 +473,7 @@ export class Collection<K, V> extends Map<K, V> {
for (const [key, val] of this) {
if (fn(val, key, this)) return true;
}
return false;
}
@@ -489,7 +483,6 @@ export class Collection<K, V> extends Map<K, V> {
*
* @param fn - Function used to test (should return a boolean)
* @param thisArg - Value to use as `this` when executing function
*
* @example
* ```ts
* collection.every(user => !user.bot);
@@ -513,6 +506,7 @@ export class Collection<K, V> extends Map<K, V> {
for (const [key, val] of this) {
if (!fn(val, key, this)) return false;
}
return true;
}
@@ -523,7 +517,6 @@ export class Collection<K, V> extends Map<K, V> {
* @param fn - Function used to reduce, taking four arguments; `accumulator`, `currentValue`, `currentKey`,
* and `collection`
* @param initialValue - Starting value for the accumulator
*
* @example
* ```ts
* collection.reduce((acc, guild) => acc + guild.memberCount, 0);
@@ -538,6 +531,7 @@ export class Collection<K, V> extends Map<K, V> {
for (const [key, val] of this) accumulator = fn(accumulator, val, key, this);
return accumulator;
}
let first = true;
for (const [key, val] of this) {
if (first) {
@@ -545,6 +539,7 @@ export class Collection<K, V> extends Map<K, V> {
first = false;
continue;
}
accumulator = fn(accumulator, val, key, this);
}
@@ -563,7 +558,6 @@ export class Collection<K, V> extends Map<K, V> {
*
* @param fn - Function to execute for each element
* @param thisArg - Value to use as `this` when executing function
*
* @example
* ```ts
* collection
@@ -576,6 +570,7 @@ export class Collection<K, V> extends Map<K, V> {
public each<T>(fn: (this: T, value: V, key: K, collection: this) => void, thisArg: T): this;
public each(fn: (value: V, key: K, collection: this) => void, thisArg?: unknown): this {
if (typeof fn !== 'function') throw new TypeError(`${fn} is not a function`);
// eslint-disable-next-line unicorn/no-array-method-this-argument
this.forEach(fn as (value: V, key: K, map: Map<K, V>) => void, thisArg);
return this;
}
@@ -585,7 +580,6 @@ export class Collection<K, V> extends Map<K, V> {
*
* @param fn - Function to execute
* @param thisArg - Value to use as `this` when executing function
*
* @example
* ```ts
* collection
@@ -619,7 +613,6 @@ export class Collection<K, V> extends Map<K, V> {
* Combines this collection with others into a new collection. None of the source collections are modified.
*
* @param collections - Collections to merge
*
* @example
* ```ts
* const newColl = someColl.concat(someOtherColl, anotherColl, ohBoyAColl);
@@ -630,6 +623,7 @@ export class Collection<K, V> extends Map<K, V> {
for (const coll of collections) {
for (const [key, val] of coll) newColl.set(key, val);
}
return newColl;
}
@@ -639,7 +633,6 @@ export class Collection<K, V> extends Map<K, V> {
* the collections may be different objects, but contain the same data.
*
* @param collection - Collection to compare with
*
* @returns Whether the collections have identical contents
*/
public equals(collection: ReadonlyCollection<K, V>) {
@@ -652,6 +645,7 @@ export class Collection<K, V> extends Map<K, V> {
return false;
}
}
return true;
}
@@ -662,7 +656,6 @@ export class Collection<K, V> extends Map<K, V> {
*
* @param compareFunction - Specifies a function that defines the sort order.
* If omitted, the collection is sorted according to each character's Unicode code point value, according to the string conversion of each element.
*
* @example
* ```ts
* collection.sort((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);
@@ -679,6 +672,7 @@ export class Collection<K, V> extends Map<K, V> {
for (const [k, v] of entries) {
super.set(k, v);
}
return this;
}
@@ -694,6 +688,7 @@ export class Collection<K, V> extends Map<K, V> {
coll.set(k, v);
}
}
return coll;
}
@@ -702,24 +697,26 @@ export class Collection<K, V> extends Map<K, V> {
*
* @param other - The other Collection to filter against
*/
public difference<T>(other: ReadonlyCollection<K, T>): Collection<K, V | T> {
const coll = new this.constructor[Symbol.species]<K, V | T>();
public difference<T>(other: ReadonlyCollection<K, T>): Collection<K, T | V> {
const coll = new this.constructor[Symbol.species]<K, T | V>();
for (const [k, v] of other) {
if (!this.has(k)) coll.set(k, v);
}
for (const [k, v] of this) {
if (!other.has(k)) coll.set(k, v);
}
return coll;
}
/**
* Merges two Collections together into a new Collection.
*
* @param other - The other Collection to merge with
* @param whenInSelf - Function getting the result if the entry only exists in this Collection
* @param whenInOther - Function getting the result if the entry only exists in the other Collection
* @param whenInBoth - Function getting the result if the entry exists in both Collections
*
* @example
* ```ts
* // Sums up the entries in two collections.
@@ -730,7 +727,6 @@ export class Collection<K, V> extends Map<K, V> {
* (x, y) => ({ keep: true, value: x + y }),
* );
* ```
*
* @example
* ```ts
* // Intersects two collections in a left-biased manner.
@@ -765,6 +761,7 @@ export class Collection<K, V> extends Map<K, V> {
if (r.keep) coll.set(k, r.value);
}
}
return coll;
}
@@ -776,7 +773,6 @@ export class Collection<K, V> extends Map<K, V> {
* @param compareFunction - Specifies a function that defines the sort order.
* If omitted, the collection is sorted according to each character's Unicode code point value,
* according to the string conversion of each element.
*
* @example
* ```ts
* collection.sorted((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);
@@ -800,7 +796,6 @@ export class Collection<K, V> extends Map<K, V> {
*
* @param entries - The list of entries
* @param combine - Function to combine an existing entry with a new one
*
* @example
* ```ts
* Collection.combineEntries([["a", 1], ["b", 2], ["a", 2]], (x, y) => x + y);
@@ -819,6 +814,7 @@ export class Collection<K, V> extends Map<K, V> {
coll.set(k, v);
}
}
return coll;
}
}
@@ -826,7 +822,7 @@ export class Collection<K, V> extends Map<K, V> {
/**
* @internal
*/
export type Keep<V> = { keep: true; value: V } | { keep: false };
export type Keep<V> = { keep: false } | { keep: true; value: V };
/**
* @internal

View File

@@ -1 +1 @@
export * from './collection';
export * from './collection.js';