@atlaskit/eslint-plugin-design-system
Version:
The essential plugin for use with the Atlassian Design System.
41 lines • 1.6 kB
JavaScript
import { isCssInJsCallNode } from './is-css-in-js-call-node';
import { isCssInJsObjectNode } from './is-css-in-js-object-node';
import { isCssInJsTemplateNode } from './is-css-in-js-template-node';
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 };