diff --git a/docs/rules/no-unsafe-values.md b/docs/rules/no-unsafe-values.md index 49c817a0..b97abb09 100644 --- a/docs/rules/no-unsafe-values.md +++ b/docs/rules/no-unsafe-values.md @@ -18,6 +18,8 @@ These issues can lead to data corruption, silent failures, or inconsistent behav This rule warns on values that are unsafe for interchange, such as strings with unmatched [surrogates](https://en.wikipedia.org/wiki/UTF-16), numbers that evaluate to Infinity, numbers that evaluate to zero unintentionally, numbers that look like integers but are too large, and [subnormal numbers](https://en.wikipedia.org/wiki/Subnormal_number). +When run on JSON5 code, this rule does not report explicit [`Infinity` and `NaN`](https://spec.json5.org/#summary-of-features-numbers) values because the specification defines how they are interpreted. These values differ from numeric literals such as `1e400`, which evaluate to `Infinity` because they exceed JavaScript's number range. + Examples of **incorrect** code for this rule: diff --git a/tests/rules/no-unsafe-values.test.js b/tests/rules/no-unsafe-values.test.js index 93e9f6c3..11c8114e 100644 --- a/tests/rules/no-unsafe-values.test.js +++ b/tests/rules/no-unsafe-values.test.js @@ -74,6 +74,30 @@ ruleTester.run("no-unsafe-values", rule, { code: "0.", language: "json/json5", }, + { + code: "Infinity", + language: "json/json5", + }, + { + code: "+Infinity", + language: "json/json5", + }, + { + code: "-Infinity", + language: "json/json5", + }, + { + code: "NaN", + language: "json/json5", + }, + { + code: "+NaN", + language: "json/json5", + }, + { + code: "-NaN", + language: "json/json5", + }, ], invalid: [ {