Skip to content

Commit

Permalink
Added the eslint rule to help with import order and ran the fix (#3885)
Browse files Browse the repository at this point in the history
* Added the eslint rule to help with import order and ran the fix

* Tweaked the eslint rule to have siblings as the last imports

* upgraded es-lint versions. ran eslint fix

* fix linting errors due to @typescript-eslint/member-ordering

* Revert "fix linting errors due to @typescript-eslint/member-ordering"

This reverts commit 4dbafef.

* set member-ordering issues to warn
  • Loading branch information
dadepo authored May 27, 2022
1 parent 7f7ef80 commit dfd4cdc
Show file tree
Hide file tree
Showing 310 changed files with 2,599 additions and 2,432 deletions.
17 changes: 16 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ module.exports = {
"prettier/prettier": "error",
//doesnt work, it reports false errors
"constructor-super": "off",
"import/order" : [
"error",
{ "groups":
[
"builtin",
"external",
"internal",
"parent",
"sibling",
"index",
],
}
],
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/naming-convention": [
"error",
Expand Down Expand Up @@ -70,7 +83,8 @@ module.exports = {
},
],
"@typescript-eslint/func-call-spacing": "error",
"@typescript-eslint/member-ordering": "error",
// TODO after upgrading es-lint, member-ordering is now leading to lint errors. Set to warning now and fix in another PR
"@typescript-eslint/member-ordering": "warn",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-require-imports": "error",
"@typescript-eslint/no-unused-vars": [
Expand Down Expand Up @@ -161,6 +175,7 @@ module.exports = {
],
},
settings: {
"import/internal-regex": "^@chainsafe/",
"import/core-modules": [
"node:child_process",
"node:crypto",
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@
"@types/mocha": "^8.0.3",
"@types/node": "^14.14.17",
"@types/sinon": "^9.0.0",
"@typescript-eslint/eslint-plugin": "4.31.1",
"@typescript-eslint/parser": "4.31.1",
"@typescript-eslint/eslint-plugin": "5.26.0",
"@typescript-eslint/parser": "5.26.0",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"codecov": "^3.8.3",
"eslint": "^7.14.0",
"eslint-plugin-import": "^2.23.0",
"eslint-plugin-no-only-tests": "^2.4.0",
"eslint-plugin-prettier": "^3.1.4",
"eslint": "^8.16.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-no-only-tests": "^2.6.0",
"eslint-plugin-prettier": "^4.0.0",
"lerna": "^4.0.0",
"mocha": "^9.2.2",
"npm-run-all": "^4.1.5",
Expand Down
6 changes: 3 additions & 3 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@
"@chainsafe/ssz": "^0.9.1",
"cross-fetch": "^3.1.4",
"eventsource": "^2.0.2",
"qs": "^6.10.1"
"qs": "^6.10.1",
"fastify": "3.15.1"
},
"devDependencies": {
"@types/eventsource": "^1.1.5",
"@types/qs": "^6.9.6",
"fastify": "3.15.1"
"@types/qs": "^6.9.6"
},
"peerDependencies": {
"fastify": "3.15.1"
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/client/beacon.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {IChainForkConfig} from "@chainsafe/lodestar-config";
import {IHttpClient, generateGenericJsonClient} from "./utils/index.js";
import {Api, ReqTypes, routesData, getReqSerializers, getReturnTypes} from "../routes/beacon/index.js";
import {IHttpClient, generateGenericJsonClient} from "./utils/index.js";

/**
* REST HTTP client for beacon routes
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/client/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {IChainForkConfig} from "@chainsafe/lodestar-config";
import {IHttpClient, generateGenericJsonClient} from "./utils/index.js";
import {Api, ReqTypes, routesData, getReqSerializers, getReturnTypes} from "../routes/config.js";
import {IHttpClient, generateGenericJsonClient} from "./utils/index.js";

/**
* REST HTTP client for config routes
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/client/debug.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {IChainForkConfig} from "@chainsafe/lodestar-config";
import {IHttpClient, getFetchOptsSerializers, generateGenericJsonClient} from "./utils/index.js";
import {Api, ReqTypes, routesData, getReqSerializers, getReturnTypes, StateFormat} from "../routes/debug.js";
import {IHttpClient, getFetchOptsSerializers, generateGenericJsonClient} from "./utils/index.js";

/**
* REST HTTP client for debug routes
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/client/lightclient.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {IChainForkConfig} from "@chainsafe/lodestar-config";
import {deserializeProof} from "@chainsafe/persistent-merkle-tree";
import {IHttpClient, getFetchOptsSerializers, generateGenericJsonClient} from "./utils/index.js";
import {Api, ReqTypes, routesData, getReqSerializers, getReturnTypes} from "../routes/lightclient.js";
import {IHttpClient, getFetchOptsSerializers, generateGenericJsonClient} from "./utils/index.js";

/**
* REST HTTP client for lightclient routes
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/client/lodestar.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {IChainForkConfig} from "@chainsafe/lodestar-config";
import {IHttpClient, generateGenericJsonClient} from "./utils/index.js";
import {Api, ReqTypes, routesData, getReqSerializers, getReturnTypes} from "../routes/lodestar.js";
import {IHttpClient, generateGenericJsonClient} from "./utils/index.js";

/**
* REST HTTP client for lodestar routes
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/client/node.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {IChainForkConfig} from "@chainsafe/lodestar-config";
import {IHttpClient, generateGenericJsonClient} from "./utils/index.js";
import {Api, ReqTypes, routesData, getReqSerializers, getReturnTypes} from "../routes/node.js";
import {IHttpClient, generateGenericJsonClient} from "./utils/index.js";

/**
* REST HTTP client for beacon routes
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/client/utils/client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {mapValues} from "@chainsafe/lodestar-utils";
import {FetchOpts, IHttpClient} from "./httpClient.js";
import {compileRouteUrlFormater} from "../../utils/urlFormat.js";
import {
RouteDef,
Expand All @@ -11,6 +10,7 @@ import {
ReqSerializers,
RoutesData,
} from "../../utils/types.js";
import {FetchOpts, IHttpClient} from "./httpClient.js";

// See /packages/api/src/routes/index.ts for reasoning

Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/client/validator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {IChainForkConfig} from "@chainsafe/lodestar-config";
import {IHttpClient, generateGenericJsonClient} from "./utils/index.js";
import {Api, ReqTypes, routesData, getReqSerializers, getReturnTypes} from "../routes/validator.js";
import {IHttpClient, generateGenericJsonClient} from "./utils/index.js";

/**
* REST HTTP client for validator routes
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/keymanager/client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {IChainForkConfig} from "@chainsafe/lodestar-config";
import {IHttpClient, generateGenericJsonClient} from "../client/utils/index.js";
import {Api, ReqTypes, routesData, getReqSerializers, getReturnTypes} from "./routes.js";
import {IChainForkConfig} from "@chainsafe/lodestar-config";

export function getClient(_config: IChainForkConfig, httpClient: IHttpClient): Api {
const reqSerializers = getReqSerializers();
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/routes/debug.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {ForkName} from "@chainsafe/lodestar-params";
import {allForks, Slot, RootHex, ssz, StringType} from "@chainsafe/lodestar-types";
import {ContainerType} from "@chainsafe/ssz";
import {StateId} from "./beacon/state.js";
import {
ArrayOf,
ContainerData,
Expand All @@ -15,6 +14,7 @@ import {
ReqEmpty,
ReqSerializer,
} from "../utils/index.js";
import {StateId} from "./beacon/state.js";

// See /packages/api/src/routes/index.ts for reasoning and instructions to add new routes

Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/server/beacon.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {IChainForkConfig} from "@chainsafe/lodestar-config";
import {ServerRoutes, getGenericJsonServer} from "./utils/index.js";
import {Api, ReqTypes, routesData, getReturnTypes, getReqSerializers} from "../routes/beacon/index.js";
import {ServerRoutes, getGenericJsonServer} from "./utils/index.js";

export function getRoutes(config: IChainForkConfig, api: Api): ServerRoutes<Api, ReqTypes> {
// All routes return JSON, use a server auto-generator
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/server/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {IChainForkConfig} from "@chainsafe/lodestar-config";
import {ServerRoutes, getGenericJsonServer} from "./utils/index.js";
import {Api, ReqTypes, routesData, getReturnTypes, getReqSerializers} from "../routes/config.js";
import {ServerRoutes, getGenericJsonServer} from "./utils/index.js";

export function getRoutes(config: IChainForkConfig, api: Api): ServerRoutes<Api, ReqTypes> {
// All routes return JSON, use a server auto-generator
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/server/debug.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {IChainForkConfig} from "@chainsafe/lodestar-config";
import {ServerRoutes, getGenericJsonServer} from "./utils/index.js";
import {Api, ReqTypes, routesData, getReturnTypes, getReqSerializers} from "../routes/debug.js";
import {ServerRoutes, getGenericJsonServer} from "./utils/index.js";

export function getRoutes(config: IChainForkConfig, api: Api): ServerRoutes<Api, ReqTypes> {
const reqSerializers = getReqSerializers();
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/server/events.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {IChainForkConfig} from "@chainsafe/lodestar-config";
import {ServerRoutes} from "./utils/index.js";
import {Api, ReqTypes, routesData, getEventSerdes} from "../routes/events.js";
import {ServerRoutes} from "./utils/index.js";

export function getRoutes(config: IChainForkConfig, api: Api): ServerRoutes<Api, ReqTypes> {
const eventSerdes = getEventSerdes();
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/server/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {FastifyInstance} from "fastify";
import {IChainForkConfig} from "@chainsafe/lodestar-config";
// eslint-disable-next-line import/no-extraneous-dependencies
import {FastifyInstance} from "fastify";
import {Api} from "../interface.js";
import {ServerRoute} from "./utils/index.js";

Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/server/lightclient.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {IChainForkConfig} from "@chainsafe/lodestar-config";
import {serializeProof} from "@chainsafe/persistent-merkle-tree";
import {ServerRoutes, getGenericJsonServer} from "./utils/index.js";
import {Api, ReqTypes, routesData, getReturnTypes, getReqSerializers} from "../routes/lightclient.js";
import {ServerRoutes, getGenericJsonServer} from "./utils/index.js";

export function getRoutes(config: IChainForkConfig, api: Api): ServerRoutes<Api, ReqTypes> {
const reqSerializers = getReqSerializers();
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/server/lodestar.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {IChainForkConfig} from "@chainsafe/lodestar-config";
import {ServerRoutes, getGenericJsonServer} from "./utils/index.js";
import {Api, ReqTypes, routesData, getReturnTypes, getReqSerializers} from "../routes/lodestar.js";
import {ServerRoutes, getGenericJsonServer} from "./utils/index.js";

export function getRoutes(config: IChainForkConfig, api: Api): ServerRoutes<Api, ReqTypes> {
// All routes return JSON, use a server auto-generator
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/server/node.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {IChainForkConfig} from "@chainsafe/lodestar-config";
import {ServerRoutes, getGenericJsonServer} from "./utils/index.js";
import {Api, ReqTypes, routesData, getReturnTypes, getReqSerializers} from "../routes/node.js";
import {ServerRoutes, getGenericJsonServer} from "./utils/index.js";

export function getRoutes(config: IChainForkConfig, api: Api): ServerRoutes<Api, ReqTypes> {
// All routes return JSON, use a server auto-generator
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/server/utils/server.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as fastify from "fastify";
import {mapValues} from "@chainsafe/lodestar-utils";
// eslint-disable-next-line import/no-extraneous-dependencies
import * as fastify from "fastify";
import {IChainForkConfig} from "@chainsafe/lodestar-config";
import {ReqGeneric, RouteGeneric, ReturnTypes, TypeJson, Resolves, RouteGroupDefinition} from "../../utils/types.js";
import {getFastifySchema} from "../../utils/schema.js";
import {IChainForkConfig} from "@chainsafe/lodestar-config";

// See /packages/api/src/routes/index.ts for reasoning

Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/server/validator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {IChainForkConfig} from "@chainsafe/lodestar-config";
import {ServerRoutes, getGenericJsonServer} from "./utils/index.js";
import {Api, ReqTypes, routesData, getReturnTypes, getReqSerializers} from "../routes/validator.js";
import {ServerRoutes, getGenericJsonServer} from "./utils/index.js";

export function getRoutes(config: IChainForkConfig, api: Api): ServerRoutes<Api, ReqTypes> {
// All routes return JSON, use a server auto-generator
Expand Down
5 changes: 3 additions & 2 deletions packages/api/test/unit/client/httpClient.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {ErrorAborted, TimeoutError} from "@chainsafe/lodestar-utils";
import {IncomingMessage} from "node:http";
import chai, {expect} from "chai";
import chaiAsPromised from "chai-as-promised";
import fastify, {RouteOptions} from "fastify";
import {IncomingMessage} from "node:http";
import {ErrorAborted, TimeoutError} from "@chainsafe/lodestar-utils";
import {AbortController} from "@chainsafe/abort-controller";
import {HttpClient, HttpError} from "../../../src/client/utils/index.js";

chai.use(chaiAsPromised);
Expand Down
2 changes: 1 addition & 1 deletion packages/api/test/unit/config.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {expect} from "chai";
import {ssz} from "@chainsafe/lodestar-types";
import {chainConfigToJson} from "@chainsafe/lodestar-config";
import {config, chainConfig} from "@chainsafe/lodestar-config/default";
Expand All @@ -6,7 +7,6 @@ import {Api, ReqTypes, getReturnTypes} from "../../src/routes/config.js";
import {getClient} from "../../src/client/config.js";
import {getRoutes} from "../../src/server/config.js";
import {runGenericServerTest} from "../utils/genericServerTest.js";
import {expect} from "chai";

/* eslint-disable @typescript-eslint/naming-convention */

Expand Down
2 changes: 1 addition & 1 deletion packages/api/test/unit/debug.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {expect} from "chai";
import {ForkName} from "@chainsafe/lodestar-params";
import {ssz} from "@chainsafe/lodestar-types";
import {toHexString} from "@chainsafe/ssz";
Expand All @@ -8,7 +9,6 @@ import {getRoutes} from "../../src/server/debug.js";
import {runGenericServerTest} from "../utils/genericServerTest.js";
import {getMockApi, getTestServer} from "../utils/utils.js";
import {registerRoutesGroup} from "../../src/server/index.js";
import {expect} from "chai";
import {HttpClient} from "../../src/index.js";

describe("debug", function () {
Expand Down
3 changes: 2 additions & 1 deletion packages/api/test/unit/events.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {expect} from "chai";
import {AbortController} from "@chainsafe/abort-controller";
import {sleep} from "@chainsafe/lodestar-utils";
import {config} from "@chainsafe/lodestar-config/default";
import {Api, routesData, EventType, BeaconEvent} from "../../src/routes/events.js";
import {getClient} from "../../src/client/events.js";
import {getRoutes} from "../../src/server/events.js";
import {getMockApi, getTestServer} from "../utils/utils.js";
import {registerRoutesGroup} from "../../src/server/index.js";
import {expect} from "chai";

describe("events", () => {
const rootHex = "0x" + "01".repeat(32);
Expand Down
2 changes: 1 addition & 1 deletion packages/api/test/unit/lightclient.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {ssz} from "@chainsafe/lodestar-types";
import {config} from "@chainsafe/lodestar-config/default";
import {ProofType} from "@chainsafe/persistent-merkle-tree";
import {toHexString} from "@chainsafe/ssz";
import {Api, ReqTypes} from "../../src/routes/lightclient.js";
import {getClient} from "../../src/client/lightclient.js";
import {getRoutes} from "../../src/server/lightclient.js";
import {runGenericServerTest} from "../utils/genericServerTest.js";
import {toHexString} from "@chainsafe/ssz";

const root = Uint8Array.from(Buffer.alloc(32, 1));

Expand Down
2 changes: 1 addition & 1 deletion packages/api/test/utils/genericServerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {IChainForkConfig} from "@chainsafe/lodestar-config";
import {RouteGeneric, ReqGeneric, Resolves} from "../../src/utils/index.js";
import {FetchOpts, HttpClient, IHttpClient} from "../../src/client/utils/index.js";
import {ServerRoutes} from "../../src/server/utils/index.js";
import {getMockApi, getTestServer} from "./utils.js";
import {registerRoutesGroup} from "../../src/server/index.js";
import {getMockApi, getTestServer} from "./utils.js";

type IgnoreVoid<T> = T extends void ? undefined : T;

Expand Down
4 changes: 2 additions & 2 deletions packages/api/test/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fastify, {FastifyInstance} from "fastify";
import querystring from "querystring";
import {mapValues} from "@chainsafe/lodestar-utils";
import fastify, {FastifyInstance} from "fastify";
import Sinon from "sinon";
import {mapValues} from "@chainsafe/lodestar-utils";

export function getTestServer(): {baseUrl: string; server: FastifyInstance} {
const port = Math.floor(Math.random() * (65535 - 49152)) + 49152;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import xor from "buffer-xor";
import {digest} from "@chainsafe/as-sha256";
import {allForks} from "@chainsafe/lodestar-types";
import {EPOCHS_PER_HISTORICAL_VECTOR} from "@chainsafe/lodestar-params";
import {getRandaoMix} from "../../util/index.js";
import {verifyRandaoSignature} from "../signatureSets/index.js";
import {CachedBeaconStateAllForks} from "../../types.js";
import {EPOCHS_PER_HISTORICAL_VECTOR} from "@chainsafe/lodestar-params";

/**
* Commit a randao reveal to generate pseudorandomness seeds
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {allForks, phase0, ssz} from "@chainsafe/lodestar-types";
import {DOMAIN_BEACON_ATTESTER} from "@chainsafe/lodestar-params";
import {computeSigningRoot, computeStartSlotAtEpoch, ISignatureSet, SignatureSetType} from "../../util/index.js";
import {CachedBeaconStateAllForks} from "../../types.js";
import {DOMAIN_BEACON_ATTESTER} from "@chainsafe/lodestar-params";

/** Get signature sets from all AttesterSlashing objects in a block */
export function getAttesterSlashingsSignatureSets(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {allForks, altair} from "@chainsafe/lodestar-types";
import {computeEpochAtSlot, ISignatureSet} from "../../util/index.js";
import {CachedBeaconStateAllForks, CachedBeaconStateAltair} from "../../types.js";
import {getSyncCommitteeSignatureSet} from "../../altair/block/processSyncCommittee.js";
import {getProposerSlashingsSignatureSets} from "./proposerSlashings.js";
import {getAttesterSlashingsSignatureSets} from "./attesterSlashings.js";
import {getAttestationsSignatureSets} from "./indexedAttestation.js";
import {getProposerSignatureSet} from "./proposer.js";
import {getRandaoRevealSignatureSet} from "./randao.js";
import {getVoluntaryExitsSignatureSets} from "./voluntaryExits.js";
import {getSyncCommitteeSignatureSet} from "../../altair/block/processSyncCommittee.js";

export * from "./attesterSlashings.js";
export * from "./indexedAttestation.js";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import * as altair from "../altair/index.js";
import * as bellatrix from "../bellatrix/index.js";
import {IBeaconStateTransitionMetrics} from "../metrics.js";
import {EpochProcess, beforeProcessEpoch} from "../cache/epochProcess.js";
import {verifyProposerSignature} from "./signatureSets/index.js";
import {CachedBeaconStateAllForks, CachedBeaconStatePhase0, CachedBeaconStateAltair} from "../types.js";
import {processSlot} from "./slot/index.js";
import {computeEpochAtSlot} from "../util/index.js";
import {verifyProposerSignature} from "./signatureSets/index.js";
import {processSlot} from "./slot/index.js";

type StateAllForks = CachedBeaconStateAllForks;
type StatePhase0 = CachedBeaconStatePhase0;
Expand Down
Loading

0 comments on commit dfd4cdc

Please sign in to comment.