eslint-plugin-sf-plugin
Version:
Helpful eslint rules for sf plugins.
49 lines (48 loc) • 2.07 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.getConnectionWithVersion = 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.getConnectionWithVersion = eslint_utils_1.RuleCreator.withoutDocs({
meta: {
docs: {
description: 'Calls to getConnection should pass in a version',
recommended: 'stylistic',
},
messages: {
addVersion: `getConnection should pass in a version, typically from the api-version flag,
even if that value may be undefined.
Otherwise, the org will default to its maximum version`,
},
type: 'problem',
schema: [],
},
defaultOptions: [],
create(context) {
return (0, commands_1.isInCommandDirectory)(context)
? {
CallExpression(node) {
var _a, _b;
if (node.type === utils_1.AST_NODE_TYPES.CallExpression &&
node.arguments.length === 0 &&
((_a = node.callee) === null || _a === void 0 ? void 0 : _a.type) === utils_1.AST_NODE_TYPES.MemberExpression &&
node.callee.property.type === utils_1.AST_NODE_TYPES.Identifier &&
((_b = node.callee.property) === null || _b === void 0 ? void 0 : _b.name) === 'getConnection' &&
(0, commands_1.ancestorsContainsSfCommand)(context)) {
context.report({
node: node.callee.property,
messageId: 'addVersion',
});
}
},
}
: {};
},
});
;