Skip to content

Commit

Permalink
chore: eslint version update and minor refactor (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
csabbee authored Dec 16, 2024
1 parent 63a677b commit 85cbf29
Show file tree
Hide file tree
Showing 761 changed files with 5,136 additions and 4,246 deletions.
39 changes: 0 additions & 39 deletions .eslintrc.js

This file was deleted.

82 changes: 82 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { fixupConfigRules, fixupPluginRules } from '@eslint/compat';
import react from 'eslint-plugin-react';
import typescriptEslint from '@typescript-eslint/eslint-plugin';
import globals from 'globals';
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 [
...fixupConfigRules(
compat.extends(
'eslint:recommended',
'plugin:react/recommended',
'plugin:react/jsx-runtime',
'plugin:react-hooks/recommended',
'plugin:@typescript-eslint/recommended',
'prettier',
'plugin:prettier/recommended',
),
),
{
plugins: {
react: fixupPluginRules(react),
'@typescript-eslint': fixupPluginRules(typescriptEslint),
},

languageOptions: {
globals: {
...globals.browser,
...globals.node,
},

parser: tsParser,
ecmaVersion: 12,
sourceType: 'module',

parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
},

settings: {
react: {
pragma: 'React',
version: 'detect',
},
},

rules: {
'@typescript-eslint/explicit-module-boundary-types': 'off',
'react/prop-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-var-requires': 'off',
'no-shadow': 'off',
'@typescript-eslint/no-shadow': 'error',
'@typescript-eslint/no-unused-vars': [
'error',
{
args: 'all',
argsIgnorePattern: '^_',
caughtErrors: 'all',
caughtErrorsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_',
varsIgnorePattern: '^_',
ignoreRestSiblings: true,
},
],
},
},
];
22 changes: 13 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"build": "yarn run build:inpage --mode=production && webpack --config webpack.prod.js",
"build:alpha": "yarn run build:inpage --mode=production && webpack --config webpack.alpha.js",
"dev": "yarn run build:inpage && webpack -w --config webpack.dev.js",
"lint": "eslint --fix -c ./.eslintrc.js \"src/**/*.ts*\"",
"lint": "eslint --fix \"src/**/*.ts*\"",
"typecheck": "yarn tsc --skipLibCheck --noEmit",
"postinstall": "husky install && patch-package",
"prettify": "prettier --write \"src/**/*.ts*\"",
Expand Down Expand Up @@ -117,6 +117,9 @@
"@commitlint/cli": "17.0.3",
"@commitlint/config-angular": "17.0.3",
"@commitlint/config-conventional": "17.0.3",
"@eslint/compat": "1.2.4",
"@eslint/eslintrc": "3.2.0",
"@eslint/js": "9.16.0",
"@google/semantic-release-replace-plugin": "1.1.0",
"@lavamoat/allow-scripts": "2.0.0",
"@lavamoat/preinstall-always-fail": "1.0.0",
Expand Down Expand Up @@ -145,8 +148,8 @@
"@types/styled-components": "5.1.21",
"@types/web3": "1.2.2",
"@types/webextension-polyfill": "0.10.0",
"@typescript-eslint/eslint-plugin": "6.11.0",
"@typescript-eslint/parser": "6.11.0",
"@typescript-eslint/eslint-plugin": "8.17.0",
"@typescript-eslint/parser": "8.17.0",
"@walletconnect/types": "2.9.1",
"babel-jest": "29.7.0",
"babel-loader": "9.1.3",
Expand All @@ -157,13 +160,14 @@
"copy-webpack-plugin": "10.2.1",
"css-loader": "5.2.4",
"dotenv-webpack": "7.0.3",
"eslint": "8.7.0",
"eslint-config-prettier": "8.3.0",
"eslint-plugin-prettier": "4.0.0",
"eslint-plugin-react": "7.28.0",
"eslint-plugin-react-hooks": "4.3.0",
"eslint": "9.15.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-prettier": "5.2.1",
"eslint-plugin-react": "7.37.2",
"eslint-plugin-react-hooks": "5.1.0",
"file-loader": "6.2.0",
"fs": "0.0.1-security",
"globals": "15.13.0",
"husky": "7.0.4",
"i18next-scanner": "4.1.1",
"i18next-scanner-typescript": "1.1.1",
Expand All @@ -175,7 +179,7 @@
"patch-package": "8.0.0",
"path-browserify": "1.0.1",
"postinstall-postinstall": "2.1.0",
"prettier": "2.5.1",
"prettier": "3.4.2",
"react-docgen-typescript-loader": "3.7.2",
"react-docgen-typescript-webpack-plugin": "1.1.0",
"react-scripts": "5.0.1",
Expand Down
4 changes: 2 additions & 2 deletions src/background/connections/RequestProcessorPipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ export function RequestProcessorPipeline<RequestType, ResponseType>(
(error) => {
// error from the middleware, halt execution
reject(error);
}
},
);
} else {
// no more middlewares, execution finished
resolve(context);
}
};
runner(0);
}
},
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class DAppConnectionController implements ConnectionController {
private accountsService: AccountsService,
private networkService: NetworkService,
private lockService: LockService,
private moduleManager: ModuleManager
private moduleManager: ModuleManager,
) {
this.onRequest = this.onRequest.bind(this);
this.disconnect = this.disconnect.bind(this);
Expand All @@ -78,11 +78,11 @@ export class DAppConnectionController implements ConnectionController {
PermissionMiddleware(
this.permissionsService,
this.accountsService,
this.lockService
this.lockService,
),
ActiveNetworkMiddleware(this.networkService),
DAppRequestHandlerMiddleware(this.handlers, this.moduleManager),
LoggerMiddleware(SideToLog.RESPONSE)
LoggerMiddleware(SideToLog.RESPONSE),
);

connectionLog('dApp Provider');
Expand All @@ -103,13 +103,13 @@ export class DAppConnectionController implements ConnectionController {
disconnect() {
this.connection?.dispose();
this.eventEmitters.forEach((emitter) =>
emitter.removeListener(this.onEvent)
emitter.removeListener(this.onEvent),
);
disconnectLog('dApp Provider');
}

needToPost(
context: Context<JsonRpcRequest, JsonRpcSuccess<unknown> | JsonRpcFailure>
context: Context<JsonRpcRequest, JsonRpcSuccess<unknown> | JsonRpcFailure>,
): boolean {
return context.response !== DEFERRED_RESPONSE;
}
Expand All @@ -126,7 +126,7 @@ export class DAppConnectionController implements ConnectionController {
request: {
...request,
},
})
}),
);

