Showing 179 of 2,612 total issues
infoMapping
has 23 functions (exceeds 20 allowed). Consider refactoring. Open
Open
const infoMapping: Record<TypeDefInfo, (registry: Registry, value: TypeDef) => CodecClass<Codec>> = {
[TypeDefInfo.BTreeMap]: (_registry: Registry, value: TypeDef): CodecClass<Codec> =>
createHashMap(BTreeMap, value),
[TypeDefInfo.BTreeSet]: (_registry: Registry, value: TypeDef): CodecClass<Codec> =>
Function mainPromise
has 62 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
async function mainPromise (): Promise<void> {
const { endpoint, input, package: pkg } = yargs(hideBin(process.argv)).strict().options({
endpoint: {
description: 'The endpoint to connect to (e.g. wss://kusama-rpc.polkadot.io) or relative path to a file containing the JSON output of an RPC state_getMetadata call',
type: 'string'
Function modules
has 62 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
const modules = rpcKeys.map((sectionFullName) => {
const rpc = definitions[sectionFullName].rpc || {};
const section = sectionFullName.split('/').pop();
const allMethods = Object.keys(rpc).sort().map((methodName) => {
Function tsEnum
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
Open
function tsEnum (registry: Registry, definitions: Record<string, ModuleTypes>, { lookupIndex, name: enumName, sub }: TypeDef, imports: TypeImports, withShortcut = false): string {
setImports(definitions, imports, ['Enum']);
const indent = withShortcut ? ' ' : '';
const named = (sub as TypeDef[]).filter(({ name }) => !!name && !name.startsWith('__Unused'));
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function generateForMeta
has 59 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function generateForMeta (registry: Registry, meta: Metadata, dest: string, extraTypes: ExtraTypes, isStrict: boolean, customLookupDefinitions?: Definitions): void {
writeFile(dest, (): string => {
const allTypes: ExtraTypes = {
'@polkadot/types-augment': {
lookup: {
File toV14.ts
has 263 lines of code (exceeds 250 allowed). Consider refactoring. Open
Open
// Copyright 2017-2024 @polkadot/types authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Text, Type } from '@polkadot/types-codec';
import type { ErrorMetadataV13, EventMetadataV13, ExtrinsicMetadataV13, ExtrinsicMetadataV14, FunctionMetadataV13, MetadataV13, MetadataV14, ModuleConstantMetadataV13, ModuleMetadataV13, PalletCallMetadataV14, PalletConstantMetadataV14, PalletErrorMetadataV14, PalletEventMetadataV14, PalletMetadataV14, PalletStorageMetadataV14, StorageEntryMetadataV14, StorageEntryTypeV14, StorageHasherV13, StorageMetadataV13 } from '../../interfaces/metadata/index.js';
Function generateForMeta
has 57 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function generateForMeta (meta: Metadata, dest: string, extraTypes: ExtraTypes, isStrict: boolean, customLookupDefinitions?: Definitions): void {
writeFile(dest, (): string => {
const allTypes = {
'@polkadot/types-augment': {
lookup: {
Function generateForMeta
has 57 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function generateForMeta (meta: Metadata, dest: string, extraTypes: ExtraTypes, isStrict: boolean, customLookupDefinitions?: Definitions): void {
writeFile(dest, (): string => {
const allTypes = {
'@polkadot/types-augment': {
lookup: {
File consts.ts
has 261 lines of code (exceeds 250 allowed). Consider refactoring. Open
Open
// Auto-generated via `yarn polkadot-types-from-chain`, do not edit
/* eslint-disable */
// import type lookup before we augment - in some environments
// this is required to allow for ambient/previous definitions
Getters
has 21 functions (exceeds 20 allowed). Consider refactoring. Open
Open
export abstract class Getters<ApiType extends ApiTypes> extends Init<ApiType> implements ApiDecoration<ApiType> {
/**
* @description Runtime call interfaces (currently untyped, only decorated via API options)
*/
public get call (): QueryableCalls<ApiType> {
Function allMethods
has 54 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
const allMethods = Object.keys(rpc).sort().map((methodName) => {
const def = rpc[methodName];
let args;
let type;
Function getAuthorDetailsWithAt
has 52 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function getAuthorDetailsWithAt (header: Header, queryAt: QueryableStorage<'rxjs'>): Observable<[Header, Vec<AccountId> | null, AccountId | null]> {
const validators = queryAt.session?.validators
? queryAt.session.validators()
: of(null);
Function parseRewards
has 51 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function parseRewards (api: DeriveApi, stashId: AccountId, [erasPoints, erasPrefs, erasRewards]: ErasResult, exposures: DeriveStakerExposure[]): DeriveStakerReward[] {
return exposures.map(({ era, isEmpty, isValidator, nominating, validators: eraValidators }): DeriveStakerReward => {
const { eraPoints, validators: allValPoints } = erasPoints.find((p) => p.era.eq(era)) || { eraPoints: BN_ZERO, validators: {} as DeriveEraValPoints };
const { eraReward } = erasRewards.find((r) => r.era.eq(era)) || { eraReward: api.registry.createType('Balance') };
const { validators: allValPrefs } = erasPrefs.find((p) => p.era.eq(era)) || { validators: {} as DeriveEraValPrefs };
Function mainPromise
has 49 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
async function mainPromise (): Promise<void> {
const { chain, endpoint } = yargs(hideBin(process.argv)).strict().options({
chain: {
description: 'The chain name to use for the output (defaults to "Substrate")',
type: 'string'
Function addRpc
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function addRpc (_runtimeDesc: string, rpcMethods?: string[]): string {
return renderPage({
description: 'The following sections contain known RPC methods that may be available on specific nodes (depending on configuration and available pallets) and allow you to interact with the actual node, query, and submit.',
sections: Object
.keys(definitions)
Function generate
has 45 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
async function generate (metaHex: HexString, pkg: string | undefined, output: string, isStrict?: boolean): Promise<void> {
console.log(`Generating from metadata, ${formatNumber((metaHex.length - 2) / 2)} bytes`);
const outputPath = assertDir(path.join(process.cwd(), output));
let extraTypes: Record<string, any> = {};
Function addRuntime
has 44 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function addRuntime (_runtimeDesc: string, apis?: ApiDef[]): string {
return renderPage({
description: 'The following section contains known runtime calls that may be available on specific runtimes (depending on configuration and available pallets). These call directly into the WASM runtime for queries and operations.',
sections: Object
.keys(definitions)
Function _stakerRewards
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
export function _stakerRewards (instanceId: string, api: DeriveApi): (accountIds: (Uint8Array | string)[], eras: EraIndex[], withActive?: boolean) => Observable<DeriveStakerReward[][]> {
return memo(instanceId, (accountIds: (Uint8Array | string)[], eras: EraIndex[], withActive = false): Observable<DeriveStakerReward[][]> => {
// Ensures that when number or string types are passed in they are sanitized
// Ref: https://github.com/polkadot-js/api/issues/5910
const sanitizedEras: EraIndex[] = eras.map((e) => typeof e === 'number' || typeof e === 'string' ? api.registry.createType('u32', e) : e);
Function filterRewards
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function filterRewards (stashIds: AccountId[], eras: number[], claimedRewards: [StorageKey<[u32, AccountId]>, Vec<u32>][], stakersOverview: [StorageKey<[u32, AccountId]>, Option<SpStakingPagedExposureMetadata>][]): number[][] {
const claimedData: Record<string, Map<number, u32[]>> = {};
const overviewData: Record<string, Map<number, u32>> = {};
const ids = stashIds.map((i) => i.toString());
Function queryCurrent
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function queryCurrent (api: DeriveApi, accountId: AccountId | string, balanceInstances: string[] = ['balances']): Observable<ResultBalance> {
const [lockEmpty, lockQueries] = createCalls<Vec<PalletBalancesBalanceLock>>(
balanceInstances.map((m) =>
(api.derive as DeriveCustomLocks)[m]?.customLocks || api.query[m as 'balances']?.locks
)