Constnium/node_modules/eslint-plugin-es/lib/rules/no-numeric-separators.js

53 lines
1.4 KiB
JavaScript
Raw Normal View History

2022-06-23 02:27:43 +02:00
/**
* @author Yosuke Ota
* See LICENSE file in root directory for full license.
*/
"use strict"
/**
* Remove the numeric separators.
* @param {string} raw The raw string of numeric literals
* @returns {string} The string with the separators removed.
*/
function removeNumericSeparators(raw) {
return raw.replace(/_/gu, "")
}
module.exports = {
meta: {
docs: {
description: "disallow numeric separators.",
category: "ES2021",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-numeric-separators.html",
},
fixable: "code",
messages: {
forbidden: "ES2021 numeric separators are forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
Literal(node) {
if (
(typeof node.value === "number" || node.bigint != null) &&
node.raw.includes("_")
) {
context.report({
node,
messageId: "forbidden",
fix: fixer =>
fixer.replaceText(
node,
removeNumericSeparators(node.raw)
),
})
}
},
}
},
}