Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors for promise issues in eslint... #8796

Merged
merged 21 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 159 additions & 0 deletions .eslintrc-diff.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
const path = require('path');

/**
* Needed for the diff plugin. Note that if you change this variable you MUST
* invalidate the eslint cache.
*
* Now that this has to run over a BRANCH not a tag!
*
* To create a branch just run:
*
* git checkout -b my_branch {checksum_id}
* git push origin my_branch
*
*/
process.env.ESLINT_PLUGIN_DIFF_COMMIT = 'origin/MASTER_CIRCA_2024_08_07';

const ENABLE_ESLINT_DIFF_PLUGIN =
process.env.ENABLE_ESLINT_DIFF_PLUGIN || 'true';

module.exports = {
settings: {
react: {
version: 'detect',
},
},
plugins: ['@tanstack/query'],
parser: '@typescript-eslint/parser',
parserOptions: {
project: `./tsconfig.json`,
},
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/camelcase': 'off',
'@typescript-eslint/ban-types': 'off',
'import/extensions': 'off',
'import/no-unresolved': 'off',
'import/no-cycle': 'off',
'import/named': 'off',
'no-underscore-dangle': 0,
'no-console': 0,
camelcase: 0,
'no-else-return': 0,
'no-unused-vars': 0,
'no-unused-expressions': 0,
'class-methods-use-this': 0,
'import/newline-after-import': 0,
'import/no-named-default': 0,
'prefer-destructuring': 0,
'comma-dangle': 0,
'array-bracket-spacing': 0,
'no-plusplus': 0,
'consistent-return': 0,
'object-curly-newline': 0,
'nonblock-statement-body-position': 0,
'no-extraneous-dependencies': 0,
curly: 0,
'no-nested-ternary': 0,
'import/first': 0,
'import/no-extraneous-dependencies': 0,
'arrow-body-style': 0,
'key-spacing': 0,
'quote-props': 0,
'no-alert': 0,
'no-undef': 0,
'no-confusing-arrow': 0,
'one-var-declaration-per-line': 0,
'one-var': 0,
'lines-between-class-members': 0,
'max-classes-per-file': ['error', 5],
'max-len': [
1,
{
code: 120,
tabWidth: 2,
},
],
'no-constant-condition': [
'error',
{
checkLoops: false,
},
],
'no-restricted-syntax': 0,
'no-trailing-spaces': ['error'],
'no-useless-constructor': 0,
'no-empty-function': 0,
'import/prefer-default-export': 0,
'dot-notation': 0,
'no-lonely-if': 0,
'no-multi-spaces': 0,
'no-await-in-loop': 0,
'no-async-promise-executor': 0,
'no-shadow': 'off',
'@typescript-eslint/no-shadow': 'error',
'@typescript-eslint/explicit-module-boundary-types': 0,
'prettier/prettier': 0,
'@typescript-eslint/no-empty-interface': [
'error',
{
allowSingleExtends: true,
},
],
'@tanstack/query/exhaustive-deps': 'error',
'@tanstack/query/prefer-query-object-syntax': 'error',
'@tanstack/query/no-deprecated-options': 1,
'react/destructuring-assignment': [1, 'always'],
'react/function-component-definition': [
1,
{ namedComponents: 'arrow-function' },
],
'react/no-multi-comp': [1, { ignoreStateless: false }],
'react/jsx-curly-brace-presence': [
'error',
{ props: 'never', children: 'never' },
],
'@typescript-eslint/no-unused-vars': 1,
'react/jsx-key': 'error',

'@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/require-await': 'error',
'@typescript-eslint/no-misused-promises': 'error',
'@typescript-eslint/await-thenable': 'error',

'no-warning-comments': [
'error',
{ terms: ['FIXME', 'eslint-disable '], location: 'anywhere' },
],

// ** 'any' issues...
// '@typescript-eslint/no-explicit-any': 'error',
// '@typescript-eslint/no-unsafe-argument': 'error',
// '@typescript-eslint/no-unsafe-assignment': 'error',
// '@typescript-eslint/no-unsafe-call': 'error',
// '@typescript-eslint/no-unsafe-member-access': 'error',
// '@typescript-eslint/no-unsafe-return': 'error',

// ** type immutability
'no-param-reassign': 'error',
'no-var': 'error',
// "prefer-const": "error",
// "@typescript-eslint/prefer-readonly": "error",
// "@typescript-eslint/prefer-readonly-parameter-types": "error",
//
// // https://www.npmjs.com/package/eslint-plugin-functional
// "functional/immutable-data": "error",
// "functional/no-let": "error",
// "functional/no-method-signature": "error",
// "functional/prefer-readonly-type": "error"
},
ignorePatterns: ['server/scripts/setupPrerenderService.ts'],
extends: [
'eslint:recommended',
'plugin:@tanstack/eslint-plugin-query/recommended',
'plugin:react-hooks/recommended',
'plugin:react/recommended',
'plugin:@typescript-eslint/recommended',
ENABLE_ESLINT_DIFF_PLUGIN !== 'false' ? 'plugin:diff/diff' : null,
].filter((current) => current !== null),
};
5 changes: 4 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ jobs:

