UNPKG

@atlaskit/eslint-plugin-design-system

Version:

The essential plugin for use with the Atlassian Design System.

48 lines (47 loc) 1.59 kB
import { isNodeOfType } from 'eslint-codemod-utils'; import { getSourceCode } from '@atlaskit/eslint-utils/context-compat'; import { getModuleOfIdentifier } from '../../utils/get-module-of-identifier'; import { blockedJSXAttributeLookup } from '../shared/blocked-jsx-attribute-lookup'; function getJSXElementNameFromAttribute(attribute) { const parent = attribute.parent; if (!parent) { return null; } if (!isNodeOfType(parent, 'JSXOpeningElement')) { return null; } const identifier = parent.name; if (!isNodeOfType(identifier, 'JSXIdentifier')) { return null; } return identifier.name; } function isOnIntrinsicJSXElement(attribute) { const name = getJSXElementNameFromAttribute(attribute); if (!name) { return false; } const firstLetter = name.at(0); if (!firstLetter) { return false; } return firstLetter === firstLetter.toLocaleLowerCase(); } function isOnBoxPrimitive(context, attribute) { if (getJSXElementNameFromAttribute(attribute) !== 'Box') { return false; } const module = getModuleOfIdentifier(getSourceCode(context), 'Box'); return (module === null || module === void 0 ? void 0 : module.moduleName) === '@atlaskit/primitives'; } export function isBlockedJSXAttribute(context, node) { const attributeName = node.name; if (!isNodeOfType(attributeName, 'JSXIdentifier')) { return false; } // not using a blocked attribute name, can continue on if (!blockedJSXAttributeLookup.has(attributeName.name)) { return false; } return isOnIntrinsicJSXElement(node) || isOnBoxPrimitive(context, node); }