UNPKG

@atlaskit/eslint-plugin-design-system

Version:

The essential plugin for use with the Atlassian Design System.

52 lines (50 loc) 1.97 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.UntokenizedProperties = void 0; var _eslintCodemodUtils = require("eslint-codemod-utils"); var _contextCompat = require("@atlaskit/eslint-utils/context-compat"); var _getNodeSource = require("../../utils/get-node-source"); var _isDecendantOfStyleBlock = require("../../utils/is-decendant-of-style-block"); var _isDecendantOfType = require("../../utils/is-decendant-of-type"); /* eslint-disable @repo/internal/react/require-jsdoc */ var UntokenizedProperties = exports.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: (0, _eslintCodemodUtils.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 (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'Property')) { return false; } if (!(0, _isDecendantOfStyleBlock.isDecendantOfStyleBlock)(node) && !(0, _isDecendantOfType.isDecendantOfType)(node, 'JSXExpressionContainer')) { return false; } var isFontProperty = (0, _eslintCodemodUtils.isNodeOfType)(node.key, 'Identifier') && node.key.name === 'font'; var valueNodeSource = (0, _getNodeSource.getNodeSource)((0, _contextCompat.getSourceCode)(context), node.value); if (isFontProperty && valueNodeSource.match(/(font\.(body|heading|code)|inherit)/)) { return false; } return true; } };