????JFIF??x?x????'
Server IP : 79.136.114.73 / Your IP : 3.23.61.129 Web Server : Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.29 OpenSSL/1.0.1f System : Linux b8009 3.13.0-170-generic #220-Ubuntu SMP Thu May 9 12:40:49 UTC 2019 x86_64 User : www-data ( 33) PHP Version : 5.5.9-1ubuntu4.29 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/appsrv.astacus.se/forge/node_modules/eslint/lib/rules/ |
Upload File : |
/** * @fileoverview Rule to require object keys to be sorted * @author Toru Nagashima */ "use strict"; //------------------------------------------------------------------------------ // Requirements //------------------------------------------------------------------------------ const astUtils = require("../util/ast-utils"), naturalCompare = require("natural-compare"); //------------------------------------------------------------------------------ // Helpers //------------------------------------------------------------------------------ /** * Gets the property name of the given `Property` node. * * - If the property's key is an `Identifier` node, this returns the key's name * whether it's a computed property or not. * - If the property has a static name, this returns the static name. * - Otherwise, this returns null. * * @param {ASTNode} node - The `Property` node to get. * @returns {string|null} The property name or null. * @private */ function getPropertyName(node) { return astUtils.getStaticPropertyName(node) || node.key.name || null; } /** * Functions which check that the given 2 names are in specific order. * * Postfix `I` is meant insensitive. * Postfix `N` is meant natual. * * @private */ const isValidOrders = { asc(a, b) { return a <= b; }, ascI(a, b) { return a.toLowerCase() <= b.toLowerCase(); }, ascN(a, b) { return naturalCompare(a, b) <= 0; }, ascIN(a, b) { return naturalCompare(a.toLowerCase(), b.toLowerCase()) <= 0; }, desc(a, b) { return isValidOrders.asc(b, a); }, descI(a, b) { return isValidOrders.ascI(b, a); }, descN(a, b) { return isValidOrders.ascN(b, a); }, descIN(a, b) { return isValidOrders.ascIN(b, a); } }; //------------------------------------------------------------------------------ // Rule Definition //------------------------------------------------------------------------------ module.exports = { meta: { type: "suggestion", docs: { description: "require object keys to be sorted", category: "Stylistic Issues", recommended: false, url: "https://eslint.org/docs/rules/sort-keys" }, schema: [ { enum: ["asc", "desc"] }, { type: "object", properties: { caseSensitive: { type: "boolean", default: true }, natural: { type: "boolean", default: false } }, additionalProperties: false } ] }, create(context) { // Parse options. const order = context.options[0] || "asc"; const options = context.options[1]; const insensitive = options && options.caseSensitive === false; const natual = options && options.natural; const isValidOrder = isValidOrders[ order + (insensitive ? "I" : "") + (natual ? "N" : "") ]; // The stack to save the previous property's name for each object literals. let stack = null; return { ObjectExpression() { stack = { upper: stack, prevName: null }; }, "ObjectExpression:exit"() { stack = stack.upper; }, SpreadElement(node) { if (node.parent.type === "ObjectExpression") { stack.prevName = null; } }, Property(node) { if (node.parent.type === "ObjectPattern") { return; } const prevName = stack.prevName; const thisName = getPropertyName(node); stack.prevName = thisName || prevName; if (!prevName || !thisName) { return; } if (!isValidOrder(prevName, thisName)) { context.report({ node, loc: node.key.loc, message: "Expected object keys to be in {{natual}}{{insensitive}}{{order}}ending order. '{{thisName}}' should be before '{{prevName}}'.", data: { thisName, prevName, order, insensitive: insensitive ? "insensitive " : "", natual: natual ? "natural " : "" } }); } } }; } };