eslint-plugin-sf-plugin
Version:
Helpful eslint rules for sf plugins.
55 lines (54 loc) • 2.52 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.commandSummary = 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 utils_1 = require("@typescript-eslint/utils");
const eslint_utils_1 = require("@typescript-eslint/utils/eslint-utils");
const commands_1 = require("../shared/commands");
exports.commandSummary = eslint_utils_1.RuleCreator.withoutDocs({
meta: {
docs: {
description: 'Ensure commands have a summary',
recommended: 'recommended',
},
messages: {
summary: 'Commands should have a summary property',
},
type: 'problem',
fixable: 'code',
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) === 'summary')) {
const descriptionNode = node.body.body.find((member) => (0, commands_1.getClassPropertyIdentifierName)(member) === 'description');
context.report({
node: node.id,
messageId: 'summary',
// if you have a description, create a summary property with the same value
...(descriptionNode && descriptionNode.type === utils_1.AST_NODE_TYPES.PropertyDefinition
? {
fix: (fixer) => fixer.insertTextBefore(descriptionNode, `public static readonly summary = ${context
.getSourceCode()
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
.getText(descriptionNode.value)};`),
}
: {}),
});
}
}
},
}
: {};
},
});
;