if (error) {
Expand Down Expand Up @@ -156,7 +156,7 @@ export class DAppConnectionController implements ConnectionController {
} catch (e) {
sentryCaptureException(
e as Error,
SentryExceptionTypes.DAPP_CONNECTION_EVENT
SentryExceptionTypes.DAPP_CONNECTION_EVENT,
);
console.error(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ export interface DAppRequestHandler {
result: any,
onSuccess: (result: unknown) => Promise<void>,
onError: (error: Error) => Promise<void>,
tabId?: number
tabId?: number,
) => Promise<void>;
}

export abstract class DAppRequestHandler<
RequestParams = unknown,
ResponseParams = any
ResponseParams = any,
> {
abstract methods: DAppProviderRequest[];

abstract handleAuthenticated: (
rpcCall: JsonRpcRequestParams<DAppProviderRequest, RequestParams>
rpcCall: JsonRpcRequestParams<DAppProviderRequest, RequestParams>,
) => Promise<JsonRpcResponse<ResponseParams>>;

abstract handleUnauthenticated: (
rpcCall: JsonRpcRequestParams<DAppProviderRequest, RequestParams>
rpcCall: JsonRpcRequestParams<DAppProviderRequest, RequestParams>,
) => Promise<JsonRpcResponse<ResponseParams>>;
}
4 changes: 2 additions & 2 deletions src/background/connections/dAppConnection/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export interface JsonRpcRequestParams<Method extends string, Params = unknown> {

export type JsonRpcRequestPayload<
Method extends string = any,
Params = unknown
Params = unknown,
> = Params extends undefined
? JsonRpcRequestPayloadWithoutParams<Method>
: JsonRpcRequestPayloadWithParams<Method, Params>;
Expand All @@ -86,7 +86,7 @@ interface JsonRpcRequestPayloadBase<Method extends string = any> {

interface JsonRpcRequestPayloadWithParams<
Method extends string = any,
Params = unknown
Params = unknown,
> extends JsonRpcRequestPayloadBase<Method> {
readonly params: Params;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('src/background/connections/extensionConnection/DappHandlerToExtensionH
expect(await transformedHandler!.handle(buildRpcCall(request))).toEqual(
expect.objectContaining({
error: 'No request ID provided',
})
}),
);
});

Expand All @@ -87,7 +87,7 @@ describe('src/background/connections/extensionConnection/DappHandlerToExtensionH
expect(await transformedHandler!.handle(buildRpcCall(request))).toEqual(
expect.objectContaining({
error,
})
}),
);
});

