UNPKG

eslint-plugin-sf-plugin

Version:
59 lines (58 loc) 2.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.sfdxFlagsProperty = 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.sfdxFlagsProperty = eslint_utils_1.RuleCreator.withoutDocs({ meta: { docs: { description: 'Change flag definitions to SfCommand version', recommended: 'recommended', }, messages: { flagsConfig: 'Use public readonly static flags = {', flagsConfigType: 'The FlagsConfig type is not used by SfCommand', }, type: 'problem', schema: [], fixable: 'code', }, defaultOptions: [], create(context) { return (0, commands_1.isInCommandDirectory)(context) ? { PropertyDefinition(node) { var _a, _b, _c; if ((0, commands_1.ancestorsContainsSfCommand)(context)) { if (node.key.type === utils_1.AST_NODE_TYPES.Identifier && node.key.name === 'flagsConfig') { context.report({ node, messageId: 'flagsConfig', fix: (fixer) => fixer.replaceTextRange(node.key.range, 'flags'), }); } if (node.key.type === utils_1.AST_NODE_TYPES.Identifier && ((_a = node.typeAnnotation) === null || _a === void 0 ? void 0 : _a.type) === utils_1.AST_NODE_TYPES.TSTypeAnnotation && ((_b = node.typeAnnotation.typeAnnotation) === null || _b === void 0 ? void 0 : _b.type) === utils_1.AST_NODE_TYPES.TSTypeReference && ((_c = node.typeAnnotation.typeAnnotation.typeName) === null || _c === void 0 ? void 0 : _c.type) === utils_1.AST_NODE_TYPES.Identifier && node.typeAnnotation.typeAnnotation.typeName.name === 'FlagsConfig') { const toRemove = node.typeAnnotation; context.report({ node, messageId: 'flagsConfigType', fix: (fixer) => fixer.remove(toRemove), }); } } }, } : {}; }, });