# To disable eslint-diff just comment the following two lines
- name: Run eslint-diff
run: pnpm -F commonwealth run lint-diff
run: pnpm -r run lint-diff
burtonator marked this conversation as resolved.
Show resolved Hide resolved

- name: Run eslint-diff-canary to make sure eslint-diff is functioning properly
run: pnpm -F commonwealth run lint-diff-canary
Expand Down Expand Up @@ -304,6 +304,9 @@ jobs:
- name: Build
run: pnpm -r build

- name: build
run: pnpm -r lint

- name: Run unit tests
run: pnpm -r test -- --allowOnly=false

Expand Down
4 changes: 3 additions & 1 deletion libs/adapters/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
"build": "tsc -b tsconfig.build.json",
"clean": "rm -rf build && rm -rf coverage && find . -type f -name '*.tsbuildinfo' -exec rm {} +",
"check-types": "tsc --noEmit",
"test": "NODE_ENV=test vitest --config ../../vite.config.ts --coverage run test"
"test": "NODE_ENV=test vitest --config ../../vite.config.ts --coverage run test",
"lint": "NODE_OPTIONS=\"--max-old-space-size=4096\" eslint -c ../../.eslintrc.cjs './src/**/*.{ts,tsx}'",
"lint-diff": "NODE_OPTIONS=\"--max-old-space-size=4096\" eslint -c ../../.eslintrc-diff.cjs './src/**/*.{ts,tsx}'"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.577.0",
Expand Down
4 changes: 3 additions & 1 deletion libs/adapters/src/daemon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ export class Activity<T extends (...args: any[]) => any> {
) as unknown as T;
}

