Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/rules/no-unsafe-values.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

<!-- prettier-ignore-start -->
Expand Down
24 changes: 24 additions & 0 deletions tests/rules/no-unsafe-values.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand Down
Loading