UNPKG

@atlaskit/eslint-plugin-design-system

Version:

The essential plugin for use with the Atlassian Design System.

23 lines 1.1 kB
import { isNodeOfType } from 'eslint-codemod-utils'; import { getSourceCode } from '@atlaskit/eslint-utils/context-compat'; /** * Get the first import declaration in the file that matches any of the packages * in `importSources`. * * @param context Rule context. * @param importSources The packages to check import statements for. If importSources * contains more than one package, the first import statement * detected in the file that matches any of the packages will be * returned. * @returns The first import declaration found in the file. */ export var getFirstSupportedImport = function getFirstSupportedImport(context, importSources) { var isSupportedImport = function isSupportedImport(node) { return isNodeOfType(node, 'ImportDeclaration') && typeof node.source.value === 'string' && importSources.includes(node.source.value); }; var source = getSourceCode(context); var supportedImports = source.ast.body.filter(isSupportedImport); if (supportedImports.length) { return supportedImports[0]; } };