Expand All @@ -109,7 +109,7 @@ describe('src/background/connections/extensionConnection/DappHandlerToExtensionH
expect(await transformedHandler!.handle(buildRpcCall(request))).toEqual(
expect.objectContaining({
error,
})
}),
);
});

Expand Down Expand Up @@ -144,7 +144,7 @@ describe('src/background/connections/extensionConnection/DappHandlerToExtensionH
name: browser.runtime.getManifest().name,
},
},
})
}),
);
});

Expand All @@ -166,7 +166,7 @@ describe('src/background/connections/extensionConnection/DappHandlerToExtensionH
expect(await transformedHandler!.handle(buildRpcCall(request))).toEqual(
expect.objectContaining({
result,
})
}),
);
});

Expand Down Expand Up @@ -204,7 +204,7 @@ describe('src/background/connections/extensionConnection/DappHandlerToExtensionH
expect(await transformedHandler!.handle(buildRpcCall(request))).toEqual(
expect.objectContaining({
result: DEFERRED_RESPONSE,
})
}),
);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { DAppRequestHandler } from '../dAppConnection/DAppRequestHandler';
import { ExtensionRequestHandler } from '../models';

const decorateWithExtensionMetadata = (
rpcCall: JsonRpcRequestParams<DAppProviderRequest, any>
rpcCall: JsonRpcRequestParams<DAppProviderRequest, any>,
): JsonRpcRequestParams<DAppProviderRequest, any> => ({
...rpcCall,
request: {
Expand All @@ -27,14 +27,14 @@ const decorateWithExtensionMetadata = (

export class DappHandlerToExtensionHandlerTransformer {
transform(
handlers: DAppRequestHandler<any, any>[]
handlers: DAppRequestHandler<any, any>[],
): ExtensionRequestHandler<any, any, any>[] {
return handlers.flatMap((handler) => {
return handler.methods.map<ExtensionRequestHandler<any, any, any>>(
(method) => ({
method,
handle: async (
rpcCall: JsonRpcRequestParams<DAppProviderRequest, any>
rpcCall: JsonRpcRequestParams<DAppProviderRequest, any>,
) => {
const extRequest = decorateWithExtensionMetadata(rpcCall);

Expand All @@ -46,7 +46,7 @@ export class DappHandlerToExtensionHandlerTransformer {
}

const [result, error] = await resolve(
handler.handleAuthenticated(extRequest) // Extension is always authenticated
handler.handleAuthenticated(extRequest), // Extension is always authenticated
);

if (error || 'error' in result) {
Expand All @@ -61,7 +61,7 @@ export class DappHandlerToExtensionHandlerTransformer {
result: result.result,
};
},
})
}),
);
});
}
Expand Down
Loading

0 comments on commit 85cbf29

Please sign in to comment.