@atlaskit/eslint-plugin-design-system
Version:
The essential plugin for use with the Atlassian Design System.
80 lines (79 loc) • 2.47 kB
JavaScript
/* eslint-disable @repo/internal/react/require-jsdoc */
import { isNodeOfType } from 'eslint-codemod-utils';
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'];
export var 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 (!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 isNodeOfType(specifier, 'ImportDefaultSpecifier') || isNodeOfType(specifier, 'ImportNamespaceSpecifier') || 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 (!isNodeOfType(specifier, 'ImportSpecifier')) {
return false;
}
return BANNED_IMPORTS.includes(specifier.imported.name);
});
if (!isViolation) {
return {
success: false,
ref: undefined
};
}
return {
success: true,
ref: node
};
}
};