// eslint-disable-next-line @typescript-eslint/require-await
async startTask(...args: any) {
try {
const jobId = daemon.startTask(
this.label,
// eslint-disable-next-line @typescript-eslint/no-misused-promises
async () => await this.queryWithCacheOverride(...args),
this.cacheDuration,
);
Expand All @@ -59,7 +61,7 @@ export class Daemons {
// don't accept to run jobs more often than 1 minute
if (timeoutMs < 60 * 1000) return;

const jobId = setInterval(async () => {
const jobId = setInterval(() => {
try {
log.info(`Running task ${label}`);
fn();
Expand Down
2 changes: 1 addition & 1 deletion libs/adapters/src/rabbitmq/RabbitMQAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ export class RabbitMQAdapter implements Broker {
this._log,
);
})
.finally(async () => {
.finally(() => {
try {
afterHandleEvent?.(topic, content, context);
} catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion libs/adapters/src/redis/RedisCacheAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class RedisCache implements Cache {
* @returns
*/
public ready(retries = 3, retryDelay = 1000) {
// eslint-disable-next-line no-async-promise-executor
// eslint-disable-next-line no-async-promise-executor, @typescript-eslint/no-misused-promises
return new Promise<boolean>(async (resolve, reject) => {
for (let i = 0; i < retries; i++) {
if (this.isReady()) {
Expand Down
1 change: 1 addition & 0 deletions libs/adapters/src/redis/RedisCacheDecorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ export class CacheDecorator {
) => string | CacheKeyDuration | null = defaultKeyGenerator,
namespace: CacheNamespaces = CacheNamespaces.Route_Response,
): RequestHandler {
// eslint-disable-next-line @typescript-eslint/no-misused-promises
return async function cache(
this: CacheDecorator,
req: Request,
Expand Down
1 change: 1 addition & 0 deletions libs/adapters/src/utils/cacheJobRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export abstract class JobRunner<CacheT> {
public start() {
if (this._jobTimeS > 0) {
this._timeoutHandle = global.setInterval(
// eslint-disable-next-line @typescript-eslint/no-misused-promises
() => this.run(),
this._jobTimeS * 1000,
);
Expand Down
3 changes: 3 additions & 0 deletions libs/adapters/src/utils/startHealthCheckLoop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ export function startHealthCheckLoop({
stats().off(key);
}
const durationUntilNextCheck = nextCheckAt - Date.now();
// eslint-disable-next-line @typescript-eslint/no-misused-promises
setTimeout(loop, durationUntilNextCheck);
};

// eslint-disable-next-line @typescript-eslint/no-misused-promises
setTimeout(loop, PING_INTERVAL);
}
3 changes: 2 additions & 1 deletion libs/chains/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"build": "tsc -b tsconfig.build.json",
"clean": "rm -rf build && rm -rf coverage && find . -type f -name '*.tsbuildinfo' -exec rm {} +",
"check-types": "tsc --noEmit",
"test": "NODE_ENV=test vitest --config ../../vite.config.ts --coverage run test"
"test": "NODE_ENV=test vitest --config ../../vite.config.ts --coverage run test",
"lint-diff": "NODE_OPTIONS=\"--max-old-space-size=4096\" eslint -c ../../.eslintrc-diff.cjs './src/**/*.{ts,tsx}'"
},
"dependencies": {
"@cosmjs/amino": "^0.31.3",
Expand Down
4 changes: 3 additions & 1 deletion libs/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
"build": "tsc -b ./tsconfig.build.json",
"clean": "rm -rf build && rm -rf coverage && find . -type f -name '*.tsbuildinfo' -exec rm {} +",
"check-types": "tsc --noEmit",
"test": "NODE_ENV=test vitest --config ../../vite.config.ts --coverage run test"
"test": "NODE_ENV=test vitest --config ../../vite.config.ts --coverage run test",
"lint": "NODE_OPTIONS=\"--max-old-space-size=4096\" eslint -c ../../.eslintrc.cjs './src/**/*.{ts,tsx}'",
"lint-diff": "NODE_OPTIONS=\"--max-old-space-size=4096\" eslint -c ../../.eslintrc-diff.cjs './src/**/*.{ts,tsx}'"
},
"dependencies": {
"@hicommonwealth/schemas": "workspace:*",
Expand Down
5 changes: 5 additions & 0 deletions libs/core/src/ports/port.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const disposeAndExit = async (
};

export const disposeAdapter = (name: string): void => {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
adapters.get(name)?.dispose();
adapters.delete(name);
adapters.clear();
Expand All @@ -99,18 +100,22 @@ export const dispose = (disposer?: Disposer): typeof disposeAndExit => {
/**
* Handlers to dispose registered resources on exit or unhandled exceptions
*/
// eslint-disable-next-line @typescript-eslint/no-misused-promises
process.once('SIGINT', async (arg?: any) => {
log.info(`SIGINT ${arg !== 'SIGINT' ? arg : ''}`);
await disposeAndExit('EXIT');
});
// eslint-disable-next-line @typescript-eslint/no-misused-promises
process.once('SIGTERM', async (arg?: any) => {
log.info(`SIGTERM ${arg !== 'SIGTERM' ? arg : ''}`);
await disposeAndExit('EXIT');
});
// eslint-disable-next-line @typescript-eslint/no-misused-promises
process.once('uncaughtException', async (arg?: any) => {
log.error('Uncaught Exception', arg);
await disposeAndExit('ERROR');
});
// eslint-disable-next-line @typescript-eslint/no-misused-promises
process.once('unhandledRejection', async (arg?: any) => {
log.error('Unhandled Rejection', arg);
await disposeAndExit('ERROR');
Expand Down
4 changes: 3 additions & 1 deletion libs/evm-testing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
"clean": "rm -rf build && rm -rf coverage && find . -type f -name '*.tsbuildinfo' -exec rm {} +",
"check-types": "tsc --noEmit",
"test": "echo No tests to run",
"start": "tsx src/server.ts"
"start": "tsx src/server.ts",
"lint": "NODE_OPTIONS=\"--max-old-space-size=4096\" eslint -c ../../.eslintrc.cjs './src/**/*.{ts,tsx}'",
"lint-diff": "NODE_OPTIONS=\"--max-old-space-size=4096\" eslint -c ../../.eslintrc-diff.cjs './src/**/*.{ts,tsx}'"
},
"author": "",
"license": "ISC",
Expand Down
4 changes: 3 additions & 1 deletion libs/model/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
"clean": "rm -rf build && rm -rf coverage && find . -type f -name '*.tsbuildinfo' -exec rm {} +",
"check-types": "tsc --noEmit",
"test": "INIT_TEST_DB=true NODE_ENV=test vitest --config ../../vite.config.ts --fileParallelism=false --coverage run test",
"test-select": "INIT_TEST_DB=true NODE_ENV=test vitest --config ../../vite.config.ts --fileParallelism=false run"
"test-select": "INIT_TEST_DB=true NODE_ENV=test vitest --config ../../vite.config.ts --fileParallelism=false run",
"lint": "NODE_OPTIONS=\"--max-old-space-size=4096\" eslint -c ../../.eslintrc.cjs './src/**/*.{ts,tsx}'",
"lint-diff": "NODE_OPTIONS=\"--max-old-space-size=4096\" eslint -c ../../.eslintrc-diff.cjs './src/**/*.{ts,tsx}'"
},
"dependencies": {
"@anatine/zod-mock": "^3.13.3",
Expand Down
4 changes: 3 additions & 1 deletion libs/model/src/chain-events/ChainEventCreated.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function anyAddressEqual(
return false;
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function verifyAlchemySignature(req: any) {
const signature = req.headers['x-alchemy-signature'];
let hmac: Hmac | undefined;
Expand Down Expand Up @@ -87,7 +88,7 @@ export function ChainEventCreated(): Command<typeof schemas.ChainEventCreated> {
return {
...schemas.ChainEventCreated,
auth: [],
// eslint-disable-next-line @typescript-eslint/no-unused-vars
// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/require-await
body: async ({ payload }) => {
// The name of the chain e.g. BaseSepolia (ex webhook url: /v1/rest/chainevent/ChainEventCreated/BaseSepolia)
// let chain = id!;
Expand Down Expand Up @@ -125,6 +126,7 @@ export function ChainEventCreated(): Command<typeof schemas.ChainEventCreated> {
} else if (
// Contests
Object.values(EvmEventSignatures.Contests).includes(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
eventSignature as any,
)
) {
Expand Down
2 changes: 2 additions & 0 deletions libs/model/src/contest/Contests.projection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ export function Contests(): Projection<typeof inputs> {
thread_id: add_action!.thread_id,
created_at: new Date(),
});

// eslint-disable-next-line @typescript-eslint/no-misused-promises
setImmediate(() => updateScore(payload.contest_address, contest_id));
burtonator marked this conversation as resolved.
Show resolved Hide resolved
},
},
Expand Down
1 change: 1 addition & 0 deletions libs/model/src/globalActivityCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export class GlobalActivityCache {

public async start() {
await this.refreshGlobalActivity();
// eslint-disable-next-line @typescript-eslint/no-misused-promises
setInterval(this.refreshGlobalActivity.bind(this), this._cacheTTL * 1000);
}

Expand Down
Loading
Loading