Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable ESLint Generic Array Rule for Consistent Array Handling #2234

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ export default tseslint.config(
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/no-floating-promises': 'warn',
'no-nested-ternary': 'error',
'@typescript-eslint/array-type': [
'error',
{
default: 'generic',
},
],
'no-restricted-imports': [
'error',
{
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/deployments.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const assetsDir = path.join(
);

type VersionsByChainIdByDeploymentMap = {
[contractAlias: string]: { [chainId: string]: string[] | undefined };
[contractAlias: string]: { [chainId: string]: Array<string> | undefined };
};

export function getVersionsByChainIdByDeploymentMap(): VersionsByChainIdByDeploymentMap {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/test-app.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class TestAppProvider<T> extends AppProvider<T> {
// Disables shutdown hooks for tests (they are not required)
// Enabling this in the tests might result in a MaxListenersExceededWarning
// as the number of listeners that this adds exceed the default
protected readonly configuration: ((app: INestApplication) => void)[] =
protected readonly configuration: Array<(app: INestApplication) => void> =
DEFAULT_CONFIGURATION.filter((config) => config !== configureShutdownHooks);

constructor() {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/util/check-guard.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
export const checkGuardIsApplied = (guard: Function, fn: Function): void => {
const guards: (() => void)[] = Reflect.getMetadata('__guards__', fn);
const guards: Array<() => void> = Reflect.getMetadata('__guards__', fn);
expect(guards?.length ?? 0).toBeGreaterThan(0);
guards.some((g) => expect(g.name).toBe(guard.name));
};
10 changes: 5 additions & 5 deletions src/app.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function configureCookies(app: INestApplication): void {
app.use(cookieParser());
}

export const DEFAULT_CONFIGURATION: ((app: INestApplication) => void)[] = [
export const DEFAULT_CONFIGURATION: Array<(app: INestApplication) => void> = [
configureVersioning,
configureShutdownHooks,
configureSwagger,
Expand All @@ -69,9 +69,9 @@ export const DEFAULT_CONFIGURATION: ((app: INestApplication) => void)[] = [
* the steps taken to configure the application
*/
export abstract class AppProvider<T> {
protected abstract readonly configuration: ((
app: INestApplication,
) => void)[];
protected abstract readonly configuration: Array<
(app: INestApplication) => void
>;

public async provide(module: T): Promise<INestApplication> {
const app = await this.getApp(module);
Expand All @@ -89,7 +89,7 @@ export abstract class AppProvider<T> {
* service
*/
export class DefaultAppProvider<T> extends AppProvider<T> {
protected readonly configuration: ((app: INestApplication) => void)[] =
protected readonly configuration: Array<(app: INestApplication) => void> =
DEFAULT_CONFIGURATION;

protected getApp(module: T): Promise<INestApplication> {
Expand Down
2 changes: 1 addition & 1 deletion src/datasources/accounts/accounts.datasource.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ describe('AccountsDatasource tests', () => {
const insertedDataTypes =
await sql`INSERT INTO account_data_types ${sql(accountDataTypes, 'name', 'is_active')} returning *`;
const [inactiveDataType] = await sql<
AccountDataType[]
Array<AccountDataType>
>`SELECT * FROM account_data_types WHERE is_active IS FALSE`;
const accountDataSettingRows = insertedDataTypes.map((dataType) => ({
account_id: account.id,
Expand Down
12 changes: 6 additions & 6 deletions src/datasources/accounts/accounts.datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export class AccountsDatasource implements IAccountsDatasource, OnModuleInit {

async getAccount(address: `0x${string}`): Promise<Account> {
const cacheDir = CacheRouter.getAccountCacheDir(address);
const [account] = await this.cachedQueryResolver.get<Account[]>({
const [account] = await this.cachedQueryResolver.get<Array<Account>>({
cacheDir,
query: this.sql`SELECT * FROM accounts WHERE address = ${address}`,
ttl: this.defaultExpirationTimeInSeconds,
Expand Down Expand Up @@ -146,9 +146,9 @@ export class AccountsDatasource implements IAccountsDatasource, OnModuleInit {
}
}

async getDataTypes(): Promise<AccountDataType[]> {
async getDataTypes(): Promise<Array<AccountDataType>> {
const cacheDir = CacheRouter.getAccountDataTypesCacheDir();
return this.cachedQueryResolver.get<AccountDataType[]>({
return this.cachedQueryResolver.get<Array<AccountDataType>>({
cacheDir,
query: this.sql`SELECT * FROM account_data_types`,
ttl: MAX_TTL,
Expand All @@ -157,10 +157,10 @@ export class AccountsDatasource implements IAccountsDatasource, OnModuleInit {

async getAccountDataSettings(
address: `0x${string}`,
): Promise<AccountDataSetting[]> {
): Promise<Array<AccountDataSetting>> {
const account = await this.getAccount(address);
const cacheDir = CacheRouter.getAccountDataSettingsCacheDir(address);
return this.cachedQueryResolver.get<AccountDataSetting[]>({
return this.cachedQueryResolver.get<Array<AccountDataSetting>>({
cacheDir,
query: this.sql`
SELECT ads.* FROM account_data_settings ads
Expand All @@ -184,7 +184,7 @@ export class AccountsDatasource implements IAccountsDatasource, OnModuleInit {
async upsertAccountDataSettings(args: {
address: `0x${string}`;
upsertAccountDataSettingsDto: UpsertAccountDataSettingsDto;
}): Promise<AccountDataSetting[]> {
}): Promise<Array<AccountDataSetting>> {
const { accountDataSettings } = args.upsertAccountDataSettingsDto;
await this.checkDataTypes(accountDataSettings);
const account = await this.getAccount(args.address);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('AddressBooksDataSource', () => {

const createTestAccount = async (): Promise<Account> => {
const createAccountDto = createAccountDtoBuilder().build();
const [account] = await sql<Account[]>`
const [account] = await sql<Array<Account>>`
INSERT INTO accounts (address, name, name_hash)
VALUES (
${createAccountDto.address},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class AddressBooksDatasource implements IAddressBooksDatasource {
chainId: string;
}): Promise<AddressBook> {
const [dbAddressBook] = await this.sql<
DbAddressBook[]
Array<DbAddressBook>
>`SELECT * FROM address_books WHERE account_id = ${args.account.id} AND chain_id = ${args.chainId}`;
if (!dbAddressBook) throw new AddressBookNotFoundError();
return this.addressBookMapper.map(dbAddressBook);
Expand Down Expand Up @@ -106,7 +106,7 @@ export class AddressBooksDatasource implements IAddressBooksDatasource {
}): Promise<DbAddressBook> {
const encryptionApi = await this.encryptionApiManager.getApi();
const encryptedBlob = await encryptionApi.encryptBlob([]);
const [dbAddressBook] = await this.sql<DbAddressBook[]>`
const [dbAddressBook] = await this.sql<Array<DbAddressBook>>`
INSERT INTO address_books (account_id, chain_id, data, key, iv)
VALUES (
${args.account.id},
Expand All @@ -124,7 +124,7 @@ export class AddressBooksDatasource implements IAddressBooksDatasource {
): Promise<DbAddressBook> {
const encryptionApi = await this.encryptionApiManager.getApi();
const encryptedBlob = await encryptionApi.encryptBlob(addressBook.data);
const [dbAddressBook] = await this.sql<DbAddressBook[]>`
const [dbAddressBook] = await this.sql<Array<DbAddressBook>>`
UPDATE address_books
SET data = ${encryptedBlob.encryptedData},
key = ${encryptedBlob.encryptedDataKey},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ export class AddressBookDbMapper {

async map(addressBook: DbAddressBook): Promise<AddressBook> {
const encryptionApi = await this.encryptionApiManager.getApi();
const decryptedData = await encryptionApi.decryptBlob<AddressBookItem[]>(
const decryptedData = await encryptionApi.decryptBlob<
Array<AddressBookItem>
>(
new EncryptedBlob({
encryptedData: addressBook.data,
encryptedDataKey: addressBook.key,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('CounterfactualSafesDatasource tests', () => {
it('should create a Counterfactual Safe', async () => {
const createAccountDto = createAccountDtoBuilder().build();
const [account] = await sql<
Account[]
Array<Account>
>`INSERT INTO accounts (address, name, name_hash) VALUES (${createAccountDto.address}, ${createAccountDto.name}, ${faker.string.alphanumeric(32)}) RETURNING *`;
const createCounterfactualSafeDto =
createCounterfactualSafeDtoBuilder().build();
Expand Down Expand Up @@ -92,7 +92,7 @@ describe('CounterfactualSafesDatasource tests', () => {
it('should create a Counterfactual Safe if the rate limit is not hit', async () => {
const createAccountDto = createAccountDtoBuilder().build();
const [account] = await sql<
Account[]
Array<Account>
>`INSERT INTO accounts (address, name, name_hash) VALUES (${createAccountDto.address}, ${createAccountDto.name}, ${faker.string.alphanumeric(32)}) RETURNING *`;
const creationRateLimitCalls = faker.number.int({ min: 5, max: 10 });
const createCounterfactualSafes = faker.helpers.multiple(
Expand Down Expand Up @@ -154,7 +154,7 @@ describe('CounterfactualSafesDatasource tests', () => {
it('should fail if the rate limit is hit', async () => {
const createAccountDto = createAccountDtoBuilder().build();
const [account] = await sql<
Account[]
Array<Account>
>`INSERT INTO accounts (address, name, name_hash) VALUES (${createAccountDto.address}, ${createAccountDto.name}, ${faker.string.alphanumeric(32)}) RETURNING *`;
const creationRateLimitCalls = faker.number.int({ min: 5, max: 10 });
const createCounterfactualSafes = faker.helpers.multiple(
Expand Down Expand Up @@ -204,7 +204,7 @@ describe('CounterfactualSafesDatasource tests', () => {
it('should delete the cache for the account Counterfactual Safes', async () => {
const createAccountDto = createAccountDtoBuilder().build();
const [account] = await sql<
Account[]
Array<Account>
>`INSERT INTO accounts (address, name, name_hash) VALUES (${createAccountDto.address}, ${createAccountDto.name}, ${faker.string.alphanumeric(32)}) RETURNING *`;
await target.createCounterfactualSafe({
account,
Expand Down Expand Up @@ -236,7 +236,7 @@ describe('CounterfactualSafesDatasource tests', () => {
it('should get a Counterfactual Safe', async () => {
const createAccountDto = createAccountDtoBuilder().build();
const [account] = await sql<
Account[]
Array<Account>
>`INSERT INTO accounts (address, name, name_hash) VALUES (${createAccountDto.address}, ${createAccountDto.name}, ${faker.string.alphanumeric(32)}) RETURNING *`;
const counterfactualSafe = await target.createCounterfactualSafe({
account,
Expand All @@ -255,7 +255,7 @@ describe('CounterfactualSafesDatasource tests', () => {
it('returns a Counterfactual Safe from cache', async () => {
const createAccountDto = createAccountDtoBuilder().build();
const [account] = await sql<
Account[]
Array<Account>
>`INSERT INTO accounts (address, name, name_hash) VALUES (${createAccountDto.address}, ${createAccountDto.name}, ${faker.string.alphanumeric(32)}) RETURNING *`;
const counterfactualSafe = await target.createCounterfactualSafe({
account,
Expand Down Expand Up @@ -338,7 +338,7 @@ describe('CounterfactualSafesDatasource tests', () => {
it('should get the Counterfactual Safes for an address', async () => {
const createAccountDto = createAccountDtoBuilder().build();
const [account] = await sql<
Account[]
Array<Account>
>`INSERT INTO accounts (address, name, name_hash) VALUES (${createAccountDto.address}, ${createAccountDto.name}, ${faker.string.alphanumeric(32)}) RETURNING *`;
const counterfactualSafes = await Promise.all([
target.createCounterfactualSafe({
Expand All @@ -364,7 +364,7 @@ describe('CounterfactualSafesDatasource tests', () => {
it('should get the Counterfactual Safes for an account from cache', async () => {
const createAccountDto = createAccountDtoBuilder().build();
const [account] = await sql<
Account[]
Array<Account>
>`INSERT INTO accounts (address, name, name_hash) VALUES (${createAccountDto.address}, ${createAccountDto.name}, ${faker.string.alphanumeric(32)}) RETURNING *`;
const counterfactualSafes = await Promise.all([
target.createCounterfactualSafe({
Expand Down Expand Up @@ -412,7 +412,7 @@ describe('CounterfactualSafesDatasource tests', () => {
it('should delete a Counterfactual Safe', async () => {
const createAccountDto = createAccountDtoBuilder().build();
const [account] = await sql<
Account[]
Array<Account>
>`INSERT INTO accounts (address, name, name_hash) VALUES (${createAccountDto.address}, ${createAccountDto.name}, ${faker.string.alphanumeric(32)}) RETURNING *`;
const counterfactualSafe = await target.createCounterfactualSafe({
account,
Expand Down Expand Up @@ -446,7 +446,7 @@ describe('CounterfactualSafesDatasource tests', () => {
it('should clear the cache on Counterfactual Safe deletion', async () => {
const createAccountDto = createAccountDtoBuilder().build();
const [account] = await sql<
Account[]
Array<Account>
>`INSERT INTO accounts (address, name, name_hash) VALUES (${createAccountDto.address}, ${createAccountDto.name}, ${faker.string.alphanumeric(32)}) RETURNING *`;
const counterfactualSafe = await target.createCounterfactualSafe({
account,
Expand Down Expand Up @@ -498,7 +498,7 @@ describe('CounterfactualSafesDatasource tests', () => {
it('should delete all the Counterfactual Safes for an account', async () => {
const createAccountDto = createAccountDtoBuilder().build();
const [account] = await sql<
Account[]
Array<Account>
>`INSERT INTO accounts (address, name, name_hash) VALUES (${createAccountDto.address}, ${createAccountDto.name}, ${faker.string.alphanumeric(32)}) RETURNING *`;
const counterfactualSafes = await Promise.all([
target.createCounterfactualSafe({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class CounterfactualSafesDatasource
createCounterfactualSafeDto: CreateCounterfactualSafeDto;
}): Promise<CounterfactualSafe> {
await this.checkCreationRateLimit(args.account);
const [counterfactualSafe] = await this.sql<CounterfactualSafe[]>`
const [counterfactualSafe] = await this.sql<Array<CounterfactualSafe>>`
INSERT INTO counterfactual_safes
${this.sql([this.mapCreationDtoToRow(args.account, args.createCounterfactualSafeDto)])}
RETURNING *`;
Expand All @@ -76,10 +76,10 @@ export class CounterfactualSafesDatasource
args.predictedAddress,
);
const [counterfactualSafe] = await this.cachedQueryResolver.get<
CounterfactualSafe[]
Array<CounterfactualSafe>
>({
cacheDir,
query: this.sql<CounterfactualSafe[]>`
query: this.sql<Array<CounterfactualSafe>>`
SELECT * FROM counterfactual_safes
WHERE account_id = (SELECT id FROM accounts WHERE address = ${args.address})
AND chain_id = ${args.chainId}
Expand All @@ -96,11 +96,11 @@ export class CounterfactualSafesDatasource

getCounterfactualSafesForAddress(
address: `0x${string}`,
): Promise<CounterfactualSafe[]> {
): Promise<Array<CounterfactualSafe>> {
const cacheDir = CacheRouter.getCounterfactualSafesCacheDir(address);
return this.cachedQueryResolver.get<CounterfactualSafe[]>({
return this.cachedQueryResolver.get<Array<CounterfactualSafe>>({
cacheDir,
query: this.sql<CounterfactualSafe[]>`
query: this.sql<Array<CounterfactualSafe>>`
SELECT * FROM counterfactual_safes WHERE account_id =
(SELECT id FROM accounts WHERE address = ${address})`,
ttl: this.defaultExpirationTimeInSeconds,
Expand Down Expand Up @@ -136,10 +136,10 @@ export class CounterfactualSafesDatasource
}

async deleteCounterfactualSafesForAccount(account: Account): Promise<void> {
let deleted: CounterfactualSafe[] = [];
let deleted: Array<CounterfactualSafe> = [];
try {
const rows = await this.sql<
CounterfactualSafe[]
Array<CounterfactualSafe>
>`DELETE FROM counterfactual_safes WHERE account_id = ${account.id} RETURNING *`;
deleted = rows;
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const coingeckoApi = {
} as IPricesApi;

const coingeckoApiMock = jest.mocked(coingeckoApi);
const ZERION_BALANCES_CHAIN_IDS: string[] = faker.helpers.multiple(
const ZERION_BALANCES_CHAIN_IDS: Array<string> = faker.helpers.multiple(
() => faker.string.numeric(),
{ count: { min: 1, max: 10 } },
);
Expand Down
6 changes: 3 additions & 3 deletions src/datasources/balances-api/balances-api.manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { type Raw, rawify } from '@/validation/entities/raw.entity';
export class BalancesApiManager implements IBalancesApiManager {
private safeBalancesApiMap: Record<string, SafeBalancesApi> = {};
private readonly isCounterFactualBalancesEnabled: boolean;
private readonly zerionChainIds: string[];
private readonly zerionChainIds: Array<string>;
private readonly zerionBalancesApi: IBalancesApi;
private readonly useVpcUrl: boolean;

Expand All @@ -42,7 +42,7 @@ export class BalancesApiManager implements IBalancesApiManager {
this.configurationService.getOrThrow<boolean>(
'features.counterfactualBalances',
);
this.zerionChainIds = this.configurationService.getOrThrow<string[]>(
this.zerionChainIds = this.configurationService.getOrThrow<Array<string>>(
'features.zerionBalancesChainIds',
);
this.useVpcUrl = this.configurationService.getOrThrow<boolean>(
Expand Down Expand Up @@ -74,7 +74,7 @@ export class BalancesApiManager implements IBalancesApiManager {
}
}

async getFiatCodes(): Promise<Raw<string[]>> {
async getFiatCodes(): Promise<Raw<Array<string>>> {
const [zerionFiatCodes, safeFiatCodes] = await Promise.all([
this.zerionBalancesApi.getFiatCodes(),
this.coingeckoApi.getFiatCodes(),
Expand Down
Loading
Loading