Skip to content

Commit

Permalink
fix: linter and some code refactors (#66)
Browse files Browse the repository at this point in the history
* chore: remove unnecessary awaits

* fix: linter

* chore: add pre-push linter hook
  • Loading branch information
mkykadir authored Sep 27, 2023
1 parent 238e465 commit cdd0bc4
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 11 deletions.
7 changes: 6 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@ cache/
dist/
node_modules
src/resolvers/fails
.tmp
.tmp
jest.config.ts
__test__
src/web3-functions
polyfill
src/lib/deno.d.ts
4 changes: 4 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn lint && yarn build
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"hardhat": "^2.13.0",
"husky": "^8.0.3",
"jest": "^29.5.0",
"prettier": "^2.3.2",
"ts-jest": "^29.1.0",
Expand Down
1 change: 1 addition & 0 deletions src/hardhat/provider/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export class EthersProviderWrapper extends StaticJsonRpcProvider {
this._hardhatProvider = hardhatProvider;
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
public async send(method: string, params: any): Promise<any> {
const result = await this._hardhatProvider.send(method, params);

Expand Down
4 changes: 2 additions & 2 deletions src/lib/binaries/benchmark.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { StaticJsonRpcProvider } from "@ethersproject/providers";
import colors from "colors/safe";
import "dotenv/config";
import { StaticJsonRpcProvider } from "@ethersproject/providers";
import path from "path";
import { performance } from "perf_hooks";

Expand Down Expand Up @@ -72,7 +72,7 @@ export default async function benchmark() {
const parsedPathParts = path.parse(web3FunctionPath).dir.split(path.sep);
const w3fName = parsedPathParts.pop() ?? "";
const w3fRootDir = parsedPathParts.join(path.sep);
const w3fDetails = await Web3FunctionLoader.load(w3fName, w3fRootDir);
const w3fDetails = Web3FunctionLoader.load(w3fName, w3fRootDir);
const userArgs = w3fDetails.userArgs;
const secrets = w3fDetails.secrets;
const storage = w3fDetails.storage;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/binaries/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import colors from "colors/safe";
import { StaticJsonRpcProvider } from "@ethersproject/providers";
import colors from "colors/safe";
import path from "path";
import { Web3FunctionBuilder } from "../builder";
import { Web3FunctionLoader } from "../loader";
Expand Down Expand Up @@ -83,7 +83,7 @@ export default async function test(callConfig?: Partial<CallConfig>) {
const parsedPathParts = path.parse(web3FunctionPath).dir.split(path.sep);
const w3fName = parsedPathParts.pop() ?? "";
const w3fRootDir = parsedPathParts.join(path.sep);
const w3fDetails = await Web3FunctionLoader.load(w3fName, w3fRootDir);
const w3fDetails = Web3FunctionLoader.load(w3fName, w3fRootDir);
userArgs = w3fDetails.userArgs;
secrets = w3fDetails.secrets;
storage = w3fDetails.storage;
Expand Down
6 changes: 2 additions & 4 deletions src/lib/net/Web3FunctionHttpProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import http, { IncomingMessage, Server, ServerResponse } from "http";
import net from "net";
import { Duplex } from "stream";

type BlacklistedHandler = (url: URL) => boolean;

interface Web3FunctionHttpProxyStats {
nbRequests: number;
nbThrottled: number;
Expand All @@ -13,7 +11,7 @@ interface Web3FunctionHttpProxyStats {

export class Web3FunctionHttpProxy {
private _debug: boolean;
private _isStopped: boolean = true;
private _isStopped = true;

private readonly _maxDownload: number;
private readonly _maxUpload: number;
Expand Down Expand Up @@ -195,7 +193,7 @@ export class Web3FunctionHttpProxy {
if (this._debug) console.log(`Web3FunctionHttpProxy: ${message}`);
}

public start(port: number = 3000) {
public start(port = 3000) {
this._server
.listen(port, () => {
this._log(`Started listening on ${port}`);
Expand Down
4 changes: 3 additions & 1 deletion src/lib/net/Web3FunctionHttpServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ export class Web3FunctionHttpServer {

for await (const conn of conns) {
// eslint-disable-next-line @typescript-eslint/no-empty-function
let connectionReleaseResolver = () => {};
let connectionReleaseResolver = () => {
// Intentionally left empty to use as variable
};
this._waitConnectionReleased = new Promise((resolve) => {
connectionReleaseResolver = () => {
resolve();
Expand Down
2 changes: 1 addition & 1 deletion src/web3-functions/fails/escape-file/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
} from "@gelatonetwork/web3-functions-sdk";

Web3Function.onRun(async (context: Web3FunctionContext) => {
const conf = await Deno.readTextFile("./.env");
const conf = Deno.readTextFile("./.env");
console.log(conf);
return { canExec: false, message: "Sandbox escaped file system" };
});
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3341,6 +3341,11 @@ human-signals@^2.1.0:
resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-2.1.0.tgz#dc91fcba42e4d06e4abaed33b3e7a3c02f514ea0"
integrity sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==

husky@^8.0.3:
version "8.0.3"
resolved "https://registry.yarnpkg.com/husky/-/husky-8.0.3.tgz#4936d7212e46d1dea28fef29bb3a108872cd9184"
integrity sha512-+dQSyqPh4x1hlO1swXBiNb2HzTDN1I2IGLQx1GrBuiqFJfoMrnZWwVmatvSiO+Iz8fBUnf+lekwNo4c2LlXItg==

[email protected]:
version "0.4.24"
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b"
Expand Down

0 comments on commit cdd0bc4

Please sign in to comment.