Skip to content

Commit

Permalink
chore: cleanup overrides for the biomejs configuration (#7162)
Browse files Browse the repository at this point in the history
* Clean overrides for unused variables

* Fix the naming conventions

* Add comments in the biome

* Fix code feedback
  • Loading branch information
nazarhussain authored Oct 16, 2024
1 parent cf72219 commit 245d63e
Show file tree
Hide file tree
Showing 16 changed files with 107 additions and 157 deletions.
188 changes: 64 additions & 124 deletions biome.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -71,54 +71,32 @@
"useNumberNamespace": "off",
// We prefer to auto-initialize enums
"useEnumInitializers": "off",
"noVar": "error",
"useConst": "error",
// Namespaces are deprecated way to organize modules in TS
"noNamespace": "error",
"useNamingConvention": {
"level": "error",
"options": {
"strictCase": false,
"requireAscii": true,
"conventions": [
// Skip __dirname and any variable starting with _, for rest check next convention
{
"selector": {
"kind": "any"
},
"formats": ["camelCase"]
},
{
"selector": {
"kind": "classProperty"
},
"formats": ["camelCase"]
},
{
"selector": {
"kind": "objectLiteralProperty"
},
"formats": ["camelCase"]
},
{
"selector": {
"kind": "classMethod"
},
"formats": ["camelCase"]
},
{
"selector": {
"kind": "functionParameter"
"kind": "variable"
},
"formats": ["camelCase"]
"match": "(?:__dirname)|(?:_.*)|(.*)"
},
{
"selector": {
"kind": "variable"
},
"formats": ["camelCase", "CONSTANT_CASE"]
"formats": ["camelCase", "PascalCase", "CONSTANT_CASE"]
},
{
"selector": {
"kind": "typeLike"
},
"formats": ["PascalCase"]
"formats": ["camelCase", "snake_case", "PascalCase", "CONSTANT_CASE"]
},
{
"selector": {
Expand All @@ -128,62 +106,62 @@
},
{
"selector": {
"kind": "enumMember"
"kind": "objectLiteralProperty"
},
"formats": ["PascalCase", "camelCase", "CONSTANT_CASE"]
"formats": ["camelCase", "snake_case", "PascalCase", "CONSTANT_CASE"]
},
{
"selector": {
"kind": "classProperty"
"kind": "objectLiteralMethod"
},
"formats": ["PascalCase", "camelCase", "CONSTANT_CASE"]
"formats": ["camelCase", "snake_case", "PascalCase", "CONSTANT_CASE"]
},
// Skip any property starting with _ and then check for next convention
{
"selector": {
"kind": "typeProperty"
"kind": "classProperty"
},
"formats": ["PascalCase", "camelCase", "CONSTANT_CASE"]
"match": "(?:_.*)|(.*)"
},
{
"selector": {
"kind": "classMember"
"kind": "classProperty"
},
"formats": ["PascalCase", "camelCase", "CONSTANT_CASE"]
"formats": ["camelCase", "snake_case", "PascalCase", "CONSTANT_CASE"]
},
{
"selector": {
"kind": "objectLiteralMethod"
"kind": "typeProperty"
},
"formats": ["PascalCase", "camelCase", "CONSTANT_CASE"]
"formats": ["camelCase", "snake_case", "PascalCase", "CONSTANT_CASE"]
},
{
"selector": {
"kind": "typeMethod"
},
"formats": ["PascalCase", "camelCase", "CONSTANT_CASE"]
"formats": ["camelCase", "snake_case", "PascalCase", "CONSTANT_CASE"]
},
{
"selector": {
"kind": "variable"
"kind": "enumMember"
},
"formats": ["PascalCase", "camelCase", "CONSTANT_CASE"]
"formats": ["camelCase", "snake_case", "PascalCase", "CONSTANT_CASE"]
},
{
"selector": {
"kind": "importAlias"
"kind": "indexParameter"
},
"formats": ["PascalCase", "camelCase"]
"formats": ["camelCase", "PascalCase"]
},
{
"selector": {
"kind": "importNamespace"
"kind": "function"
},
"formats": ["PascalCase", "camelCase"]
"formats": ["camelCase", "PascalCase"]
}
]
}
},
"noNamespace": "error"
}
},
"suspicious": {
// `void` as type is useful in our case when used as generic constraint e.g. K extends number | void
Expand Down Expand Up @@ -246,13 +224,7 @@
"globals": ["BigInt"]
},
"overrides": [
{
"include": ["packages/**/test/perf/**/*.test.ts", "packages/state-transition/test/utils/beforeValueMocha.ts"],
"javascript": {
// These are used by mocha
"globals": ["describe", "it", "before", "after"]
}
},
// Code using console output
{
"include": ["packages/cli/src/", "packages/test-utils/src", "packages/flare/src"],
"linter": {
Expand All @@ -263,89 +235,57 @@
}
}
},
// All test files
{
"include": [
"**/*.config.js",
"**/*.config.mjs",
"**/*.config.cjs",
"**/*.config.ts",
"scripts/vitest/**/*.ts",
"scripts/vite/**/*.ts",
"**/types/**/*.ts",
"packages/api/src/beacon/routes/*.ts",
"packages/api/src/**/routes.ts",
"packages/api/src/utils/server/handler.ts",
"packages/api/test/unit/client/urlFormat.test.ts",
"packages/beacon-node/src/api/impl/config/constants.ts",
"packages/beacon-node/src/eth1/provider/eth1Provider.ts",
""
],
"linter": {
"rules": {
"style": {
"useNamingConvention": {
"level": "off",
"options": {
"strictCase": false
}
}
}
}
}
},
{
"include": [
"**/test/**/*.ts",
"packages/*/test/**/*.js",
"packages/api/src/utils/**/*.ts",
"packages/beacon-node/src/db/repositories/checkpointState.ts",
"packages/spec-test-util/src/single.ts"
],
"linter": {
"rules": {
"suspicious": {
"noExplicitAny": "off"
}
}
}
},
{
"include": ["packages/beacon-node/test/e2e/eth1/jsonRpcHttpClient.test.ts"],
"linter": {
"rules": {
"correctness": {
"noUnusedVariables": "off"
}
}
}
},
{
"include": ["**/test/**/*.ts", "packages/*/test/**/*.js"],
"include": ["**/test/**/*.ts", "packages/spec-test-util/src"],
"linter": {
"rules": {
"complexity": {
// During tests we often need to use private/protected attributes, which is only possible with literal keys
"useLiteralKeys": "off"
},
"suspicious": {
// During tests it's quicker to define variables with `let` without specifying types
"noImplicitAnyLet": "off",
// During testing we use `any` type for quick assignments
"noExplicitAny": "off",
// Console logging is often used in tests
"noConsoleLog": "off"
}
}
}
},
// Dependencies still using mocha
{
"include": ["**/perf/**/*.ts"],
"linter": {
"rules": {}
"include": ["packages/**/test/perf/**/*.test.ts", "packages/state-transition/test/utils/beforeValueMocha.ts"],
"javascript": {
// These are used by mocha
"globals": ["describe", "it", "before", "after"]
}
},
{
"include": ["**/test/**/*.test.ts"],
"include": [
// These files are using mix cases e.g. `engine_newPayloadV4`
// It's a mix of snake_case and camelCase, which can't validated by biome
"packages/beacon-node/src/db/buckets.ts",
"packages/beacon-node/src/execution/engine/mock.ts",
"packages/beacon-node/src/execution/engine/types.ts",
"packages/beacon-node/src/eth1/provider/eth1Provider.ts",
"packages/validator/src/buckets.ts",
"packages/prover/src/types.ts",
"prover/src/utils/process.ts",
"prover/src/verified_requests/**/*.ts",
"packages/types/src/utils/**/*.ts",
// This file is using snake_case function names
"packages/beacon-node/test/spec/bls/bls.ts"
],
"linter": {
"rules": {
"complexity": {
// During tests we often need to use private/protected attributes, which is only possible with literal keys
"useLiteralKeys": "off"
},
"suspicious": {
// During tests it's quicker to define variables with `let` without specifying types
"noImplicitAnyLet": "off"
"style": {
"useNamingConvention": {
"level": "off",
"options": {}
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/utils/client/httpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ export class HttpClient implements IHttpClient {
this.logger?.debug("Requesting fallback URL", {routeId, baseUrl: printableUrl, score: this.urlsScore[i]});
}

// biome-ignore lint/style/useNamingConvention: Author preferred this format
const i_ = i; // Keep local copy of i variable to index urlScore after requestWithBody() resolves

const urlInit = this.urlsInits[i];
Expand Down
3 changes: 3 additions & 0 deletions packages/api/src/utils/codecs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ export type EmptyRequest = Record<never, never>;
export type EmptyResponseData = void;
export type EmptyMeta = void;

// biome-ignore lint/suspicious/noExplicitAny: We can not use `unknown` type here
export type AnyEndpoint = Endpoint<any, any, any, any, any>;
// biome-ignore lint/suspicious/noExplicitAny: We can not use `unknown` type here
export type EmptyRequestEndpoint = Endpoint<any, EmptyArgs, EmptyRequest, any, any>;
// biome-ignore lint/suspicious/noExplicitAny: We can not use `unknown` type here
export type EmptyResponseEndpoint = Endpoint<any, any, any, EmptyResponseData, EmptyMeta>;

/** Shortcut for routes that have no params, query */
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {WireFormat} from "./wireFormat.js";

export type HasOnlyOptionalProps<T> = {
[K in keyof T]-?: object extends Pick<T, K> ? never : K;
} extends {[_ in keyof T]: never}
} extends {[K2 in keyof T]: never}
? true
: false;

Expand Down
5 changes: 3 additions & 2 deletions packages/beacon-node/src/db/repositories/checkpointState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import {Bucket, getBucketNameByValue} from "../buckets.js";
export class CheckpointStateRepository extends Repository<Uint8Array, BeaconStateAllForks> {
constructor(config: ChainForkConfig, db: Db) {
// Pick some type but won't be used. Casted to any because no type can match `BeaconStateAllForks`
const type = ssz.phase0.BeaconState as any;
const type = ssz.phase0.BeaconState;
const bucket = Bucket.allForks_checkpointState;
super(config, db, bucket, type, getBucketNameByValue(bucket));
// biome-ignore lint/suspicious/noExplicitAny: The type is complex to specify a proper override
super(config, db, bucket, type as any, getBucketNameByValue(bucket));
}

getId(): Uint8Array {
Expand Down
1 change: 1 addition & 0 deletions packages/beacon-node/src/network/discv5/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {ENRKey} from "../metadata.js";
export enum ENRRelevance {
no_tcp = "no_tcp",
no_eth2 = "no_eth2",
// biome-ignore lint/style/useNamingConvention: Need to use the this name for network convention
unknown_forkDigest = "unknown_forkDigest",
relevant = "relevant",
}
Expand Down
4 changes: 4 additions & 0 deletions packages/beacon-node/src/util/kzg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ export function loadEthereumTrustedSetup(mode: TrustedFileMode = TrustedFileMode
}

export interface TrustedSetupJSON {
// biome-ignore lint/style/useNamingConvention: Need to be consistent with KZG pattern
setup_G1: string[];
// biome-ignore lint/style/useNamingConvention: Need to be consistent with KZG pattern
setup_G2: string[];
}

Expand Down Expand Up @@ -120,7 +122,9 @@ export function trustedSetupJsonToBin(data: TrustedSetupJSON): TrustedSetupBin {

export function trustedSetupBinToJson(bytes: TrustedSetupBin): TrustedSetupJSON {
const data: TrustedSetupJSON = {
// biome-ignore lint/style/useNamingConvention: Need to be consistent with KZG pattern
setup_G1: [],
// biome-ignore lint/style/useNamingConvention: Need to be consistent with KZG pattern
setup_G2: [],
};

Expand Down
Loading

0 comments on commit 245d63e

Please sign in to comment.