UNPKG

@atlaskit/eslint-plugin-design-system

Version:

The essential plugin for use with the Atlassian Design System.

62 lines (59 loc) 2.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isDecendantOfStyleBlock = exports.isCssInJsObjectNode = exports.isCssInJsCallNode = void 0; Object.defineProperty(exports, "isPropertyKey", { enumerable: true, get: function get() { return _isPropertyKey.isPropertyKey; } }); var _isCssInJsTemplateNode = require("./is-css-in-js-template-node"); var _isPropertyKey = require("./is-property-key"); var cssInJsCallees = ['css', 'styled', 'styled2']; var isCssInJsCallNode = exports.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 var isCssInJsObjectNode = exports.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 = exports.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) || (0, _isCssInJsTemplateNode.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; };