From f029bda5a8f5755b739d33d41713038b25c399e6 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Thu, 4 Apr 2024 02:35:16 +0100 Subject: [PATCH 1/2] feat(eslint-plugin): deprecate no-loss-of-precision extension rule --- .../eslint-plugin/docs/rules/no-loss-of-precision.mdx | 8 ++++++-- packages/eslint-plugin/src/configs/all.ts | 2 -- .../eslint-plugin/src/configs/recommended-type-checked.ts | 2 -- packages/eslint-plugin/src/configs/recommended.ts | 2 -- packages/eslint-plugin/src/configs/strict-type-checked.ts | 2 -- packages/eslint-plugin/src/configs/strict.ts | 2 -- packages/eslint-plugin/src/rules/no-loss-of-precision.ts | 2 +- packages/typescript-eslint/src/configs/all.ts | 2 -- .../src/configs/recommended-type-checked.ts | 2 -- packages/typescript-eslint/src/configs/recommended.ts | 2 -- .../typescript-eslint/src/configs/strict-type-checked.ts | 2 -- packages/typescript-eslint/src/configs/strict.ts | 2 -- 12 files changed, 7 insertions(+), 23 deletions(-) diff --git a/packages/eslint-plugin/docs/rules/no-loss-of-precision.mdx b/packages/eslint-plugin/docs/rules/no-loss-of-precision.mdx index 07fb1f0deb56..77f48255ae4a 100644 --- a/packages/eslint-plugin/docs/rules/no-loss-of-precision.mdx +++ b/packages/eslint-plugin/docs/rules/no-loss-of-precision.mdx @@ -9,5 +9,9 @@ import TabItem from '@theme/TabItem'; > > See **https://typescript-eslint.io/rules/no-loss-of-precision** for documentation. -This rule extends the base [`eslint/no-loss-of-precision`](https://eslint.org/docs/rules/no-loss-of-precision) rule. -It adds support for [numeric separators](https://github.com/tc39/proposal-numeric-separator). +:::danger Deprecated + +This rule has been deprecated because the base [`eslint/no-loss-of-precision`](https://eslint.org/docs/rules/no-loss-of-precision) rule added support for [numeric separators](https://github.com/tc39/proposal-numeric-separator). +There is no longer any need to use this extension rule. + +::: diff --git a/packages/eslint-plugin/src/configs/all.ts b/packages/eslint-plugin/src/configs/all.ts index 1e7304e45a36..71db2c523b2b 100644 --- a/packages/eslint-plugin/src/configs/all.ts +++ b/packages/eslint-plugin/src/configs/all.ts @@ -69,8 +69,6 @@ export = { '@typescript-eslint/no-invalid-void-type': 'error', 'no-loop-func': 'off', '@typescript-eslint/no-loop-func': 'error', - 'no-loss-of-precision': 'off', - '@typescript-eslint/no-loss-of-precision': 'error', 'no-magic-numbers': 'off', '@typescript-eslint/no-magic-numbers': 'error', '@typescript-eslint/no-meaningless-void-operator': 'error', diff --git a/packages/eslint-plugin/src/configs/recommended-type-checked.ts b/packages/eslint-plugin/src/configs/recommended-type-checked.ts index 38d36c132851..20993a066405 100644 --- a/packages/eslint-plugin/src/configs/recommended-type-checked.ts +++ b/packages/eslint-plugin/src/configs/recommended-type-checked.ts @@ -24,8 +24,6 @@ export = { '@typescript-eslint/no-for-in-array': 'error', 'no-implied-eval': 'off', '@typescript-eslint/no-implied-eval': 'error', - 'no-loss-of-precision': 'off', - '@typescript-eslint/no-loss-of-precision': 'error', '@typescript-eslint/no-misused-new': 'error', '@typescript-eslint/no-misused-promises': 'error', '@typescript-eslint/no-namespace': 'error', diff --git a/packages/eslint-plugin/src/configs/recommended.ts b/packages/eslint-plugin/src/configs/recommended.ts index 80a607a3288f..58f31702ada3 100644 --- a/packages/eslint-plugin/src/configs/recommended.ts +++ b/packages/eslint-plugin/src/configs/recommended.ts @@ -17,8 +17,6 @@ export = { '@typescript-eslint/no-duplicate-enum-values': 'error', '@typescript-eslint/no-explicit-any': 'error', '@typescript-eslint/no-extra-non-null-assertion': 'error', - 'no-loss-of-precision': 'off', - '@typescript-eslint/no-loss-of-precision': 'error', '@typescript-eslint/no-misused-new': 'error', '@typescript-eslint/no-namespace': 'error', '@typescript-eslint/no-non-null-asserted-optional-chain': 'error', diff --git a/packages/eslint-plugin/src/configs/strict-type-checked.ts b/packages/eslint-plugin/src/configs/strict-type-checked.ts index 26d8d9698812..5b00d2369842 100644 --- a/packages/eslint-plugin/src/configs/strict-type-checked.ts +++ b/packages/eslint-plugin/src/configs/strict-type-checked.ts @@ -32,8 +32,6 @@ export = { 'no-implied-eval': 'off', '@typescript-eslint/no-implied-eval': 'error', '@typescript-eslint/no-invalid-void-type': 'error', - 'no-loss-of-precision': 'off', - '@typescript-eslint/no-loss-of-precision': 'error', '@typescript-eslint/no-meaningless-void-operator': 'error', '@typescript-eslint/no-misused-new': 'error', '@typescript-eslint/no-misused-promises': 'error', diff --git a/packages/eslint-plugin/src/configs/strict.ts b/packages/eslint-plugin/src/configs/strict.ts index dbf57cc2c3f6..598b3246e270 100644 --- a/packages/eslint-plugin/src/configs/strict.ts +++ b/packages/eslint-plugin/src/configs/strict.ts @@ -23,8 +23,6 @@ export = { '@typescript-eslint/no-extra-non-null-assertion': 'error', '@typescript-eslint/no-extraneous-class': 'error', '@typescript-eslint/no-invalid-void-type': 'error', - 'no-loss-of-precision': 'off', - '@typescript-eslint/no-loss-of-precision': 'error', '@typescript-eslint/no-misused-new': 'error', '@typescript-eslint/no-namespace': 'error', '@typescript-eslint/no-non-null-asserted-nullish-coalescing': 'error', diff --git a/packages/eslint-plugin/src/rules/no-loss-of-precision.ts b/packages/eslint-plugin/src/rules/no-loss-of-precision.ts index 06938f9e4dcf..df5dd19c64bc 100644 --- a/packages/eslint-plugin/src/rules/no-loss-of-precision.ts +++ b/packages/eslint-plugin/src/rules/no-loss-of-precision.ts @@ -16,9 +16,9 @@ export default createRule({ name: 'no-loss-of-precision', meta: { type: 'problem', + deprecated: true, docs: { description: 'Disallow literal numbers that lose precision', - recommended: 'recommended', extendsBaseRule: true, }, hasSuggestions: baseRule.meta.hasSuggestions, diff --git a/packages/typescript-eslint/src/configs/all.ts b/packages/typescript-eslint/src/configs/all.ts index 893a6364f56b..beb6b9565908 100644 --- a/packages/typescript-eslint/src/configs/all.ts +++ b/packages/typescript-eslint/src/configs/all.ts @@ -77,8 +77,6 @@ export default ( '@typescript-eslint/no-invalid-void-type': 'error', 'no-loop-func': 'off', '@typescript-eslint/no-loop-func': 'error', - 'no-loss-of-precision': 'off', - '@typescript-eslint/no-loss-of-precision': 'error', 'no-magic-numbers': 'off', '@typescript-eslint/no-magic-numbers': 'error', '@typescript-eslint/no-meaningless-void-operator': 'error', diff --git a/packages/typescript-eslint/src/configs/recommended-type-checked.ts b/packages/typescript-eslint/src/configs/recommended-type-checked.ts index 77feebb92cba..a98eab620741 100644 --- a/packages/typescript-eslint/src/configs/recommended-type-checked.ts +++ b/packages/typescript-eslint/src/configs/recommended-type-checked.ts @@ -32,8 +32,6 @@ export default ( '@typescript-eslint/no-for-in-array': 'error', 'no-implied-eval': 'off', '@typescript-eslint/no-implied-eval': 'error', - 'no-loss-of-precision': 'off', - '@typescript-eslint/no-loss-of-precision': 'error', '@typescript-eslint/no-misused-new': 'error', '@typescript-eslint/no-misused-promises': 'error', '@typescript-eslint/no-namespace': 'error', diff --git a/packages/typescript-eslint/src/configs/recommended.ts b/packages/typescript-eslint/src/configs/recommended.ts index 042891ebf9b2..6e2906aedf86 100644 --- a/packages/typescript-eslint/src/configs/recommended.ts +++ b/packages/typescript-eslint/src/configs/recommended.ts @@ -25,8 +25,6 @@ export default ( '@typescript-eslint/no-duplicate-enum-values': 'error', '@typescript-eslint/no-explicit-any': 'error', '@typescript-eslint/no-extra-non-null-assertion': 'error', - 'no-loss-of-precision': 'off', - '@typescript-eslint/no-loss-of-precision': 'error', '@typescript-eslint/no-misused-new': 'error', '@typescript-eslint/no-namespace': 'error', '@typescript-eslint/no-non-null-asserted-optional-chain': 'error', diff --git a/packages/typescript-eslint/src/configs/strict-type-checked.ts b/packages/typescript-eslint/src/configs/strict-type-checked.ts index ba6e92ae3565..abe6656ca8be 100644 --- a/packages/typescript-eslint/src/configs/strict-type-checked.ts +++ b/packages/typescript-eslint/src/configs/strict-type-checked.ts @@ -40,8 +40,6 @@ export default ( 'no-implied-eval': 'off', '@typescript-eslint/no-implied-eval': 'error', '@typescript-eslint/no-invalid-void-type': 'error', - 'no-loss-of-precision': 'off', - '@typescript-eslint/no-loss-of-precision': 'error', '@typescript-eslint/no-meaningless-void-operator': 'error', '@typescript-eslint/no-misused-new': 'error', '@typescript-eslint/no-misused-promises': 'error', diff --git a/packages/typescript-eslint/src/configs/strict.ts b/packages/typescript-eslint/src/configs/strict.ts index dabfa2f78a92..2a01a4a39e16 100644 --- a/packages/typescript-eslint/src/configs/strict.ts +++ b/packages/typescript-eslint/src/configs/strict.ts @@ -31,8 +31,6 @@ export default ( '@typescript-eslint/no-extra-non-null-assertion': 'error', '@typescript-eslint/no-extraneous-class': 'error', '@typescript-eslint/no-invalid-void-type': 'error', - 'no-loss-of-precision': 'off', - '@typescript-eslint/no-loss-of-precision': 'error', '@typescript-eslint/no-misused-new': 'error', '@typescript-eslint/no-namespace': 'error', '@typescript-eslint/no-non-null-asserted-nullish-coalescing': 'error', From 0bb64bc6bbcc115dbfcab5a7897485eefe72f3ae Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Fri, 19 Apr 2024 11:29:30 -0400 Subject: [PATCH 2/2] baseRule.create, nice Kirk --- .../src/rules/no-loss-of-precision.ts | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/packages/eslint-plugin/src/rules/no-loss-of-precision.ts b/packages/eslint-plugin/src/rules/no-loss-of-precision.ts index df5dd19c64bc..000e5d9aa0bc 100644 --- a/packages/eslint-plugin/src/rules/no-loss-of-precision.ts +++ b/packages/eslint-plugin/src/rules/no-loss-of-precision.ts @@ -1,5 +1,3 @@ -import type { TSESTree } from '@typescript-eslint/utils'; - import type { InferMessageIdsTypeFromRule, InferOptionsTypeFromRule, @@ -27,18 +25,6 @@ export default createRule({ }, defaultOptions: [], create(context) { - const rules = baseRule.create(context); - - function isSeparatedNumeric(node: TSESTree.Literal): boolean { - return typeof node.value === 'number' && node.raw.includes('_'); - } - return { - Literal(node: TSESTree.Literal): void { - rules.Literal({ - ...node, - raw: isSeparatedNumeric(node) ? node.raw.replace(/_/g, '') : node.raw, - } as never); - }, - }; + return baseRule.create(context); }, });