UNPKG

eslint-plugin-sf-plugin

Version:
64 lines (63 loc) 3.26 kB
"use strict"; /* * 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 */ Object.defineProperty(exports, "__esModule", { value: true }); exports.noUnnecessaryAliases = void 0; const eslint_utils_1 = require("@typescript-eslint/utils/eslint-utils"); const utils_1 = require("@typescript-eslint/utils"); const commands_1 = require("../shared/commands"); exports.noUnnecessaryAliases = eslint_utils_1.RuleCreator.withoutDocs({ meta: { docs: { description: 'Mark when an alias is unnecessary because its only an order permutation, not really a different name', recommended: 'recommended', }, messages: { summary: 'the Salesforce CLI will match the command words in any order, so this alias is unnecessary', }, type: 'problem', schema: [], fixable: 'code', }, defaultOptions: [], create(context) { return (0, commands_1.isInCommandDirectory)(context) ? { Literal(node) { var _a, _b; if (((_a = node.parent) === null || _a === void 0 ? void 0 : _a.type) === utils_1.AST_NODE_TYPES.ArrayExpression && ((_b = node.parent.parent) === null || _b === void 0 ? void 0 : _b.type) === utils_1.AST_NODE_TYPES.PropertyDefinition && node.parent.parent.key.type === utils_1.AST_NODE_TYPES.Identifier && node.parent.parent.key.name === 'aliases' && context.getPhysicalFilename && (0, commands_1.ancestorsContainsSfCommand)(context)) { const parentLength = node.parent.elements.length; const cmdParts = (0, commands_1.getCommandNameParts)(context.getPhysicalFilename()); const aliasParts = typeof node.value === 'string' ? node.value.split(':') : []; if (aliasParts.every((part) => cmdParts.includes(part)) && cmdParts.every((part) => aliasParts.includes(part))) { context.report({ node, messageId: 'summary', fix: (fixer) => { var _a; const comma = context.sourceCode.getTokenAfter(node); if (parentLength === 1 && ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.parent)) { return fixer.remove(node.parent.parent); } return (comma === null || comma === void 0 ? void 0 : comma.value) === ',' ? fixer.removeRange([node.range[0], node.range[1] + 1]) : fixer.remove(node); }, }); } } }, } : {}; }, });