@atlaskit/eslint-plugin-design-system
Version:
The essential plugin for use with the Atlassian Design System.
44 lines (43 loc) • 1.65 kB
JavaScript
/* eslint-disable @repo/internal/react/require-jsdoc */
import { isNodeOfType } from 'eslint-codemod-utils';
var messageId = 'noWrappedTokenTypographyValues';
export var WrappedTokenValue = {
lint: function lint(node, _ref) {
var context = _ref.context,
config = _ref.config;
if (WrappedTokenValue._check(node, {
context: context,
config: config
})) {
context.report({
node: node,
messageId: messageId,
fix: WrappedTokenValue._fix(node)
});
}
},
_check: function _check(node, _ref2) {
var config = _ref2.config;
if (!config.patterns.includes('wrapped-token-value')) {
return false;
}
if (isNodeOfType(node.parent, 'Property') && isNodeOfType(node.parent.value, 'CallExpression') && isNodeOfType(node.parent.value.callee, 'Identifier') && node.parent.value.callee.name === 'token' && node.parent.value.arguments.length >= 1) {
return true;
}
return false;
},
_fix: function _fix(node) {
return function (fixer) {
var wrappedTokenFix;
if (isNodeOfType(node.parent, 'Property') && isNodeOfType(node.parent.value, 'CallExpression') && node.parent.value.arguments.length >= 1) {
var firstArg = node.parent.value.arguments[0];
if (isNodeOfType(firstArg, 'Literal') && typeof firstArg.value === 'string') {
wrappedTokenFix = fixer.replaceText(node.parent.value, "'".concat(firstArg.value, "'"));
}
}
return [wrappedTokenFix].filter(function (fix) {
return Boolean(fix);
}); // Some of the transformers can return arrays with undefined, so filter them out
};
}
};