@atlaskit/eslint-plugin-design-system
Version:
The essential plugin for use with the Atlassian Design System.
29 lines (28 loc) • 1.18 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _eslintCodemodUtils = require("eslint-codemod-utils");
var _getImportedNodeBySource = require("../utils/get-imported-node-by-source");
var _constants = require("./constants");
var _getFirstImport = require("./get-first-import");
var fixJsx = function fixJsx(source, node) {
return function (fixer) {
var fixes = [];
var importedNode = (0, _getFirstImport.getFirstImport)(source);
var visuallyHiddenNode = (0, _getImportedNodeBySource.getImportedNodeBySource)(source, _constants.VISUALLY_HIDDEN_SOURCE);
if (!importedNode) {
return [];
}
var jsxOpeningElement = (0, _eslintCodemodUtils.closestOfType)(node, 'JSXOpeningElement');
if (visuallyHiddenNode) {
fixes.push(fixer.replaceText(jsxOpeningElement, visuallyHiddenNode.specifiers[0].local.name));
} else {
fixes.push(fixer.insertTextBefore(importedNode, _constants.VISUALLY_HIDDEN_IMPORT));
fixes.push(fixer.replaceText(jsxOpeningElement, "<".concat(_constants.IMPORT_NAME, " />")));
}
return fixes;
};
};
var _default = exports.default = fixJsx;