UNPKG

@atlaskit/eslint-plugin-design-system

Version:

The essential plugin for use with the Atlassian Design System.

68 lines (66 loc) 2.81 kB
import { getScope, getSourceCode } from '@atlaskit/eslint-utils/context-compat'; import { CSS_IN_JS_IMPORTS } from '@atlaskit/eslint-utils/is-supported-import'; import { createLintRule } from '../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 = [CSS_IN_JS_IMPORTS.compiled, 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 = 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 = getSourceCode(context), text = _getSourceCode.text; if (IMPORT_SOURCES.every(function (importSource) { return !text.includes(importSource); })) { return {}; } return { CallExpression: function CallExpression(node) { var references = getScope(context, node).references; if (isCssMapScopedCallee(node.callee, references)) { context.report({ node: node, messageId: 'noCssMapScoped' }); } } }; } }); export default noCssMapScopedRule;