@atlaskit/eslint-plugin-design-system
Version:
The essential plugin for use with the Atlassian Design System.
61 lines • 2.2 kB
JavaScript
import { getScope, getSourceCode } from '@atlaskit/eslint-utils/context-compat';
import { getImportSources } from '@atlaskit/eslint-utils/is-supported-import';
import { checkIfSupportedExport } from './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.
*/
export var createNoExportedRule = function createNoExportedRule(isUsage, messageId) {
return function (context) {
var importSources = getImportSources(context);
var _getSourceCode = getSourceCode(context),
text = _getSourceCode.text;
if (importSources.every(function (importSource) {
return !text.includes(importSource);
})) {
return {};
}
return {
CallExpression: function CallExpression(node) {
var _getScope = getScope(context, node),
references = _getScope.references;
if (!isUsage(node.callee, references, importSources)) {
return;
}
var state = checkIfSupportedExport(context, node, importSources);
if (!state.isExport) {
return;
}
context.report({
messageId: messageId,
node: state.node
});
},
TaggedTemplateExpression: function TaggedTemplateExpression(node) {
var _getScope2 = getScope(context, node),
references = _getScope2.references;
if (!isUsage(node.tag, references, importSources)) {
return;
}
var state = checkIfSupportedExport(context, node, importSources);
if (!state.isExport) {
return;
}
context.report({
messageId: messageId,
node: state.node
});
}
};
};
};