Skip to content

Commit

Permalink
Lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardocustodio committed Nov 1, 2024
1 parent 0c15950 commit 6af8b37
Show file tree
Hide file tree
Showing 37 changed files with 62 additions and 100 deletions.
33 changes: 0 additions & 33 deletions .eslintrc

This file was deleted.

51 changes: 51 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import tsParser from "@typescript-eslint/parser";
import path from "node:path";
import { fileURLToPath } from "node:url";
import js from "@eslint/js";
import { FlatCompat } from "@eslint/eslintrc";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all
});

export default [{
ignores: ["src/model", "src/types"],
}, ...compat.extends(
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended",
"prettier",
), {
languageOptions: {
parser: tsParser,
ecmaVersion: 5,
sourceType: "script",

parserOptions: {
project: "./tsconfig.json",
},
},

rules: {
"no-console": "warn",
"import/prefer-default-export": "off",
"class-methods-use-this": "off",
"no-param-reassign": "off",
"no-underscore-dangle": "off",
"@typescript-eslint/no-explicit-any": "off",

"@typescript-eslint/no-unused-vars": ["warn", {
argsIgnorePattern: "^_",
}],

"max-len": ["error", {
code: 130,
ignoreComments: true,
ignoreStrings: true,
ignoreTemplateLiterals: true,
}],
},
}];
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"generate:types": "npm run generate:defs && npm run generate:meta",
"generate:defs": "npx tsx node_modules/.bin/polkadot-types-from-defs --package matrixchain-indexer/common/interfaces --input ./src/common/interfaces --endpoint wss://rpc.matrix.blockchain.enjin.io",
"generate:meta": "npx tsx node_modules/.bin/polkadot-types-from-chain --package matrixchain-indexer/common/interfaces --endpoint wss://rpc.matrix.blockchain.enjin.io --output ./src/common/interfaces",
"lint": "eslint src --ext .ts,.js",
"fix": "eslint src --ext .ts,.js --fix",
"lint": "eslint src ",
"fix": "eslint src --fix",
"sentry:sourcemaps": "sentry-cli sourcemaps inject --org enjin --project enjin-indexer ./lib && sentry-cli sourcemaps upload --org enjin --project enjin-indexer ./lib"
},
"dependencies": {
Expand Down
1 change: 0 additions & 1 deletion src/common/errors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable max-classes-per-file */
import * as Sentry from '@sentry/node'

export class UnknownVersionError extends Error {
Expand Down
2 changes: 1 addition & 1 deletion src/common/interfaces/lookup.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
/* eslint-disable */

/* eslint-disable sort-keys */

export default {
/**
Expand Down
1 change: 0 additions & 1 deletion src/common/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class Rpc {

public static async getInstance(): Promise<Rpc> {
if (!this._instance) {
// eslint-disable-next-line @typescript-eslint/no-shadow
const types = Object.values(definitions).reduce((res): object => ({ ...res }), {})

const api = await ApiPromise.create({
Expand Down
4 changes: 1 addition & 3 deletions src/common/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function isValidAddress(address: any) {
try {
encodeAddress(isHex(address) ? hexToU8a(address) : decodeAddress(address))
return true
} catch (e) {
} catch (_) {
return false
}
}
Expand Down Expand Up @@ -44,10 +44,8 @@ export function isAddressSS58(address: Uint8Array) {
}
}

// eslint-disable-next-line no-control-regex
const regex = /\/\/u0000/ // null string unicode

// eslint-disable-next-line no-control-regex
const regex2 = /\u0000/ // null byte unicode

export function safeString(s: string) {
Expand Down
1 change: 0 additions & 1 deletion src/job-handlers/collection-stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ export default async (job: Queue.Job<JobData>, done: Queue.DoneCallback) => {
.getRawOne(),
]

// eslint-disable-next-line @typescript-eslint/naming-convention
const [sales, [{ floor_price }], { tokenCount, supply }] = await Promise.all(promises)

const stats = new CollectionStats({
Expand Down
3 changes: 0 additions & 3 deletions src/job-handlers/fetch-balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ export default async (job: Queue.Job<JobData>, done: Queue.DoneCallback) => {
const { ids } = job.data
const data: SystemAccount[] = await fetchBalances(ids)

// eslint-disable-next-line no-restricted-syntax
for (const systemAccount of data) {
// eslint-disable-next-line no-await-in-loop
const account: Account = await getOrCreateAccount({ store: em } as any, decodeAddress(systemAccount.address))

account.nonce = systemAccount.nonce
Expand All @@ -29,7 +27,6 @@ export default async (job: Queue.Job<JobData>, done: Queue.DoneCallback) => {
account.balance.transferable = account.balance.free - account.balance.miscFrozen
account.balance.feeFrozen = 0n

// eslint-disable-next-line no-await-in-loop
await em.save<Account>(account)
}

Expand Down
2 changes: 0 additions & 2 deletions src/job-handlers/process-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ async function* tokensInBatch(em: EntityManager, collectionId: string) {
const limit = 500

while (true) {
// eslint-disable-next-line no-await-in-loop
const items = await em
.getRepository(Token)
.createQueryBuilder('token')
Expand Down Expand Up @@ -146,7 +145,6 @@ export default async (job: Queue.Job<JobData>, done: Queue.DoneCallback) => {

const batch = tokensInBatch(em, jobData.resourceId)

// eslint-disable-next-line no-restricted-syntax
for await (const tokens of batch) {
tokens.forEach((token) => {
processMetadata(token.id, 'token', true)
Expand Down
1 change: 0 additions & 1 deletion src/jobs/fetch-balance.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-restricted-syntax */
import Queue from 'bull'
import { redisConfig } from './common'
import { BlockHeader, CommonContext } from '../mappings/types/contexts'
Expand Down
13 changes: 1 addition & 12 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable no-restricted-syntax */
/* eslint-disable no-await-in-loop */
import { TypeormDatabase } from '@subsquid/typeorm-store'
import { hexStripPrefix } from '@polkadot/util'
import _ from 'lodash'
Expand Down Expand Up @@ -223,7 +221,6 @@ processor.run(
try {
ctx.log.info(`last block of batch: ${ctx.blocks[ctx.blocks.length - 1].header.height}`)

// eslint-disable-next-line no-restricted-syntax
for (const block of ctx.blocks) {
const extrinsics: Extrinsic[] = []
const signers = new Set<string>()
Expand Down Expand Up @@ -259,12 +256,10 @@ processor.run(
let fuelTank = null

if (!call) {
// eslint-disable-next-line no-continue
continue
}

if (['ParachainSystem.set_validation_data', 'Timestamp.set'].includes(call.name)) {
// eslint-disable-next-line no-continue
continue
}

Expand Down Expand Up @@ -304,14 +299,11 @@ processor.run(
: null,
})

// eslint-disable-next-line no-restricted-syntax
for (const eventItem of block.events) {
if (eventItem.name !== 'Balances.Withdraw' || eventItem.extrinsic?.id !== id) {
// eslint-disable-next-line no-continue
continue
}

// eslint-disable-next-line no-await-in-loop
const transfer = await map.balances.events.withdraw(
ctx as unknown as CommonContext,
block.header,
Expand All @@ -324,7 +316,6 @@ processor.run(
}
}

// eslint-disable-next-line no-await-in-loop
const signer = await getOrCreateAccount(ctx as unknown as CommonContext, publicKey)
const callName = call.name.split('.')
const txFee = (fee ?? 0n) + (fuelTank?.feePaid ?? 0n)
Expand Down Expand Up @@ -364,7 +355,7 @@ processor.run(
call.args.call?.value?.__kind === 'finalize_auction')
) {
const listingId = call.args.call?.value?.listingId ?? call.args.listingId
// eslint-disable-next-line no-await-in-loop

const listing = await ctx.store.findOne(Listing, {
where: { id: hexStripPrefix(listingId) },
relations: { seller: true },
Expand All @@ -382,8 +373,6 @@ processor.run(
await handleCalls(ctx as unknown as CommonContext, block.header, call)
}
for (const eventItem of block.events) {
// eslint-disable-next-line no-await-in-loop

const event = await handleEvents(ctx as unknown as CommonContext, block.header, eventItem, false)

if (event) {
Expand Down
4 changes: 0 additions & 4 deletions src/mappings/balances/processor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable no-continue */
/* eslint-disable no-await-in-loop */
import { BlockHeader } from '@subsquid/substrate-processor'
import chunk from 'lodash/chunk'
import { UnknownVersionError } from '../../common/errors'
Expand Down Expand Up @@ -280,9 +278,7 @@ export async function saveAccounts(ctx: CommonContext, block: BlockHeader) {
const accountIds = Array.from(accountsSet)
if (accountIds.length === 0) return

// eslint-disable-next-line no-restricted-syntax
for (const chunked of chunk(accountIds, 100)) {
// eslint-disable-next-line no-await-in-loop
const accountInfos = await getBalances(ctx, block, chunked)

if (accountInfos === undefined || accountInfos.length === 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/mappings/multiTokens/events/collection_created.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ async function getCollectionId(ctx: CommonContext, block: BlockHeader, collectio
if (storage.multiTokens.collections.v1010.is(block)) {
const data = await storage.multiTokens.collections.v1010.get(block, collectionId)
const currencies: [AssetId, any][] | undefined = data?.explicitRoyaltyCurrencies
// eslint-disable-line @typescript-eslint/no-unused-vars

const assets = currencies?.map(([assetId, _]) => assetId)

if (data) {
Expand All @@ -243,7 +243,7 @@ async function getCollectionId(ctx: CommonContext, block: BlockHeader, collectio
if (storage.multiTokens.collections.matrixEnjinV603.is(block)) {
const data = await storage.multiTokens.collections.matrixEnjinV603.get(block, collectionId)
const currencies: [AssetId, any][] | undefined = data?.explicitRoyaltyCurrencies
// eslint-disable-line @typescript-eslint/no-unused-vars

const assets = currencies?.map(([assetId, _]) => assetId)

if (data) {
Expand Down
5 changes: 1 addition & 4 deletions src/mappings/multiTokens/events/collection_mutated.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-restricted-syntax */
import { UnknownVersionError, throwError } from '../../../common/errors'
import { events } from '../../../types/generated'
import {
Expand Down Expand Up @@ -92,11 +91,10 @@ export async function collectionMutated(
)
if (rc) {
royaltyCurrencies.splice(royaltyCurrencies.indexOf(rc), 1)
// eslint-disable-next-line no-continue

continue
}

// eslint-disable-next-line no-await-in-loop
const token = await ctx.store.findOne<Token>(Token, {
where: { id: `${currency.collectionId}-${currency.tokenId}` },
})
Expand All @@ -113,7 +111,6 @@ export async function collectionMutated(
token,
})

// eslint-disable-next-line no-await-in-loop
await ctx.store.insert(royaltyCurrency)
}
}
Expand Down
1 change: 0 additions & 1 deletion src/mappings/multiTokens/events/collection_transferred.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-restricted-syntax */
import { throwError, UnknownVersionError } from '../../../common/errors'
import { events } from '../../../types/generated'
import { Collection, Event as EventModel, Extrinsic, MultiTokensCollectionTransferred } from '../../../model'
Expand Down
3 changes: 1 addition & 2 deletions src/mappings/util/balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ export async function fetchBalances(ids: string[]): Promise<SystemAccount[]> {
const { api } = await Rpc.getInstance()

// We could use a multi query but that would be error prone
// eslint-disable-next-line no-restricted-syntax

for (const id of ids) {
// eslint-disable-next-line no-await-in-loop
const balance = await api.query.system.account(id)
accounts.push({
address: id,
Expand Down
7 changes: 2 additions & 5 deletions src/mappings/util/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-console */
import Axios from 'axios'
import https from 'https'
import Queue from 'bull'
Expand Down Expand Up @@ -42,7 +41,6 @@ export async function fetchMetadata(url: string, job: Queue.Job) {
throw new Error(`Failed to fetch metadata from ${url}`)
} catch (error: unknown) {
if (!Axios.isAxiosError(error)) {
// eslint-disable-next-line no-console
job.log(`Failed to fetch metadata from ${url} (non-axios) : ${(error as any).toString()}`)
throw error
}
Expand Down Expand Up @@ -80,15 +78,14 @@ function parseMedia(value: string | Media[]) {
)
}
return null
} catch (e) {
} catch (_) {
return null
}
}

function parseObjectProperties(value: object) {
const properties: any = {}

// eslint-disable-next-line no-restricted-syntax
for (const [k, v] of Object.entries(value)) {
if (typeof v === 'object' && v !== null && 'value' in v && v.value && typeof v.value !== 'object') {
properties[k] = v
Expand Down Expand Up @@ -208,7 +205,7 @@ export function metadataParser(
metadata.attributes = parseArrayAttributes(attributes)
}
}
} catch (e) {
} catch (_) {
/* empty */
}
}
Expand Down
1 change: 0 additions & 1 deletion src/prom-metrics/definitions/fuelTank.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/naming-convention */
import client from 'prom-client'
import register from '../registry'
import connection from '../../connection'
Expand Down
1 change: 0 additions & 1 deletion src/prom-metrics/definitions/identity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/naming-convention */
import client from 'prom-client'
import register from '../registry'
import connection from '../../connection'
Expand Down
1 change: 0 additions & 1 deletion src/prom-metrics/definitions/info.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/naming-convention */
import client from 'prom-client'
import register from '../registry'
import connection from '../../connection'
Expand Down
1 change: 0 additions & 1 deletion src/prom-metrics/definitions/marketplace.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/naming-convention */
import client from 'prom-client'
import register from '../registry'
import connection from '../../connection'
Expand Down
1 change: 0 additions & 1 deletion src/prom-metrics/definitions/migration.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/naming-convention */
import client from 'prom-client'
import register from '../registry'
import connection from '../../connection'
Expand Down
Loading

0 comments on commit 6af8b37

Please sign in to comment.