diff --git a/tools/eslint-rules/no-duplicate-requires.js b/tools/eslint-rules/no-duplicate-requires.js index 05a379eba673c9..8c4b7a4c273457 100644 --- a/tools/eslint-rules/no-duplicate-requires.js +++ b/tools/eslint-rules/no-duplicate-requires.js @@ -4,17 +4,13 @@ */ 'use strict'; -const { isRequireCall } = require('./rules-utils.js'); +const { isRequireCall, isString } = require('./rules-utils.js'); //------------------------------------------------------------------------------ // Rule Definition //------------------------------------------------------------------------------ -function isString(node) { - return node && node.type === 'Literal' && typeof node.value === 'string'; -} - function isTopLevel(node) { do { if (node.type === 'FunctionDeclaration' || diff --git a/tools/eslint-rules/require-common-first.js b/tools/eslint-rules/require-common-first.js index 2b04a98d9f4bc3..4096ee27710781 100644 --- a/tools/eslint-rules/require-common-first.js +++ b/tools/eslint-rules/require-common-first.js @@ -4,7 +4,7 @@ 'use strict'; const path = require('path'); -const { isRequireCall } = require('./rules-utils.js'); +const { isRequireCall, isString } = require('./rules-utils.js'); //------------------------------------------------------------------------------ // Rule Definition @@ -15,15 +15,6 @@ module.exports = function(context) { const isESM = context.parserOptions.sourceType === 'module'; const foundModules = []; - /** - * Function to check if a node is a string literal. - * @param {ASTNode} node The node to check. - * @returns {boolean} If the node is a string literal. - */ - function isString(node) { - return node && node.type === 'Literal' && typeof node.value === 'string'; - } - /** * Function to check if the path is a module and return its name. * @param {String} str The path to check diff --git a/tools/eslint-rules/required-modules.js b/tools/eslint-rules/required-modules.js index 40cb8e46e57f02..06c998c7f5a182 100644 --- a/tools/eslint-rules/required-modules.js +++ b/tools/eslint-rules/required-modules.js @@ -4,7 +4,7 @@ */ 'use strict'; -const { isRequireCall } = require('./rules-utils.js'); +const { isRequireCall, isString } = require('./rules-utils.js'); //------------------------------------------------------------------------------ // Rule Definition @@ -25,15 +25,6 @@ module.exports = function(context) { return {}; } - /** - * Function to check if a node is a string literal. - * @param {ASTNode} node The node to check. - * @returns {boolean} If the node is a string literal. - */ - function isString(node) { - return node && node.type === 'Literal' && typeof node.value === 'string'; - } - /** * Function to check if the path is a required module and return its name. * @param {String} str The path to check diff --git a/tools/eslint-rules/rules-utils.js b/tools/eslint-rules/rules-utils.js index 713a49bf7aa183..462ab7c2ff3ab8 100644 --- a/tools/eslint-rules/rules-utils.js +++ b/tools/eslint-rules/rules-utils.js @@ -8,6 +8,10 @@ function isRequireCall(node) { } module.exports.isRequireCall = isRequireCall; +module.exports.isString = function(node) { + return node && node.type === 'Literal' && typeof node.value === 'string'; +}; + module.exports.isDefiningError = function(node) { return node.expression && node.expression.type === 'CallExpression' &&