UNPKG

eslint-plugin-sf-plugin

Version:
56 lines (55 loc) 2.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.noSfdxCommandImport = 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 eslint_utils_1 = require("@typescript-eslint/utils/eslint-utils"); const utils_1 = require("@typescript-eslint/utils"); const commands_1 = require("../../shared/commands"); exports.noSfdxCommandImport = eslint_utils_1.RuleCreator.withoutDocs({ meta: { docs: { description: 'Change import and base class from SfdxCommand to sfCommand', recommended: 'recommended', }, messages: { import: 'Use SfCommand from sf-plugins-core', superClass: 'Use SfCommand as the base class', }, type: 'problem', schema: [], fixable: 'code', }, defaultOptions: [], create(context) { return (0, commands_1.isInCommandDirectory)(context) ? { ClassDeclaration(node) { var _a; if (((_a = node.superClass) === null || _a === void 0 ? void 0 : _a.type) === utils_1.AST_NODE_TYPES.Identifier && node.superClass.name === 'SfdxCommand') { const fixTarget = node.superClass.range; context.report({ node: node.superClass, messageId: 'superClass', fix: (fixer) => fixer.replaceTextRange(fixTarget, 'SfCommand<unknown>'), }); } }, ImportDeclaration(node) { // verify it extends SfCommand if (node.source.value === '@salesforce/command') { context.report({ node, messageId: 'import', fix: (fixer) => fixer.replaceText(node, "import {Flags, SfCommand} from '@salesforce/sf-plugins-core';"), }); } }, } : {}; }, });