UNPKG

@atlaskit/eslint-plugin-design-system

Version:

The essential plugin for use with the Atlassian Design System.

67 lines (66 loc) 2.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createNoExportedRule = void 0; var _contextCompat = require("@atlaskit/eslint-utils/context-compat"); var _isSupportedImport = require("@atlaskit/eslint-utils/is-supported-import"); var _checkIfSupportedExport = require("./check-if-supported-export"); /** * Creates a new ESLint rule for banning exporting certain function calls, e.g. * `css` and `keyframes`. * * Copied from the `utils/create-no-exported-rule/` folder in @compiled/eslint-plugin. * * Requires an importSources option defined on the rule, which is used to define additional * packages which should be checked as part of this rule. * * @param isUsage A function that checks whether the current node matches the desired * function call to check. * @param messageId The ESLint error message to use for lint violations. * @returns An eslint rule. */ var createNoExportedRule = exports.createNoExportedRule = function createNoExportedRule(isUsage, messageId) { return function (context) { var importSources = (0, _isSupportedImport.getImportSources)(context); var _getSourceCode = (0, _contextCompat.getSourceCode)(context), text = _getSourceCode.text; if (importSources.every(function (importSource) { return !text.includes(importSource); })) { return {}; } return { CallExpression: function CallExpression(node) { var _getScope = (0, _contextCompat.getScope)(context, node), references = _getScope.references; if (!isUsage(node.callee, references, importSources)) { return; } var state = (0, _checkIfSupportedExport.checkIfSupportedExport)(context, node, importSources); if (!state.isExport) { return; } context.report({ messageId: messageId, node: state.node }); }, TaggedTemplateExpression: function TaggedTemplateExpression(node) { var _getScope2 = (0, _contextCompat.getScope)(context, node), references = _getScope2.references; if (!isUsage(node.tag, references, importSources)) { return; } var state = (0, _checkIfSupportedExport.checkIfSupportedExport)(context, node, importSources); if (!state.isExport) { return; } context.report({ messageId: messageId, node: state.node }); } }; }; };