UNPKG

eslint-plugin-sf-plugin

Version:
73 lines (72 loc) 3.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.noOclifFlagsCommandImport = 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 commands_1 = require("../shared/commands"); exports.noOclifFlagsCommandImport = eslint_utils_1.RuleCreator.withoutDocs({ meta: { docs: { description: 'Change import of flags and Command from oclif to use sf-plugins-core', recommended: 'recommended', }, messages: { flags: 'Use Flags from sf-plugins-core', command: 'Use SfCommand from sf-plugins-core', empty: 'no empty imports', }, type: 'problem', schema: [], fixable: 'code', }, defaultOptions: [], create(context) { return (0, commands_1.isInCommandDirectory)(context) ? { ImportDeclaration(node) { // verify it extends SfCommand if (node.source.value === '@oclif/core') { node.specifiers.forEach((specifier) => { if (specifier.local.name === 'Flags') { context.report({ node: specifier, messageId: 'flags', fix: (fixer) => { const comma = context.sourceCode.getTokenAfter(specifier); return (comma === null || comma === void 0 ? void 0 : comma.value) === ',' ? fixer.removeRange([specifier.range[0], specifier.range[1] + 1]) : fixer.remove(specifier); }, }); } if (specifier.local.name === 'Command') { context.report({ node: specifier, messageId: 'command', fix: (fixer) => { const comma = context.sourceCode.getTokenAfter(specifier); return (comma === null || comma === void 0 ? void 0 : comma.value) === ',' ? fixer.removeRange([specifier.range[0], specifier.range[1] + 1]) : fixer.remove(specifier); }, }); } }); if (node.specifiers.length === 0) { context.report({ node, messageId: 'empty', fix: (fixer) => fixer.remove(node), }); } } }, } : {}; }, });