UNPKG

@atlaskit/eslint-plugin-design-system

Version:

The essential plugin for use with the Atlassian Design System.

35 lines 1.14 kB
const getNodeValue = node => { var _node$value; switch (node.type) { case 'Identifier': return node.name; case 'Literal': return typeof node.value === 'string' ? node.value : null; case 'CallExpression': return node.callee.type === 'Identifier' ? node.callee.name : null; case 'JSXAttribute': return ((_node$value = node.value) === null || _node$value === void 0 ? void 0 : _node$value.type) === 'Literal' && typeof node.value.value === 'string' ? node.value.value : null; default: return null; } }; export const getIsException = exceptions => { if (!(exceptions !== null && exceptions !== void 0 && exceptions.length)) { return () => false; } const exceptionsSet = new Set(exceptions.map(x => x.toLowerCase())); const isException = node => { const value = getNodeValue(node); if (value) { const splitValues = value.split(/[-_\s]+/); if (splitValues.some(v => exceptionsSet.has(v.toLowerCase()))) { return true; } } if (node.parent) { return isException(node.parent); } return false; }; return isException; };