UNPKG

eslint-plugin-sf-plugin

Version:
56 lines (55 loc) 2.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.dashO = void 0; /* * Copyright (c) 2020, salesforce.com, inc. * All rights reserved. * Licensed under the BSD 3-Clause license. * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ const utils_1 = require("@typescript-eslint/utils"); const eslint_utils_1 = require("@typescript-eslint/utils/eslint-utils"); const commands_1 = require("../shared/commands"); const flags_1 = require("../shared/flags"); exports.dashO = eslint_utils_1.RuleCreator.withoutDocs({ meta: { docs: { description: 'Warn on a flag that uses -o', recommended: 'strict', }, messages: { message: '-o is usually used by target-org. For consistency, choose a different short character if you plan to connect to an org', }, type: 'problem', schema: [], }, defaultOptions: [], create(context) { return (0, commands_1.isInCommandDirectory)(context) ? { Property(node) { var _a, _b, _c, _d; // is a flag if ((0, flags_1.isFlag)(node) && (0, commands_1.ancestorsContainsSfCommand)(context) && ((_a = node.value) === null || _a === void 0 ? void 0 : _a.type) === utils_1.AST_NODE_TYPES.CallExpression && ((_b = node.value.callee) === null || _b === void 0 ? void 0 : _b.type) === utils_1.AST_NODE_TYPES.MemberExpression && node.value.callee.property.type === utils_1.AST_NODE_TYPES.Identifier && !node.value.callee.property.name.toLowerCase().includes('org') && !node.value.callee.property.name.toLowerCase().includes('hub') && ((_d = (_c = node.value.arguments) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.type) === utils_1.AST_NODE_TYPES.ObjectExpression) { const hChar = node.value.arguments[0].properties .filter((0, flags_1.flagPropertyIsNamed)('char')) .find((property) => property.value.type === utils_1.AST_NODE_TYPES.Literal && property.value.value === 'o'); if (hChar) { context.report({ node: hChar, messageId: 'message', }); } } }, } : {}; }, });