@atlaskit/eslint-plugin-design-system
Version:
The essential plugin for use with the Atlassian Design System.
33 lines (32 loc) • 913 B
JavaScript
import { isNodeOfType } from 'eslint-codemod-utils';
import { validPrimitiveElements } from './valid-primitive-elements';
const getChildrenByType = (node, types) => {
return node.children.filter(child => {
return types.find(type => isNodeOfType(child, type));
});
};
const isValidPrimitiveElement = node => {
return validPrimitiveElements.has(node.openingElement.name.name);
};
export const 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>
* ```
*/
const nonWhiteSpaceTextChildren = getChildrenByType(node, ['JSXText']).filter(child => child.value.trim() !== '');
if (nonWhiteSpaceTextChildren.length > 0) {
return false;
}
return true;
};