@atlaskit/eslint-plugin-design-system
Version:
The essential plugin for use with the Atlassian Design System.
46 lines (45 loc) • 1.65 kB
JavaScript
/* 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 var UntokenizedProperties = {
lint: function lint(node, _ref) {
var context = _ref.context,
config = _ref.config;
// Check whether all criteria needed to make a transformation are met
var success = UntokenizedProperties._check(node, {
context: context,
config: config
});
if (success) {
return context.report({
node: node,
messageId: 'noUntokenizedProperties',
data: {
property: isNodeOfType(node.key, 'Identifier') ? node.key.name : 'this property'
}
});
}
},
_check: function _check(node, _ref2) {
var config = _ref2.config,
context = _ref2.context;
if (!config.patterns.includes('untokenized-properties')) {
return false;
}
if (!isNodeOfType(node, 'Property')) {
return false;
}
if (!isDecendantOfStyleBlock(node) && !isDecendantOfType(node, 'JSXExpressionContainer')) {
return false;
}
var isFontProperty = isNodeOfType(node.key, 'Identifier') && node.key.name === 'font';
var valueNodeSource = getNodeSource(getSourceCode(context), node.value);
if (isFontProperty && valueNodeSource.match(/(font\.(body|heading|code)|inherit)/)) {
return false;
}
return true;
}
};