eslint-plugin-sf-plugin
Version:
Helpful eslint rules for sf plugins.
54 lines (53 loc) • 2.82 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.useSfCommandFlags = 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.useSfCommandFlags = eslint_utils_1.RuleCreator.withoutDocs({
meta: {
docs: {
description: 'Use Flags export from sf-plugins-core',
recommended: 'recommended',
},
messages: {
message: 'for SfCommand, each flag definition should use "Flags", not "flags"',
},
type: 'problem',
schema: [],
fixable: 'code',
},
defaultOptions: [],
create(context) {
return (0, commands_1.isInCommandDirectory)(context)
? {
Property(node) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
if (node.type === utils_1.AST_NODE_TYPES.Property &&
((_a = node.value) === null || _a === void 0 ? void 0 : _a.type) === utils_1.AST_NODE_TYPES.CallExpression &&
((_c = (_b = node.value) === null || _b === void 0 ? void 0 : _b.callee) === null || _c === void 0 ? void 0 : _c.type) === utils_1.AST_NODE_TYPES.MemberExpression &&
((_f = (_e = (_d = node.value) === null || _d === void 0 ? void 0 : _d.callee) === null || _e === void 0 ? void 0 : _e.object) === null || _f === void 0 ? void 0 : _f.type) === utils_1.AST_NODE_TYPES.Identifier &&
((_j = (_h = (_g = node.value) === null || _g === void 0 ? void 0 : _g.callee) === null || _h === void 0 ? void 0 : _h.object) === null || _j === void 0 ? void 0 : _j.name) === 'flags' &&
(0, commands_1.ancestorsContainsSfCommand)(context)) {
const range = node.value.callee.object.range;
context.report({
node,
messageId: 'message',
fix: (fixer) =>
// TS isn't using the type narrowing done above.
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore, eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-argument
fixer.replaceTextRange(range, 'Flags'),
});
}
},
}
: {};
},
});
;