UNPKG

@atlaskit/eslint-plugin-design-system

Version:

The essential plugin for use with the Atlassian Design System.

86 lines (84 loc) 2.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ImportDeclaration = void 0; var _eslintCodemodUtils = require("eslint-codemod-utils"); /* eslint-disable @repo/internal/react/require-jsdoc */ var messageId = 'use-spotlight-package'; var ONBOARDING_PACKAGE = '@atlaskit/onboarding'; var BANNED_IMPORT_SOURCES = new Set(['@atlaskit/onboarding/spotlight', '@atlaskit/onboarding/spotlight-card', '@atlaskit/onboarding/spotlight-manager', '@atlaskit/onboarding/spotlight-target', '@atlaskit/onboarding/spotlight-transition', '@atlaskit/onboarding/theme', '@atlaskit/onboarding/use-spotlight']); var BANNED_IMPORTS = [ // 'Modal', 'Spotlight', 'SpotlightCard', 'SpotlightManager', 'SpotlightTarget', 'SpotlightTransition', // 'modalButtonTheme', 'spotlightButtonTheme', 'useSpotlight', // 'ModalTransition', 'SpotlightPulse']; var ImportDeclaration = exports.ImportDeclaration = { lint: function lint(node, _ref) { var context = _ref.context; // Check whether all criteria needed to make a transformation are met var _ImportDeclaration$_c = ImportDeclaration._check(node), success = _ImportDeclaration$_c.success, ref = _ImportDeclaration$_c.ref; if (!success) { return; } context.report({ node: ref, messageId: messageId }); }, _check: function _check(node) { if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'ImportDeclaration')) { return { success: false, ref: undefined }; } if (!node.specifiers) { return { success: false, ref: undefined }; } if (BANNED_IMPORT_SOURCES.has(String(node.source.value))) { var hasValueImport = node.specifiers.some(function (specifier) { return (0, _eslintCodemodUtils.isNodeOfType)(specifier, 'ImportDefaultSpecifier') || (0, _eslintCodemodUtils.isNodeOfType)(specifier, 'ImportNamespaceSpecifier') || (0, _eslintCodemodUtils.isNodeOfType)(specifier, 'ImportSpecifier'); }); if (!hasValueImport) { return { success: false, ref: undefined }; } return { success: true, ref: node }; } if (node.source.value !== ONBOARDING_PACKAGE) { return { success: false, ref: undefined }; } var isViolation = node.specifiers.some(function (specifier) { if (!(0, _eslintCodemodUtils.isNodeOfType)(specifier, 'ImportSpecifier')) { return false; } return BANNED_IMPORTS.includes(specifier.imported.name); }); if (!isViolation) { return { success: false, ref: undefined }; } return { success: true, ref: node }; } };