From 661357c985b49629ad5b2221be9aae999db41831 Mon Sep 17 00:00:00 2001 From: Joachim Van Herwegen Date: Tue, 12 Sep 2023 13:53:50 +0200 Subject: [PATCH] chore: Remove eslint rule about deleting dynamic keys --- .eslintrc.js | 6 +++++- src/pods/generate/BaseResourcesGenerator.ts | 1 - src/storage/accessors/InMemoryDataAccessor.ts | 1 - src/storage/keyvalue/JsonFileStorage.ts | 1 - src/util/locking/MemoryResourceLocker.ts | 1 - test/unit/storage/DataAccessorBasedStore.test.ts | 4 ---- test/unit/util/locking/BaseReadWriteLocker.test.ts | 1 - test/unit/util/locking/RedisLocker.test.ts | 1 - test/util/Util.ts | 4 ---- 9 files changed, 5 insertions(+), 15 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 23acb1268..a9ff1ab80 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -38,6 +38,8 @@ module.exports = { // There are valid typing reasons to have one or the other '@typescript-eslint/consistent-type-definitions': 'off', '@typescript-eslint/lines-between-class-members': [ 'error', { exceptAfterSingleLine: true }], + // We almost exclusively do dynamic deletes + '@typescript-eslint/no-dynamic-delete': 'off', '@typescript-eslint/no-empty-interface': 'off', // Breaks with default void in AsyncHandler 2nd generic '@typescript-eslint/no-invalid-void-type': 'off', @@ -78,9 +80,11 @@ module.exports = { 'unicorn/catch-error-name': 'off', 'unicorn/import-index': 'off', 'unicorn/import-style': 'off', - // The next 2 some functional programming paradigms + // The next 2 would prevent some functional programming paradigms 'unicorn/no-array-callback-reference': 'off', 'unicorn/no-fn-reference-in-iterator': 'off', + // Triggers on all functions called `find`, not just on arrays + 'unicorn/no-array-method-this-argument':'off', 'unicorn/no-object-as-default-parameter': 'off', 'unicorn/numeric-separators-style': 'off', // At function only supported in Node v16.6.0 diff --git a/src/pods/generate/BaseResourcesGenerator.ts b/src/pods/generate/BaseResourcesGenerator.ts index 998c72f4e..57b7b02f6 100644 --- a/src/pods/generate/BaseResourcesGenerator.ts +++ b/src/pods/generate/BaseResourcesGenerator.ts @@ -118,7 +118,6 @@ export class BaseResourcesGenerator implements TemplatedResourcesGenerator { // Remove root metadata if it exists const metaLink = links[folderLink.identifier.path]?.meta; - // eslint-disable-next-line @typescript-eslint/no-dynamic-delete delete links[folderLink.identifier.path]; yield* this.generateResource(folderLink, options, metaLink); diff --git a/src/storage/accessors/InMemoryDataAccessor.ts b/src/storage/accessors/InMemoryDataAccessor.ts index ab95c1c32..c43212cc5 100644 --- a/src/storage/accessors/InMemoryDataAccessor.ts +++ b/src/storage/accessors/InMemoryDataAccessor.ts @@ -95,7 +95,6 @@ export class InMemoryDataAccessor implements DataAccessor, SingleThreaded { if (!parent.entries[identifier.path]) { throw new NotFoundHttpError(); } - // eslint-disable-next-line @typescript-eslint/no-dynamic-delete delete parent.entries[identifier.path]; } diff --git a/src/storage/keyvalue/JsonFileStorage.ts b/src/storage/keyvalue/JsonFileStorage.ts index 48d574a2e..885ad8032 100644 --- a/src/storage/keyvalue/JsonFileStorage.ts +++ b/src/storage/keyvalue/JsonFileStorage.ts @@ -40,7 +40,6 @@ export class JsonFileStorage implements KeyValueStorage { public async delete(key: string): Promise { return this.updateJsonSafely((json: NodeJS.Dict): boolean => { if (typeof json[key] !== 'undefined') { - // eslint-disable-next-line @typescript-eslint/no-dynamic-delete delete json[key]; return true; } diff --git a/src/util/locking/MemoryResourceLocker.ts b/src/util/locking/MemoryResourceLocker.ts index c322e2ff0..6e4a69f1d 100644 --- a/src/util/locking/MemoryResourceLocker.ts +++ b/src/util/locking/MemoryResourceLocker.ts @@ -31,7 +31,6 @@ export class MemoryResourceLocker implements ResourceLocker, SingleThreaded { this.logger.debug(`Acquired lock for ${path}. ${this.getLockCount()} locks active.`); resolve(); }, (): void => { - // eslint-disable-next-line @typescript-eslint/no-dynamic-delete delete this.unlockCallbacks[path]; this.logger.debug(`Released lock for ${path}. ${this.getLockCount()} active locks remaining.`); }); diff --git a/test/unit/storage/DataAccessorBasedStore.test.ts b/test/unit/storage/DataAccessorBasedStore.test.ts index 3467b8997..c9dbcae4a 100644 --- a/test/unit/storage/DataAccessorBasedStore.test.ts +++ b/test/unit/storage/DataAccessorBasedStore.test.ts @@ -48,7 +48,6 @@ class SimpleDataAccessor implements DataAccessor { public async deleteResource(identifier: ResourceIdentifier): Promise { this.checkExists(identifier); - // eslint-disable-next-line @typescript-eslint/no-dynamic-delete delete this.data[identifier.path]; } @@ -424,7 +423,6 @@ describe('A DataAccessorBasedStore', (): void => { // As discussed in #475, trimming the trailing slash of a root container in getNormalizedMetadata // can result in undefined behaviour since there is no parent container. it('will not trim the slash of root containers since there is no parent.', async(): Promise => { - // eslint-disable-next-line @typescript-eslint/no-dynamic-delete delete accessor.data[root]; const mock = jest.spyOn(accessor, 'getMetadata'); @@ -524,7 +522,6 @@ describe('A DataAccessorBasedStore', (): void => { }); it('can write resources even if root does not exist.', async(): Promise => { - // eslint-disable-next-line @typescript-eslint/no-dynamic-delete delete accessor.data[root]; const resourceID = { path: `${root}resource` }; const result = await store.setRepresentation(resourceID, representation); @@ -558,7 +555,6 @@ describe('A DataAccessorBasedStore', (): void => { }); it('can write to root if it does not exist.', async(): Promise => { - // eslint-disable-next-line @typescript-eslint/no-dynamic-delete delete accessor.data[root]; const resourceID = { path: `${root}` }; diff --git a/test/unit/util/locking/BaseReadWriteLocker.test.ts b/test/unit/util/locking/BaseReadWriteLocker.test.ts index b3aeb9a5f..4f3b63ac9 100644 --- a/test/unit/util/locking/BaseReadWriteLocker.test.ts +++ b/test/unit/util/locking/BaseReadWriteLocker.test.ts @@ -28,7 +28,6 @@ class MemoryLocker implements ResourceLocker { if (this.locks[path].length > 0) { this.locks[path].shift()!(); } else { - // eslint-disable-next-line @typescript-eslint/no-dynamic-delete delete this.locks[path]; } } diff --git a/test/unit/util/locking/RedisLocker.test.ts b/test/unit/util/locking/RedisLocker.test.ts index 8341fb6cd..57c85019f 100644 --- a/test/unit/util/locking/RedisLocker.test.ts +++ b/test/unit/util/locking/RedisLocker.test.ts @@ -79,7 +79,6 @@ const redis: jest.Mocked = { if (typeof store.internal[key] !== 'undefined') { deletedEntries += 1; } - // eslint-disable-next-line @typescript-eslint/no-dynamic-delete delete store.internal[key]; } return deletedEntries; diff --git a/test/util/Util.ts b/test/util/Util.ts index 59c585f0f..15f78b5ad 100644 --- a/test/util/Util.ts +++ b/test/util/Util.ts @@ -184,7 +184,6 @@ export function mockFileSystem(rootFilepath?: string, time?: Date): { data: any if (!(await this.lstat(path)).isFile()) { throwSystemError('EISDIR'); } - // eslint-disable-next-line @typescript-eslint/no-dynamic-delete delete folder[name]; }, async symlink(target: string, path: string): Promise { @@ -207,7 +206,6 @@ export function mockFileSystem(rootFilepath?: string, time?: Date): { data: any if (!(await this.lstat(path)).isDirectory()) { throwSystemError('ENOTDIR'); } - // eslint-disable-next-line @typescript-eslint/no-dynamic-delete delete folder[name]; }, async readdir(path: string): Promise { @@ -261,7 +259,6 @@ export function mockFileSystem(rootFilepath?: string, time?: Date): { data: any const { folder: folderDest, name: nameDest } = getFolder(destination); folderDest[nameDest] = folder[name]; - // eslint-disable-next-line @typescript-eslint/no-dynamic-delete delete folder[name]; }, }, @@ -286,7 +283,6 @@ export function mockFileSystem(rootFilepath?: string, time?: Date): { data: any }, async remove(path: string): Promise { const { folder, name } = getFolder(path); - // eslint-disable-next-line @typescript-eslint/no-dynamic-delete delete folder[name]; }, async pathExists(path: string): Promise {