UNPKG

@atlaskit/eslint-plugin-design-system

Version:

The essential plugin for use with the Atlassian Design System.

48 lines (47 loc) 1.53 kB
/* eslint-disable @repo/internal/react/require-jsdoc */ import { isNodeOfType } from 'eslint-codemod-utils'; import { getSourceCode } from '@atlaskit/eslint-utils/context-compat'; import { getNodeSource } from '../../utils/get-node-source'; import { isDecendantOfStyleBlock } from '../../utils/is-decendant-of-style-block'; import { isDecendantOfType } from '../../utils/is-decendant-of-type'; export const UntokenizedProperties = { lint(node, { context, config }) { // Check whether all criteria needed to make a transformation are met const success = UntokenizedProperties._check(node, { context, config }); if (success) { return context.report({ node, messageId: 'noUntokenizedProperties', data: { property: isNodeOfType(node.key, 'Identifier') ? node.key.name : 'this property' } }); } }, _check(node, { config, context }) { if (!config.patterns.includes('untokenized-properties')) { return false; } if (!isNodeOfType(node, 'Property')) { return false; } if (!isDecendantOfStyleBlock(node) && !isDecendantOfType(node, 'JSXExpressionContainer')) { return false; } const isFontProperty = isNodeOfType(node.key, 'Identifier') && node.key.name === 'font'; const valueNodeSource = getNodeSource(getSourceCode(context), node.value); if (isFontProperty && valueNodeSource.match(/(font\.(body|heading|code)|inherit)/)) { return false; } return true; } };