@atlaskit/eslint-plugin-design-system
Version:
The essential plugin for use with the Atlassian Design System.
54 lines (52 loc) • 1.86 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isBlockedJSXAttribute = isBlockedJSXAttribute;
var _eslintCodemodUtils = require("eslint-codemod-utils");
var _contextCompat = require("@atlaskit/eslint-utils/context-compat");
var _getModuleOfIdentifier = require("../../utils/get-module-of-identifier");
var _blockedJsxAttributeLookup = require("../shared/blocked-jsx-attribute-lookup");
function getJSXElementNameFromAttribute(attribute) {
var parent = attribute.parent;
if (!parent) {
return null;
}
if (!(0, _eslintCodemodUtils.isNodeOfType)(parent, 'JSXOpeningElement')) {
return null;
}
var identifier = parent.name;
if (!(0, _eslintCodemodUtils.isNodeOfType)(identifier, 'JSXIdentifier')) {
return null;
}
return identifier.name;
}
function isOnIntrinsicJSXElement(attribute) {
var name = getJSXElementNameFromAttribute(attribute);
if (!name) {
return false;
}
var firstLetter = name.at(0);
if (!firstLetter) {
return false;
}
return firstLetter === firstLetter.toLocaleLowerCase();
}
function isOnBoxPrimitive(context, attribute) {
if (getJSXElementNameFromAttribute(attribute) !== 'Box') {
return false;
}
var module = (0, _getModuleOfIdentifier.getModuleOfIdentifier)((0, _contextCompat.getSourceCode)(context), 'Box');
return (module === null || module === void 0 ? void 0 : module.moduleName) === '@atlaskit/primitives';
}
function isBlockedJSXAttribute(context, node) {
var attributeName = node.name;
if (!(0, _eslintCodemodUtils.isNodeOfType)(attributeName, 'JSXIdentifier')) {
return false;
}
// not using a blocked attribute name, can continue on
if (!_blockedJsxAttributeLookup.blockedJSXAttributeLookup.has(attributeName.name)) {
return false;
}
return isOnIntrinsicJSXElement(node) || isOnBoxPrimitive(context, node);
}