UNPKG

@atlaskit/eslint-plugin-design-system

Version:

The essential plugin for use with the Atlassian Design System.

73 lines (71 loc) 3.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _contextCompat = require("@atlaskit/eslint-utils/context-compat"); var _isSupportedImport = require("@atlaskit/eslint-utils/is-supported-import"); var _createLintRule = require("../utils/create-lint-rule"); // `cssMapScoped` is an experimental, internal API in @compiled/react that is // intentionally not exported from its public types. This rule prevents // accidental adoption outside of the small set of packages (e.g. editor-core) // that are allowed to use it. // // The detection logic mirrors @compiled/eslint-plugin's `no-css-map-scoped` // rule (which lives in the nonAtomic patch). It is reimplemented here so this // rule does not depend on the upstream rule being available at codegen time // (the patch is applied during `afm install`, but codegen runs ahead of that). var IMPORT_SOURCES = [_isSupportedImport.CSS_IN_JS_IMPORTS.compiled, _isSupportedImport.CSS_IN_JS_IMPORTS.atlaskitCss]; var isCssMapScopedCallee = function isCssMapScopedCallee(node, references) { if (node.type !== 'Identifier') { return false; } return references.some(function (reference) { var _reference$resolved; return reference.identifier === node && ((_reference$resolved = reference.resolved) === null || _reference$resolved === void 0 ? void 0 : _reference$resolved.defs.some(function (def) { if (def.type !== 'ImportBinding') { return false; } if (!def.parent || !IMPORT_SOURCES.includes(def.parent.source.value)) { return false; } return def.node.type === 'ImportSpecifier' && def.node.imported.type === 'Identifier' && def.node.imported.name === 'cssMapScoped'; })); }); }; var noCssMapScopedRule = (0, _createLintRule.createLintRule)({ meta: { name: 'no-css-map-scoped', type: 'problem', docs: { description: 'Disallows usage of the experimental `cssMapScoped` API from `@compiled/react`. This API is internal and is not part of the public Compiled CSS-in-JS interface.', recommended: true, severity: 'error' }, messages: { noCssMapScoped: '`cssMapScoped` is experimental and restricted. Use `cssMap` for standard atomic CSS map output, or contact the Compiled team for approval to use `cssMapScoped`.' }, schema: [] }, create: function create(context) { var _getSourceCode = (0, _contextCompat.getSourceCode)(context), text = _getSourceCode.text; if (IMPORT_SOURCES.every(function (importSource) { return !text.includes(importSource); })) { return {}; } return { CallExpression: function CallExpression(node) { var references = (0, _contextCompat.getScope)(context, node).references; if (isCssMapScopedCallee(node.callee, references)) { context.report({ node: node, messageId: 'noCssMapScoped' }); } } }; } }); var _default = exports.default = noCssMapScopedRule;