eslint-plugin-sf-plugin
Version:
Helpful eslint rules for sf plugins.
52 lines (51 loc) • 2.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractMessageCommand = 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");
const propertiesYouShouldntHardCode = ['description', 'summary'];
exports.extractMessageCommand = eslint_utils_1.RuleCreator.withoutDocs({
meta: {
docs: {
description: 'Use loaded messages and separate files for messages',
recommended: 'stylistic',
},
messages: {
message: 'Summary/Description property should use messages.getMessage instead of hardcoding the message. See https://github.com/forcedotcom/sfdx-core/blob/v3/MIGRATING_V2-V3.md#messages',
},
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.body.body
.filter((prop) =>
// this could be `undefined` but that works okay with `.includes`
propertiesYouShouldntHardCode.includes((0, commands_1.getClassPropertyIdentifierName)(prop)))
.forEach((prop) => {
var _a;
if (prop.type === utils_1.AST_NODE_TYPES.PropertyDefinition && ((_a = prop.value) === null || _a === void 0 ? void 0 : _a.type) === utils_1.AST_NODE_TYPES.Literal) {
context.report({
node: prop,
messageId: 'message',
});
}
});
}
},
}
: {};
},
});