@atlaskit/eslint-plugin-design-system
Version:
The essential plugin for use with the Atlassian Design System.
29 lines (28 loc) • 1.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getFirstSupportedImport = void 0;
var _eslintCodemodUtils = require("eslint-codemod-utils");
var _contextCompat = require("@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.
*/
var getFirstSupportedImport = exports.getFirstSupportedImport = function getFirstSupportedImport(context, importSources) {
var isSupportedImport = function isSupportedImport(node) {
return (0, _eslintCodemodUtils.isNodeOfType)(node, 'ImportDeclaration') && typeof node.source.value === 'string' && importSources.includes(node.source.value);
};
var source = (0, _contextCompat.getSourceCode)(context);
var supportedImports = source.ast.body.filter(isSupportedImport);
if (supportedImports.length) {
return supportedImports[0];
}
};