UNPKG

eslint-plugin-sf-plugin

Version:
69 lines (68 loc) 3.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.noUnnecessaryProperties = 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 falseProps = ['requiresProject', 'hidden']; const emptyProps = ['aliases']; exports.noUnnecessaryProperties = eslint_utils_1.RuleCreator.withoutDocs({ meta: { docs: { description: 'Boolean properties are false by default, so they should not be set to false', recommended: 'recommended', }, messages: { messageFalse: 'The {{prop}} property can be omitted since it is false by default', messageEmpty: 'The {{prop}} property can be omitted since it is empty', }, type: 'problem', fixable: 'code', schema: [], }, defaultOptions: [], create(context) { return (0, commands_1.isInCommandDirectory)(context) ? { PropertyDefinition(node) { var _a, _b, _c; if (node.static && ((_a = node.key) === null || _a === void 0 ? void 0 : _a.type) === utils_1.AST_NODE_TYPES.Identifier && ((_b = node.parent) === null || _b === void 0 ? void 0 : _b.type) === utils_1.AST_NODE_TYPES.ClassBody && ((_c = node.parent.parent) === null || _c === void 0 ? void 0 : _c.type) === utils_1.AST_NODE_TYPES.ClassDeclaration && node.value && (0, commands_1.extendsSfCommand)(node.parent.parent, context)) { // properties that default to false if (node.value.type === utils_1.AST_NODE_TYPES.Literal && falseProps.includes(node.key.name) && node.value.value === false) { context.report({ node, messageId: 'messageFalse', data: { prop: node.key.name }, fix: (fixer) => fixer.remove(node), }); } // properties that default to emptyArrays if (node.value.type === utils_1.AST_NODE_TYPES.ArrayExpression && emptyProps.includes(node.key.name) && node.value.elements.length === 0) { context.report({ node, messageId: 'messageEmpty', data: { prop: node.key.name }, fix: (fixer) => fixer.remove(node), }); } } }, } : {}; }, });