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

chore(dependencies): update eslint 8->9 #296

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
45 changes: 0 additions & 45 deletions .eslintrc

This file was deleted.

84 changes: 84 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import typescriptEslint from '@typescript-eslint/eslint-plugin';
import header from 'eslint-plugin-header';
import jestFormatting from 'eslint-plugin-jest-formatting';
import prettier from 'eslint-plugin-prettier';
import unicorn from 'eslint-plugin-unicorn';
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);

// workaround: https://github.com/Stuk/eslint-plugin-header/issues/57#issuecomment-2378485611
header.rules.header.meta.schema = false;
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
});

export default [
...compat.extends(
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'prettier',
),
{
plugins: {
'@typescript-eslint': typescriptEslint,
header,
'jest-formatting': jestFormatting,
prettier,
unicorn,
},

languageOptions: {
parser: tsParser,
ecmaVersion: 5,
sourceType: 'script',

parserOptions: {
project: 'tsconfig.json',
},
},
Comment on lines +39 to +47
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Update language options for modern TypeScript.

The current configuration might be too restrictive:

  • ecmaVersion: 5 is outdated for a TypeScript project
  • sourceType: 'script' could cause issues with ES modules

Apply this diff to align with modern TypeScript practices:

    languageOptions: {
      parser: tsParser,
-     ecmaVersion: 5,
-     sourceType: 'script',
+     ecmaVersion: 2022,
+     sourceType: 'module',

      parserOptions: {
        project: 'tsconfig.json',
      },
    },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
languageOptions: {
parser: tsParser,
ecmaVersion: 5,
sourceType: 'script',
parserOptions: {
project: 'tsconfig.json',
},
},
languageOptions: {
parser: tsParser,
ecmaVersion: 2022,
sourceType: 'module',
parserOptions: {
project: 'tsconfig.json',
},
},


rules: {
'@typescript-eslint/no-explicit-any': ['off'],
'@typescript-eslint/no-unused-vars': ['off'],

'@typescript-eslint/strict-boolean-expressions': [
2,
{
allowNullableObject: true,
allowNullableBoolean: true,
allowAny: true,
},
],

eqeqeq: ['error', 'smart'],
'jest-formatting/padding-around-describe-blocks': 2,
'jest-formatting/padding-around-test-blocks': 2,
'header/header': [2, './resources/license.header.js'],
'mocha/max-top-level-suites': 'off',
'mocha/no-exports': 'off',
'mocha/no-mocha-arrows': 'off',
'no-console': 0,
'no-return-await': 2,
'no-unneeded-ternary': 2,
'no-unused-vars': 'off',

'prettier/prettier': [
'error',
{
endOfLine: 'auto',
},
],

'unicorn/prefer-node-protocol': 2,
},
Comment on lines +49 to +82
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add rules to address reported linting issues.

Based on the PR comments, there are several linting issues that should be addressed:

  • prefer-const violations
  • non-null assertion warnings

Add these rules to enforce better code quality:

    rules: {
      '@typescript-eslint/no-explicit-any': ['off'],
      '@typescript-eslint/no-unused-vars': ['off'],
+     '@typescript-eslint/no-non-null-assertion': ['warn'],
+     'prefer-const': ['error'],

      '@typescript-eslint/strict-boolean-expressions': [
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
rules: {
'@typescript-eslint/no-explicit-any': ['off'],
'@typescript-eslint/no-unused-vars': ['off'],
'@typescript-eslint/strict-boolean-expressions': [
2,
{
allowNullableObject: true,
allowNullableBoolean: true,
allowAny: true,
},
],
eqeqeq: ['error', 'smart'],
'jest-formatting/padding-around-describe-blocks': 2,
'jest-formatting/padding-around-test-blocks': 2,
'header/header': [2, './resources/license.header.js'],
'mocha/max-top-level-suites': 'off',
'mocha/no-exports': 'off',
'mocha/no-mocha-arrows': 'off',
'no-console': 0,
'no-return-await': 2,
'no-unneeded-ternary': 2,
'no-unused-vars': 'off',
'prettier/prettier': [
'error',
{
endOfLine: 'auto',
},
],
'unicorn/prefer-node-protocol': 2,
},
rules: {
'@typescript-eslint/no-explicit-any': ['off'],
'@typescript-eslint/no-unused-vars': ['off'],
'@typescript-eslint/no-non-null-assertion': ['warn'],
'prefer-const': ['error'],
'@typescript-eslint/strict-boolean-expressions': [
2,
{
allowNullableObject: true,
allowNullableBoolean: true,
allowAny: true,
},
],
eqeqeq: ['error', 'smart'],
'jest-formatting/padding-around-describe-blocks': 2,
'jest-formatting/padding-around-test-blocks': 2,
'header/header': [2, './resources/license.header.js'],
'mocha/max-top-level-suites': 'off',
'mocha/no-exports': 'off',
'mocha/no-mocha-arrows': 'off',
'no-console': 0,
'no-return-await': 2,
'no-unneeded-ternary': 2,
'no-unused-vars': 'off',
'prettier/prettier': [
'error',
{
endOfLine: 'auto',
},
],
'unicorn/prefer-node-protocol': 2,
},

},
];
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
},
"devDependencies": {
"@aws-lite/s3-types": "^0.2.6",
"@eslint/eslintrc": "^3.2.0",
"@eslint/js": "^9.19.0",
"@smithy/types": "^3.7.2",
"@swc/core": "^1.10.12",
"@testcontainers/localstack": "^10.17.2",
Expand All @@ -73,16 +75,16 @@
"@types/stream-json": "^1.7.8",
"@types/supertest": "^2.0.16",
"@types/swagger-ui-express": "^4.1.7",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"@typescript-eslint/eslint-plugin": "^8.22.0",
"@typescript-eslint/parser": "^8.22.0",
"c8": "^8.0.1",
"copyfiles": "^2.4.1",
"eslint": "^8.55.0",
"eslint-config-prettier": "^9.1.0",
"eslint": "^9.19.0",
"eslint-config-prettier": "^10.0.1",
"eslint-plugin-header": "^3.1.1",
"eslint-plugin-jest-formatting": "^3.1.0",
"eslint-plugin-prettier": "^5.2.3",
"eslint-plugin-unicorn": "^49.0.0",
"eslint-plugin-unicorn": "^56.0.1",
"msgpack-lite": "^0.1.26",
"nodemon": "^2.0.22",
"npm-check-updates": "^16.14.20",
Expand Down
4 changes: 3 additions & 1 deletion src/data/ar-io-data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ export class ArIODataSource implements ContiguousDataSource {
}

stopUpdatingPeers() {
this.intervalId && clearInterval(this.intervalId);
if (this.intervalId) {
clearInterval(this.intervalId);
}
}

async updatePeerList() {
Expand Down
4 changes: 2 additions & 2 deletions src/data/gateways-data-source.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import { Readable } from 'node:stream';

const axiosMockCommonParams = (config: any) => ({
interceptors: {
request: { use: () => {} }, // eslint-disable-line @typescript-eslint/no-empty-function
response: { use: () => {} }, // eslint-disable-line @typescript-eslint/no-empty-function
request: { use: () => {} },
response: { use: () => {} },
},
defaults: config,
});
Expand Down
11 changes: 5 additions & 6 deletions src/data/read-through-data-cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ describe('ReadThroughDataCache', function () {
123,
);

assert.deepEqual(calledWithArgument!, 'test-hash'); // eslint-disable-line @typescript-eslint/no-non-null-assertion
assert.deepEqual(calledWithArgument!, 'test-hash');
assert.deepEqual(result?.stream, mockStream);
assert.deepEqual(result?.size, 123);
});
Expand All @@ -192,7 +192,7 @@ describe('ReadThroughDataCache', function () {
123,
);

assert.deepEqual(calledWithArgument!, 'test-hash'); // eslint-disable-line @typescript-eslint/no-non-null-assertion
assert.deepEqual(calledWithArgument!, 'test-hash');

assert.deepEqual(result, undefined);
});
Expand Down Expand Up @@ -227,9 +227,9 @@ describe('ReadThroughDataCache', function () {
20,
);

assert.deepEqual(calledWithArgument!, 'test-hash'); // eslint-disable-line @typescript-eslint/no-non-null-assertion
assert.deepEqual(calledWithArgument!, 'test-hash');

assert.deepEqual(calledWithParentArgument!, 'test-parent-hash'); // eslint-disable-line @typescript-eslint/no-non-null-assertion
assert.deepEqual(calledWithParentArgument!, 'test-parent-hash');

assert.deepEqual(result?.stream, mockStream);
assert.deepEqual(result?.size, 20);
Expand Down Expand Up @@ -278,7 +278,7 @@ describe('ReadThroughDataCache', function () {
origin: 'node-url',
},
});
assert.equal(calledWithArgument!, 'test-hash'); // eslint-disable-line @typescript-eslint/no-non-null-assertion
assert.equal(calledWithArgument!, 'test-hash');

let receivedData = '';

Expand Down Expand Up @@ -381,7 +381,6 @@ describe('ReadThroughDataCache', function () {
requestAttributes,
});

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
assert.deepEqual(calledWithArgument!, {
id: 'test-id',
dataAttributes: undefined,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function sanityCheckBlock(block: PartialJsonBlock) {
throw new Error("Invalid block: invalid 'indep_hash' format");
}

if (!block.height === undefined) {
if (!block.height === false) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix the block height validation logic.

The current condition if (!block.height === false) is confusing and potentially error-prone. It's equivalent to checking if block.height is truthy, which isn't the intended validation.

Consider this clearer alternative:

-  if (!block.height === false) {
+  if (block.height === undefined) {
     throw new Error("Invalid block: missing 'height'");
   }

This explicitly checks for undefined, making the validation more straightforward and maintainable.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (!block.height === false) {
if (block.height === undefined) {

throw new Error("Invalid block: missing 'height'");
}

Expand Down
12 changes: 6 additions & 6 deletions src/store/kv-debounce-store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('KvDebounceCache', () => {
await kvDebounceCache.set(key, Buffer.from('test2', 'base64url'));
const result = await kvDebounceCache.get(key);
assert.notEqual(result, undefined);
assert.equal(toB64Url(result!), 'test'); // eslint-disable-line @typescript-eslint/no-non-null-assertion
assert.equal(toB64Url(result!), 'test');
});

describe('debounceFn', () => {
Expand All @@ -78,7 +78,7 @@ describe('KvDebounceCache', () => {
});
await kvDebounceStore.get(key);
const result = await kvBufferStore.get(key);
assert.equal(result!.toString('utf-8'), 'test'); // eslint-disable-line @typescript-eslint/no-non-null-assertion
assert.equal(result!.toString('utf-8'), 'test');
assert.equal(callCount, 1);
});

Expand All @@ -101,7 +101,7 @@ describe('KvDebounceCache', () => {
},
});
const result = await kvBufferStore.get(key);
assert.equal(result, undefined); // eslint-disable-line @typescript-eslint/no-non-null-assertion
assert.equal(result, undefined);
assert.equal(callCount, 0);
assert.equal(lastCallTimestamp, 0);
});
Expand Down Expand Up @@ -138,7 +138,7 @@ describe('KvDebounceCache', () => {
const result = await kvDebounceStore.get(key);
assert.equal(callCount, 2);
assert.ok(lastCallTimestamp >= Date.now() - 10);
assert.equal(result!.toString('utf-8'), '1'); // eslint-disable-line @typescript-eslint/no-non-null-assertion
assert.equal(result!.toString('utf-8'), '1');
});

it('should call debounceFn on cache hit after the cache hit debounce ttl expires', async () => {
Expand All @@ -163,7 +163,7 @@ describe('KvDebounceCache', () => {

// should hydrate immediately
const result = await kvDebounceStore.get(key);
assert.equal(result!.toString('utf-8'), 'test0'); // eslint-disable-line @typescript-eslint/no-non-null-assertion
assert.equal(result!.toString('utf-8'), 'test0');
assert.ok(lastCallTimestamp <= Date.now());
assert.equal(callCount, 1);

Expand All @@ -172,7 +172,7 @@ describe('KvDebounceCache', () => {
assert.equal(callCount, 2);
assert.ok(lastCallTimestamp >= Date.now() - 100);
const result2 = await kvDebounceStore.get(key);
assert.equal(result2!.toString('utf-8'), 'test1'); // eslint-disable-line @typescript-eslint/no-non-null-assertion
assert.equal(result2!.toString('utf-8'), 'test1');
});

// intentional design choice to bubble up errors from debounceFn and let the caller handle them appropriately
Expand Down
8 changes: 4 additions & 4 deletions src/store/lmdb-kv-store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('LmdbKvStore', () => {
await lmdbKvStore.set(key, value);
const result = await lmdbKvStore.get(key);
assert.notEqual(result, undefined);
assert.equal(toB64Url(result!), 'test'); // eslint-disable-line @typescript-eslint/no-non-null-assertion
assert.equal(toB64Url(result!), 'test');
});

it('should properly delete buffer', async () => {
Expand All @@ -59,9 +59,9 @@ describe('LmdbKvStore', () => {
await lmdbKvStore.set(key, value);
await lmdbKvStore.set(key, Buffer.from('test2', 'base64url'));
const result = await lmdbKvStore.get(key);
assert.notEqual(result, undefined); // eslint-disable-line @typescript-eslint/no-non-null-assertion
assert.notEqual(result, undefined);

assert.equal(toB64Url(result!), 'test'); // eslint-disable-line @typescript-eslint/no-non-null-assertion
assert.equal(toB64Url(result!), 'test');
});

it('should return a buffer when a Uint8Array is stored in the cache', async () => {
Expand All @@ -74,6 +74,6 @@ describe('LmdbKvStore', () => {
const result = await lmdbKvStore.get(key);
assert.notEqual(result, undefined);
assert.equal(Buffer.isBuffer(result), true);
assert.equal(toB64Url(result!), 'test'); // eslint-disable-line @typescript-eslint/no-non-null-assertion
assert.equal(toB64Url(result!), 'test');
});
});
4 changes: 3 additions & 1 deletion src/workers/sqlite-wal-cleanup-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ export class SQLiteWalCleanupWorker {
}

stop(): void {
this.intervalId && clearInterval(this.intervalId);
if (this.intervalId) {
clearInterval(this.intervalId);
}
this.log.info(
`Stopped SQLite WAL cleanup worker for ${this.dbName} database`,
);
Expand Down
4 changes: 3 additions & 1 deletion src/workers/transaction-offset-repair-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ export class TransactionOffsetRepairWorker {
async stop(): Promise<void> {
const log = this.log.child({ method: 'stop' });

this.intervalId && clearInterval(this.intervalId);
if (this.intervalId) {
clearInterval(this.intervalId);
}

log.debug('Stopped successfully.');
}
Expand Down
4 changes: 3 additions & 1 deletion src/workers/transaction-repair-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ export class TransactionRepairWorker {
async stop(): Promise<void> {
const log = this.log.child({ method: 'stop' });

this.intervalId && clearInterval(this.intervalId);
if (this.intervalId) {
clearInterval(this.intervalId);
}

log.debug('Stopped successfully.');
}
Expand Down
1 change: 0 additions & 1 deletion test/sqlite-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export let dataDb: Sqlite.Database;
export let moderationDb: Sqlite.Database;
export let bundlesDb: Sqlite.Database;

/* eslint-disable */
before(async () => {
log.transports.forEach((t) => (t.silent = true));
fs.readdirSync('test/tmp').forEach((file) => {
Expand Down
Loading