From 0ee3594db064d2fbe6bbfe827c54caf1751ee897 Mon Sep 17 00:00:00 2001 From: Stephen Cresswell <229672+cressie176@users.noreply.github.com> Date: Thu, 4 Sep 2025 20:17:11 +0100 Subject: [PATCH] Replace global isNaN with Number.isNaN for safer type checking MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace all instances of the global isNaN function with Number.isNaN to avoid unsafe type coercion and improve numerical validation reliability. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- CHANGELOG.md | 1 + biome.json | 2 +- examples/tutorials/callback_api/rpc_client.js | 2 +- examples/tutorials/rpc_client.js | 2 +- test/data.js | 6 +++--- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0115d8a4..a5d18c1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ - Remove redundant 'use strict' directives as modules are automatically in strict mode - Refactor assignment-in-expression patterns to improve code clarity and readability - Enforce strict equality checks (=== and !==) instead of loose equality (== and !=) +- Replace global isNaN with Number.isNaN for safer type checking ## v0.10.9 - Add support for IPv6 urls diff --git a/biome.json b/biome.json index 555e8e0c..fd3791c9 100644 --- a/biome.json +++ b/biome.json @@ -22,7 +22,7 @@ "suspicious": { "noRedundantUseStrict": "error", "noAsyncPromiseExecutor": "off", - "noGlobalIsNan": "off", + "noGlobalIsNan": "error", "noRedeclare": "off", "noGlobalIsFinite": "off", "noPrototypeBuiltins": "off", diff --git a/examples/tutorials/callback_api/rpc_client.js b/examples/tutorials/callback_api/rpc_client.js index 48b3c081..d42003bf 100755 --- a/examples/tutorials/callback_api/rpc_client.js +++ b/examples/tutorials/callback_api/rpc_client.js @@ -7,7 +7,7 @@ const {v4: uuid} = require('uuid'); const queue = 'rpc_queue'; const n = parseInt(process.argv[2], 10); -if (isNaN(n)) { +if (Number.isNaN(n)) { console.warn('Usage: %s number', basename(process.argv[1])); process.exit(1); } diff --git a/examples/tutorials/rpc_client.js b/examples/tutorials/rpc_client.js index 4f4505cb..5ce313aa 100755 --- a/examples/tutorials/rpc_client.js +++ b/examples/tutorials/rpc_client.js @@ -7,7 +7,7 @@ const {v4: uuid} = require('uuid'); const queue = 'rpc_queue'; const n = parseInt(process.argv[2], 10); -if (isNaN(n)) { +if (Number.isNaN(n)) { console.warn('Usage: %s number', basename(process.argv[1])); process.exit(1); } diff --git a/test/data.js b/test/data.js index bb4bce1d..c80dc4ea 100644 --- a/test/data.js +++ b/test/data.js @@ -43,7 +43,7 @@ function toFloat32(i) { function floatChooser(maxExp) { return function () { let n = Number.NaN; - while (isNaN(n)) { + while (Number.isNaN(n)) { const mantissa = Math.random() * 2 - 1; const exponent = chooseInt(0, maxExp); n = mantissa ** exponent; @@ -268,13 +268,13 @@ const domainProps = [ [ Double, function (f) { - return !isNaN(f) && isFinite(f); + return !Number.isNaN(f) && isFinite(f); }, ], [ Float, function (f) { - return !isNaN(f) && isFinite(f) && Math.log(Math.abs(f)) * Math.LOG10E < 309; + return !Number.isNaN(f) && isFinite(f) && Math.log(Math.abs(f)) * Math.LOG10E < 309; }, ], [