UNPKG

@atlaskit/eslint-plugin-design-system

Version:

The essential plugin for use with the Atlassian Design System.

51 lines (49 loc) 2.27 kB
import { isCssInJsTemplateNode } from './is-css-in-js-template-node'; var cssInJsCallees = ['css', 'styled', 'styled2']; export var isCssInJsCallNode = function isCssInJsCallNode(node) { return (node === null || node === void 0 ? void 0 : node.type) === 'CallExpression' && node.callee.type === 'Identifier' && cssInJsCallees.includes(node.callee.name); }; // eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports export var isCssInJsObjectNode = function isCssInJsObjectNode(node) { return (node === null || node === void 0 ? void 0 : node.type) === 'CallExpression' && node.callee.type === 'MemberExpression' && node.callee.object.type === 'Identifier' && cssInJsCallees.includes(node.callee.object.name); }; // eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports var _isDecendantOfStyleBlock = function isDecendantOfStyleBlock(node) { if (node.type === 'VariableDeclarator') { if (node.id.type !== 'Identifier') { return false; } if ( // @ts-ignore typeAnnotation is not defined by types node.id.typeAnnotation && // @ts-ignore typeAnnotation is not defined by types node.id.typeAnnotation.typeAnnotation.type === 'GenericTypeAnnotation' && // @ts-ignore typeAnnotation is not defined by types node.id.typeAnnotation.typeAnnotation.id.type === 'Identifier') { // @ts-ignore typeAnnotation is not defined by types var typeName = node.id.typeAnnotation.typeAnnotation.id.name; var hasCSSType = ['CSSProperties', 'CSSObject'].some(function (el) { return typeName.includes(el); }); if (hasCSSType) { return true; } } var varName = node.id.name.toLowerCase(); return ['style', 'css', 'theme'].some(function (el) { return varName.includes(el); }); } if (isCssInJsCallNode(node) || isCssInJsObjectNode(node) || isCssInJsTemplateNode(node)) { return true; } if (node.type === 'TaggedTemplateExpression' && node.tag.type === 'Identifier' && node.tag.name === 'css') { return true; } if (node.parent) { return _isDecendantOfStyleBlock(node.parent); } return false; }; export { _isDecendantOfStyleBlock as isDecendantOfStyleBlock }; export { isPropertyKey } from './is-property-key';