⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.1
Server IP:
185.238.29.86
Server:
Linux server2 6.8.12-6-pve #1 SMP PREEMPT_DYNAMIC PMX 6.8.12-6 (2024-12-19T19:05Z) x86_64
Server Software:
nginx/1.18.0
PHP Version:
8.1.31
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
var
/
www
/
invoice
/
node_modules
/
eslint
/
lib
/
rules
/
Edit File: valid-typeof.js
/** * @fileoverview Ensures that the results of typeof are compared against a valid string * @author Ian Christian Myers */ "use strict"; //------------------------------------------------------------------------------ // Rule Definition //------------------------------------------------------------------------------ module.exports = { meta: { type: "problem", docs: { description: "enforce comparing `typeof` expressions against valid strings", category: "Possible Errors", recommended: true, url: "https://eslint.org/docs/rules/valid-typeof" }, schema: [ { type: "object", properties: { requireStringLiterals: { type: "boolean", default: false } }, additionalProperties: false } ], messages: { invalidValue: "Invalid typeof comparison value.", notString: "Typeof comparisons should be to string literals." } }, create(context) { const VALID_TYPES = ["symbol", "undefined", "object", "boolean", "number", "string", "function", "bigint"], OPERATORS = ["==", "===", "!=", "!=="]; const requireStringLiterals = context.options[0] && context.options[0].requireStringLiterals; /** * Determines whether a node is a typeof expression. * @param {ASTNode} node The node * @returns {boolean} `true` if the node is a typeof expression */ function isTypeofExpression(node) { return node.type === "UnaryExpression" && node.operator === "typeof"; } //-------------------------------------------------------------------------- // Public //-------------------------------------------------------------------------- return { UnaryExpression(node) { if (isTypeofExpression(node)) { const parent = context.getAncestors().pop(); if (parent.type === "BinaryExpression" && OPERATORS.indexOf(parent.operator) !== -1) { const sibling = parent.left === node ? parent.right : parent.left; if (sibling.type === "Literal" || sibling.type === "TemplateLiteral" && !sibling.expressions.length) { const value = sibling.type === "Literal" ? sibling.value : sibling.quasis[0].value.cooked; if (VALID_TYPES.indexOf(value) === -1) { context.report({ node: sibling, messageId: "invalidValue" }); } } else if (requireStringLiterals && !isTypeofExpression(sibling)) { context.report({ node: sibling, messageId: "notString" }); } } } } }; } };
Simpan