function validateThemeMixin()

in tools/stylelint/theme-mixin-api.ts [58:143]


    function validateThemeMixin(node: AtRule, args: string[]) {
      if (args.length !== 1) {
        reportError(node, 'Expected theme mixin to only declare a single argument.');
      } else if (args[0] !== '$theme-or-color-config') {
        if (context.fix) {
          node.params = node.params.replace(args[0], '$theme-or-color-config');
        } else {
          reportError(node, 'Expected first mixin argument to be called `$theme-or-color-config`.');
        }
      }

      const themePropName = `$theme`;
      const legacyColorExtractExpr = `theming.private-legacy-get-theme($theme-or-color-config)`;
      const duplicateStylesCheckExpr = `theming.private-check-duplicate-theme-styles(${themePropName}, '${componentName}')`;

      let legacyConfigDecl: Declaration | null = null;
      let duplicateStylesCheck: AtRule | null = null;
      let hasNodesOutsideDuplicationCheck = false;
      let isLegacyConfigRetrievalFirstStatement = false;

      if (node.nodes) {
        for (let i = 0; i < node.nodes.length; i++) {
          const childNode = node.nodes[i];
          if (childNode.type === 'decl' && childNode.value === legacyColorExtractExpr) {
            legacyConfigDecl = childNode;
            isLegacyConfigRetrievalFirstStatement = i === 0;
          } else if (
            childNode.type === 'atrule' &&
            childNode.name === 'include' &&
            childNode.params === duplicateStylesCheckExpr
          ) {
            duplicateStylesCheck = childNode;
          } else if (childNode.type !== 'comment') {
            hasNodesOutsideDuplicationCheck = true;
          }
        }
      }

      if (!legacyConfigDecl) {
        if (context.fix) {
          legacyConfigDecl = decl({prop: themePropName, value: legacyColorExtractExpr});
          node.insertBefore(0, legacyConfigDecl);
        } else {
          reportError(
            node,
            `Legacy color API is not handled. Consumers could pass in a ` +
              `color configuration directly to the theme mixin. For backwards compatibility, ` +
              `use the following declaration to retrieve the theme object: ` +
              `${themePropName}: ${legacyColorExtractExpr}`,
          );
        }
      } else if (legacyConfigDecl.prop !== themePropName) {
        reportError(
          legacyConfigDecl,
          `For consistency, theme variable should be called: ${themePropName}`,
        );
      }

      if (!duplicateStylesCheck) {
        if (context.fix) {
          duplicateStylesCheck = atRule({name: 'include', params: duplicateStylesCheckExpr});
          node.insertBefore(1, duplicateStylesCheck);
        } else {
          reportError(
            node,
            `Missing check for duplicative theme styles. Please include the ` +
              `duplicate styles check mixin: ${duplicateStylesCheckExpr}`,
          );
        }
      }

      if (hasNodesOutsideDuplicationCheck) {
        reportError(
          node,
          `Expected nodes other than the "${legacyColorExtractExpr}" ` +
            `declaration to be nested inside the duplicate styles check.`,
        );
      }

      if (legacyConfigDecl !== null && !isLegacyConfigRetrievalFirstStatement) {
        reportError(
          legacyConfigDecl,
          'Legacy configuration should be retrieved first in theme mixin.',
        );
      }
    }