Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2a81578

Browse filesBrowse 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
Copy full SHA for 2a81578

File tree

Expand file treeCollapse file tree

2 files changed

+37
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+37
-0
lines changed

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

Copy file name to clipboardExpand all lines: lib/rules/no-loss-of-precision.js
+2Lines 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

Copy file name to clipboardExpand all lines: tests/lib/rules/no-loss-of-precision.js
+35Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.