From 3ea85b14a3f55d7f04b0d5c309572a83f2dea562 Mon Sep 17 00:00:00 2001 From: dakkar Date: Wed, 27 Nov 2024 21:01:12 +0000 Subject: [PATCH 1/2] silence linter those objects always have the normal prototype, and can't have `hasOwnProperty` redefined, let me call it normally (otherwise I'd have to write `Object.prototype.hasOwnProperty.call(newUser, field)` and that's ugly) --- packages/backend/src/server/api/endpoints/i/update.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/backend/src/server/api/endpoints/i/update.ts b/packages/backend/src/server/api/endpoints/i/update.ts index f0e8dfc832..0965f4bcf4 100644 --- a/packages/backend/src/server/api/endpoints/i/update.ts +++ b/packages/backend/src/server/api/endpoints/i/update.ts @@ -588,11 +588,13 @@ export default class extends Endpoint { // eslint- // `ApRendererService.renderPerson` private userNeedsPublishing(oldUser: MiLocalUser, newUser: Partial): boolean { for (const field of ['avatarId', 'bannerId', 'backgroundId', 'isBot', 'username', 'name', 'isLocked', 'isExplorable', 'isCat', 'noindex', 'speakAsCat', 'movedToUri', 'alsoKnownAs'] as (keyof MiUser)[]) { + /* eslint-disable-next-line no-prototype-builtins */ if (newUser.hasOwnProperty(field) && oldUser[field] !== newUser[field]) { return true; } } for (const arrayField of ['emojis', 'tags'] as (keyof MiUser)[]) { + /* eslint-disable-next-line no-prototype-builtins */ if (newUser.hasOwnProperty(arrayField) !== oldUser.hasOwnProperty(arrayField)) { return true; } @@ -611,11 +613,13 @@ export default class extends Endpoint { // eslint- private profileNeedsPublishing(oldProfile: MiUserProfile, newProfile: Partial): boolean { for (const field of ['description', 'followedMessage', 'birthday', 'location', 'listenbrainz'] as (keyof MiUserProfile)[]) { + /* eslint-disable-next-line no-prototype-builtins */ if (newProfile.hasOwnProperty(field) && oldProfile[field] !== newProfile[field]) { return true; } } for (const arrayField of ['fields'] as (keyof MiUserProfile)[]) { + /* eslint-disable-next-line no-prototype-builtins */ if (newProfile.hasOwnProperty(arrayField) !== oldProfile.hasOwnProperty(arrayField)) { return true; } From 9309872cff349060ef82cf368c81f50a0932367b Mon Sep 17 00:00:00 2001 From: dakkar Date: Wed, 27 Nov 2024 21:25:54 +0000 Subject: [PATCH 2/2] simpler check for "property present" --- .../backend/src/server/api/endpoints/i/update.ts | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/packages/backend/src/server/api/endpoints/i/update.ts b/packages/backend/src/server/api/endpoints/i/update.ts index 0965f4bcf4..8e61b8f784 100644 --- a/packages/backend/src/server/api/endpoints/i/update.ts +++ b/packages/backend/src/server/api/endpoints/i/update.ts @@ -588,14 +588,12 @@ export default class extends Endpoint { // eslint- // `ApRendererService.renderPerson` private userNeedsPublishing(oldUser: MiLocalUser, newUser: Partial): boolean { for (const field of ['avatarId', 'bannerId', 'backgroundId', 'isBot', 'username', 'name', 'isLocked', 'isExplorable', 'isCat', 'noindex', 'speakAsCat', 'movedToUri', 'alsoKnownAs'] as (keyof MiUser)[]) { - /* eslint-disable-next-line no-prototype-builtins */ - if (newUser.hasOwnProperty(field) && oldUser[field] !== newUser[field]) { + if ((field in newUser) && oldUser[field] !== newUser[field]) { return true; } } for (const arrayField of ['emojis', 'tags'] as (keyof MiUser)[]) { - /* eslint-disable-next-line no-prototype-builtins */ - if (newUser.hasOwnProperty(arrayField) !== oldUser.hasOwnProperty(arrayField)) { + if ((arrayField in newUser) !== (arrayField in oldUser)) { return true; } @@ -613,14 +611,12 @@ export default class extends Endpoint { // eslint- private profileNeedsPublishing(oldProfile: MiUserProfile, newProfile: Partial): boolean { for (const field of ['description', 'followedMessage', 'birthday', 'location', 'listenbrainz'] as (keyof MiUserProfile)[]) { - /* eslint-disable-next-line no-prototype-builtins */ - if (newProfile.hasOwnProperty(field) && oldProfile[field] !== newProfile[field]) { + if ((field in newProfile) && oldProfile[field] !== newProfile[field]) { return true; } } for (const arrayField of ['fields'] as (keyof MiUserProfile)[]) { - /* eslint-disable-next-line no-prototype-builtins */ - if (newProfile.hasOwnProperty(arrayField) !== oldProfile.hasOwnProperty(arrayField)) { + if ((arrayField in newProfile) !== (arrayField in oldProfile)) { return true; }