Skip to content

Commit 2a81578

Browse files
authored
feat: support TS syntax in no-loss-of-precision (#19560)
* feat: support TS syntax in `no-loss-of-precision` * chore: fix lint
1 parent 366e369 commit 2a81578

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

‎lib/rules/no-loss-of-precision.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
module.exports = {
1414
meta: {
1515
type: "problem",
16+
dialects: ["typescript", "javascript"],
17+
language: "javascript",
1618

1719
docs: {
1820
description: "Disallow literal numbers that lose precision",

‎tests/lib/rules/no-loss-of-precision.js‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,3 +318,38 @@ ruleTester.run("no-loss-of-precision", rule, {
318318
},
319319
],
320320
});
321+
322+
const ruleTesterTypeScript = new RuleTester({
323+
languageOptions: {
324+
parser: require("@typescript-eslint/parser"),
325+
},
326+
});
327+
328+
ruleTesterTypeScript.run("no-loss-of-precision", rule, {
329+
valid: [
330+
"const x = 12345;",
331+
"const x = 123.456;",
332+
"const x = -123.456;",
333+
"const x = 123_456;",
334+
"const x = 123_00_000_000_000_000_000_000_000;",
335+
"const x = 123.000_000_000_000_000_000_000_0;",
336+
],
337+
invalid: [
338+
{
339+
code: "const x = 9007199254740993;",
340+
errors: [{ messageId: "noLossOfPrecision" }],
341+
},
342+
{
343+
code: "const x = 9_007_199_254_740_993;",
344+
errors: [{ messageId: "noLossOfPrecision" }],
345+
},
346+
{
347+
code: "const x = 9_007_199_254_740.993e3;",
348+
errors: [{ messageId: "noLossOfPrecision" }],
349+
},
350+
{
351+
code: "const x = 0b100_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_000_001;",
352+
errors: [{ messageId: "noLossOfPrecision" }],
353+
},
354+
],
355+
});

0 commit comments

Comments
 (0)