UNPKG

eslint-plugin-sf-plugin

Version:
45 lines (44 loc) 1.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.commandExamples = 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 commands_1 = require("../shared/commands"); const eslint_utils_1 = require("@typescript-eslint/utils/eslint-utils"); const createRule = (0, eslint_utils_1.RuleCreator)((name) => `https://example.com/rule/${name}`); exports.commandExamples = createRule({ name: 'command-example', meta: { docs: { description: 'Ensure commands have a summary, description, and examples', recommended: 'stylistic', }, messages: { example: 'Commands should have an examples property', }, type: 'problem', schema: [], }, defaultOptions: [], create(context) { return (0, commands_1.isInCommandDirectory)(context) ? { ClassDeclaration(node) { // verify it extends SfCommand if ((0, commands_1.extendsSfCommand)(node, context) && node.id) { if (!node.body.body.some((member) => (0, commands_1.getClassPropertyIdentifierName)(member) === 'examples')) { context.report({ node: node.id, messageId: 'example', }); } } }, } : {}; }, });