Server IP : 150.95.80.236 / Your IP : 18.217.40.118 Web Server : Apache System : Linux host-150-95-80-236 3.10.0-1160.105.1.el7.x86_64 #1 SMP Thu Dec 7 15:39:45 UTC 2023 x86_64 User : social-telecare ( 10000) PHP Version : 7.4.33 Disable Function : opcache_get_status MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/vhosts/pcu.in.th/api-uat.pcu.in.th/node_modules/eslint/lib/rules/ |
Upload File : |
/** * @fileoverview Rule to flag comparison where left part is the same as the right * part. * @author Ilya Volodin */ "use strict"; //------------------------------------------------------------------------------ // Rule Definition //------------------------------------------------------------------------------ /** @type {import('../shared/types').Rule} */ module.exports = { meta: { type: "problem", docs: { description: "Disallow comparisons where both sides are exactly the same", recommended: false, url: "https://eslint.org/docs/latest/rules/no-self-compare" }, schema: [], messages: { comparingToSelf: "Comparing to itself is potentially pointless." } }, create(context) { const sourceCode = context.sourceCode; /** * Determines whether two nodes are composed of the same tokens. * @param {ASTNode} nodeA The first node * @param {ASTNode} nodeB The second node * @returns {boolean} true if the nodes have identical token representations */ function hasSameTokens(nodeA, nodeB) { const tokensA = sourceCode.getTokens(nodeA); const tokensB = sourceCode.getTokens(nodeB); return tokensA.length === tokensB.length && tokensA.every((token, index) => token.type === tokensB[index].type && token.value === tokensB[index].value); } return { BinaryExpression(node) { const operators = new Set(["===", "==", "!==", "!=", ">", "<", ">=", "<="]); if (operators.has(node.operator) && hasSameTokens(node.left, node.right)) { context.report({ node, messageId: "comparingToSelf" }); } } }; } };