UNPKG

eslint-plugin-sf-plugin

Version:
63 lines (62 loc) 3.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.noSplitExamples = 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.noSplitExamples = eslint_utils_1.RuleCreator.withoutDocs({ meta: { docs: { description: 'Arrays of messags should use getMessages instead of getMessage followed by EOL splitting', recommended: 'strict', }, messages: { message: 'use getMessages', }, type: 'problem', fixable: 'code', schema: [], }, defaultOptions: [], create(context) { return (0, commands_1.isInCommandDirectory)(context) ? { PropertyDefinition(node) { var _a, _b, _c; if (node.static && node.key.type === utils_1.AST_NODE_TYPES.Identifier && node.key.name === 'examples' && ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.type) === utils_1.AST_NODE_TYPES.ClassBody && ((_b = node.parent.parent) === null || _b === void 0 ? void 0 : _b.type) === utils_1.AST_NODE_TYPES.ClassDeclaration && ((_c = node.value) === null || _c === void 0 ? void 0 : _c.type) === utils_1.AST_NODE_TYPES.CallExpression && node.value.callee.type === utils_1.AST_NODE_TYPES.MemberExpression && node.value.callee.object.type === utils_1.AST_NODE_TYPES.CallExpression && node.value.callee.object.callee.type === utils_1.AST_NODE_TYPES.MemberExpression && node.value.callee.object.callee.property.type === utils_1.AST_NODE_TYPES.Identifier && node.value.callee.object.callee.property.name === 'getMessage' && node.value.callee.property.type === utils_1.AST_NODE_TYPES.Identifier && node.value.callee.property.name === 'split' && (0, commands_1.extendsSfCommand)(node.parent.parent, context)) { const target = node.value; const fixedText = context .getSourceCode() .getText(node.value) .replace('getMessage', 'getMessages') .replace(/\.split\(.*\)/, ''); context.report({ node: node.value.callee.property, messageId: 'message', fix: (fixer) => fixer.replaceText(target, fixedText), }); } }, } : {}; }, });