Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
Closed
Description
Before You File a Bug Report Please Confirm You Have Done The Following...
- I have tried restarting my IDE and the issue persists.
- I have updated to the latest version of the packages.
- I havesearched for related issues and found none that matched my issue.
- I haveread the FAQ and my problem is not listed.
Playground Link
Repro Code
exporttypeOneOrTwo=1|2;
ESLint Config
{"plugin":["@typescript-eslint"],"rules":{"@typescript-eslint/no-magic-numbers":["warn",{"ignore":[1,2]}]}}
tsconfig
No response
Expected Result
I expected that because the numeric literals 1 and 2 are in the "ignore" setting of the "no-magic-numbers" rule, they would not be reported as magic numbers.
Actual Result
The numeric literals 1 and 2 are reported as magic numbers, despite the rule being configured to ignore them.
Additional Info
Here's a patch:
diff --git a/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-magic-numbers.js b/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-magic-numbers.jsindex 07b7055..c5b6014 100644--- a/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-magic-numbers.js+++ b/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-magic-numbers.js@@ -25,6 +25,17 @@ Array.isArray(baseRule.meta.schema) }, }, });+/**+ * Convert the value to bigint if it's a string. Otherwise return the value as-is.+ * @param {bigint|number|string} x The value to normalize.+ * @returns {bigint|number} The normalized value.+ */+function normalizeIgnoreValue(x) {+ if (typeof x === "string") {+ return BigInt(x.slice(0, -1));+ }+ return x;+} exports.default = (0, util_1.createRule)({ name: 'no-magic-numbers', meta: {@@ -49,6 +60,7 @@ exports.default = (0, util_1.createRule)({ ], create(context, [options]) { const rules = baseRule.create(context);+ const ignore = new Set((options.ignore || []).map(normalizeIgnoreValue)); return { Literal(node) { // If it’s not a numeric literal we’re not interested@@ -76,6 +88,10 @@ exports.default = (0, util_1.createRule)({ else if (isParentTSReadonlyPropertyDefinition(node)) { isAllowed = options.ignoreReadonlyClassProperties === true; }+ // Check if the value is allowed+ if (ignore.has(node.value)) {+ isAllowed = true;+ } // If we’ve hit a case where the ignore option is true we can return now if (isAllowed === true) { return;