eslint-plugin-sf-plugin
Version:
Helpful eslint rules for sf plugins.
64 lines (63 loc) • 3.74 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.spreadBaseFlags = 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 flags_1 = require("../shared/flags");
exports.spreadBaseFlags = eslint_utils_1.RuleCreator.withoutDocs({
meta: {
docs: {
description: "When not directly extending SfCommand, the parent's flags must be spread like flags = { ...{{parent}}.{{property}} }",
recommended: 'recommended',
},
messages: {
message: "When not directly extending SfCommand, the parent's flags must be spread like flags = { ...{{parent}}.{{property}} }",
},
type: 'problem',
schema: [],
},
defaultOptions: [],
create(context) {
return (0, commands_1.isInCommandDirectory)(context)
? {
ClassDeclaration(node) {
var _a, _b, _c, _d, _e, _f;
const flagsProperty = (0, flags_1.getFlagsStaticPropertyFromCommandClass)(node);
if (flagsProperty) {
// @ts-ignore SpreadElement (...) on property==='flags' (BaseCommand.flags)
const flags = (_b = (_a = flagsProperty === null || flagsProperty === void 0 ? void 0 : flagsProperty.value) === null || _a === void 0 ? void 0 : _a.properties) === null || _b === void 0 ? void 0 : _b.find((f) => { var _a; return f.type === 'SpreadElement' && ((_a = f.argument.property) === null || _a === void 0 ? void 0 : _a.name) === 'flags'; });
// @ts-ignore name will not be undefined because we're in a command class, which has to at least extend Command
const parent = (_c = node.superClass) === null || _c === void 0 ? void 0 : _c.name;
if (parent !== 'SfCommand' && !flags) {
context.report({
loc: flagsProperty.loc,
messageId: 'message',
data: { parent, property: 'flags' },
});
}
}
const baseFlagsProperty = (0, flags_1.getBaseFlagsStaticPropertyFromCommandClass)(node);
if (baseFlagsProperty) {
// @ts-ignore SpreadElement (...) on property==='baseFlags' (BaseCommand.baseFlags)
const baseFlags = (_e = (_d = baseFlagsProperty.value) === null || _d === void 0 ? void 0 : _d.properties) === null || _e === void 0 ? void 0 : _e.find((f) => { var _a; return f.type === 'SpreadElement' && ((_a = f.argument.property) === null || _a === void 0 ? void 0 : _a.name) === 'baseFlags'; });
// @ts-ignore name will not be undefined because we're in a command class, which has to at least extend Command
const parent = (_f = node.superClass) === null || _f === void 0 ? void 0 : _f.name;
if (parent !== 'SfCommand' && !baseFlags) {
context.report({
loc: baseFlagsProperty.loc,
messageId: 'message',
data: { parent, property: 'baseFlags' },
});
}
}
},
}
: {};
},
});