@atlaskit/eslint-plugin-design-system
Version:
The essential plugin for use with the Atlassian Design System.
37 lines (36 loc) • 1.04 kB
JavaScript
import { isNodeOfType } from 'eslint-codemod-utils';
import { validPrimitiveElements } from './valid-primitive-elements';
var getChildrenByType = function getChildrenByType(node, types) {
return node.children.filter(function (child) {
return types.find(function (type) {
return isNodeOfType(child, type);
});
});
};
var isValidPrimitiveElement = function isValidPrimitiveElement(node) {
return validPrimitiveElements.has(node.openingElement.name.name);
};
export var 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;
};