From 149913102fde44262ea64edc106764b139c4f6b8 Mon Sep 17 00:00:00 2001 From: Stephen Cresswell <229672+cressie176@users.noreply.github.com> Date: Thu, 4 Sep 2025 20:35:16 +0100 Subject: [PATCH] Replace Object.prototype.hasOwnProperty() with safer Object.hasOwn() method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .claude/commands/lint-enforce.md | 2 -- CHANGELOG.md | 1 + biome.json | 2 +- lib/codec.js | 4 ++-- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.claude/commands/lint-enforce.md b/.claude/commands/lint-enforce.md index fb7826aa..b5e0b23f 100644 --- a/.claude/commands/lint-enforce.md +++ b/.claude/commands/lint-enforce.md @@ -10,5 +10,3 @@ Please follow the following process when I ask you to enfore a new lint rule usi 8. Add the changes 9. Commit the changes 10. Push the changes - -You do not need to ask before updating biome.json, running tests, using --fix in safe mode, fetching coment from biomejs.dev, or updating the changelog diff --git a/CHANGELOG.md b/CHANGELOG.md index 652fb00f..5492865a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ - Replace string concatenation with modern template literals - Remove redundant 'use strict' directives as modules are automatically in strict mode - Refactor assignment-in-expression patterns to improve code clarity and readability +- Replace Object.prototype.hasOwnProperty() with safer Object.hasOwn() method - Enforce strict equality checks (=== and !==) instead of loose equality (== and !=) - Replace global isNaN with Number.isNaN for safer type checking - Ensure no variable redeclarations exist to prevent shadowing issues diff --git a/biome.json b/biome.json index e5ff7d3a..8c3ea674 100644 --- a/biome.json +++ b/biome.json @@ -24,7 +24,7 @@ "noAsyncPromiseExecutor": "off", "noGlobalIsNan": "error", "noGlobalIsFinite": "error", - "noPrototypeBuiltins": "off", + "noPrototypeBuiltins": "error", "noVar": "error" } } diff --git a/lib/codec.js b/lib/codec.js index bdf453e2..2c1c2f8a 100644 --- a/lib/codec.js +++ b/lib/codec.js @@ -51,7 +51,7 @@ function encodeFieldValue(buffer, value, offset) { let type = typeof value, val = value; // A trapdoor for specifying a type, e.g., timestamp - if (value && type === 'object' && value.hasOwnProperty('!')) { + if (value && type === 'object' && Object.hasOwn(value, '!')) { val = value.value; type = value['!']; } @@ -190,7 +190,7 @@ function encodeFieldValue(buffer, value, offset) { break; case 'decimal': tag('D'); - if (val.hasOwnProperty('places') && val.hasOwnProperty('digits') && val.places >= 0 && val.places < 256) { + if (Object.hasOwn(val, 'places') && Object.hasOwn(val, 'digits') && val.places >= 0 && val.places < 256) { buffer[offset] = val.places; offset++; buffer.writeUInt32BE(val.digits, offset);