UNPKG

@atlaskit/eslint-plugin-design-system

Version:

The essential plugin for use with the Atlassian Design System.

21 lines 831 B
import { getImportedNodeBySource } from '../utils/get-imported-node-by-source'; import { IMPORT_NAME, VISUALLY_HIDDEN_IMPORT, VISUALLY_HIDDEN_SOURCE } from './constants'; import { getFirstImport } from './get-first-import'; var fixVanilla = function fixVanilla(source, node) { return function (fixer) { var fixes = []; var importedNode = getFirstImport(source); var visuallyHiddenNode = getImportedNodeBySource(source, VISUALLY_HIDDEN_SOURCE); if (!importedNode) { return []; } if (visuallyHiddenNode) { fixes.push(fixer.replaceText(node, visuallyHiddenNode.specifiers[0].local.name)); } else { fixes.push(fixer.insertTextBefore(importedNode, VISUALLY_HIDDEN_IMPORT)); fixes.push(fixer.replaceText(node, IMPORT_NAME)); } return fixes; }; }; export default fixVanilla;