UNPKG

@atlaskit/eslint-plugin-design-system

Version:

The essential plugin for use with the Atlassian Design System.

43 lines (41 loc) 1.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.shouldSuggest = void 0; var _eslintCodemodUtils = require("eslint-codemod-utils"); var _validPrimitiveElements = require("./valid-primitive-elements"); var getChildrenByType = function getChildrenByType(node, types) { return node.children.filter(function (child) { return types.find(function (type) { return (0, _eslintCodemodUtils.isNodeOfType)(child, type); }); }); }; var isValidPrimitiveElement = function isValidPrimitiveElement(node) { return _validPrimitiveElements.validPrimitiveElements.has(node.openingElement.name.name); }; var shouldSuggest = exports.shouldSuggest = function shouldSuggest(node) { if (!node) { return false; } if (!isValidPrimitiveElement(node)) { return false; } /** * Ignore text, check for things like: * ``` * <div> * <h2>heading</h2> * subheading <= rejected because of standalone piece of text * </div> * ``` */ var nonWhiteSpaceTextChildren = getChildrenByType(node, ['JSXText']).filter(function (child) { return child.value.trim() !== ''; }); if (nonWhiteSpaceTextChildren.length > 0) { return false; } return true; };