eslint-plugin-sf-plugin
Version:
Helpful eslint rules for sf plugins.
52 lines (51 loc) • 2.23 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.dashH = 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");
const flags_1 = require("../shared/flags");
exports.dashH = eslint_utils_1.RuleCreator.withoutDocs({
meta: {
docs: {
description: 'Do not allow creation of a flag with short char -h',
recommended: 'recommended',
},
messages: {
message: '-h is reserved for help. Choose a different short character',
},
type: 'problem',
schema: [],
},
defaultOptions: [],
create(context) {
return (0, commands_1.isInCommandDirectory)(context)
? {
Property(node) {
var _a, _b, _c;
// is a flag
if ((0, flags_1.isFlag)(node) &&
(0, commands_1.ancestorsContainsSfCommand)(context) &&
((_a = node.value) === null || _a === void 0 ? void 0 : _a.type) === utils_1.AST_NODE_TYPES.CallExpression &&
((_c = (_b = node.value.arguments) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.type) === utils_1.AST_NODE_TYPES.ObjectExpression) {
const hChar = node.value.arguments[0].properties
.filter((0, flags_1.flagPropertyIsNamed)('char'))
.find((property) => property.value.type === utils_1.AST_NODE_TYPES.Literal && property.value.value === 'h');
if (hChar) {
context.report({
node: hChar,
messageId: 'message',
});
}
}
},
}
: {};
},
});
;