eslint-plugin-sf-plugin
Version:
Helpful eslint rules for sf plugins.
53 lines (52 loc) • 2.48 kB
JavaScript
;
/*
* 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
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.noHyphenAliases = void 0;
const eslint_utils_1 = require("@typescript-eslint/utils/eslint-utils");
const utils_1 = require("@typescript-eslint/utils");
const commands_1 = require("../shared/commands");
const flags_1 = require("../shared/flags");
exports.noHyphenAliases = eslint_utils_1.RuleCreator.withoutDocs({
meta: {
docs: {
description: 'Mark when an alias starts with a hyphen, like -f or --foo',
recommended: 'recommended',
},
messages: {
summary: 'aliases should not start with hyphens',
},
type: 'problem',
schema: [],
fixable: 'code',
},
defaultOptions: [],
create(context) {
return (0, commands_1.isInCommandDirectory)(context)
? {
Literal(node) {
var _a, _b, _c, _d, _e, _f;
if (typeof node.value === 'string' &&
node.value.startsWith('-') &&
((_a = node.parent) === null || _a === void 0 ? void 0 : _a.type) === utils_1.AST_NODE_TYPES.ArrayExpression &&
((_b = node.parent.parent) === null || _b === void 0 ? void 0 : _b.type) === utils_1.AST_NODE_TYPES.Property &&
node.parent.parent.key.type === utils_1.AST_NODE_TYPES.Identifier &&
node.parent.parent.key.name === 'aliases' &&
((_d = (_c = node.parent.parent.parent) === null || _c === void 0 ? void 0 : _c.parent) === null || _d === void 0 ? void 0 : _d.parent) &&
(0, flags_1.isFlag)((_f = (_e = node.parent.parent.parent) === null || _e === void 0 ? void 0 : _e.parent) === null || _f === void 0 ? void 0 : _f.parent) &&
(0, commands_1.ancestorsContainsSfCommand)(context)) {
context.report({
node,
messageId: 'summary',
fix: (fixer) => fixer.replaceText(node, `'${node.value.replace(/^-+/, '')}'`),
});
}
},
}
: {};
},
});