From f8fe8627acf990fb6278f5b25948af1711863e83 Mon Sep 17 00:00:00 2001 From: "Henry Q. Dineen" Date: Fri, 26 Jun 2026 23:53:38 -0400 Subject: [PATCH] [eslint] Allow type exports in enforce-extension rule Type exports (export type, export interface, export type { ... }, export { type ... }) are erased at compile time and don't violate the intent of the rule. Skip them so they don't trigger false positives for the mixed-export check. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../stylex-enforce-extension-test.js | 75 +++++++++++++++++++ .../src/stylex-enforce-extension.js | 3 + 2 files changed, 78 insertions(+) diff --git a/packages/@stylexjs/eslint-plugin/__tests__/stylex-enforce-extension-test.js b/packages/@stylexjs/eslint-plugin/__tests__/stylex-enforce-extension-test.js index 1b837af93..fc898adb6 100644 --- a/packages/@stylexjs/eslint-plugin/__tests__/stylex-enforce-extension-test.js +++ b/packages/@stylexjs/eslint-plugin/__tests__/stylex-enforce-extension-test.js @@ -1024,3 +1024,78 @@ ruleTester.run('stylex-enforce-extension', rule.default, { }, ], }); + +const typeExportRuleTester = new RuleTester({ + parser: require.resolve('@typescript-eslint/parser'), + parserOptions: { sourceType: 'module' }, +}); + +typeExportRuleTester.run( + 'stylex-enforce-extension (type exports)', + rule.default, + { + valid: [ + { + code: ` + import * as stylex from '@stylexjs/stylex'; + export const colors = stylex.defineVars({ + primary: 'blue', + secondary: 'green', + accent: 'coral', + }); + export type Colors = keyof typeof colors; + `, + filename: 'colors.stylex.ts', + }, + { + code: ` + import * as stylex from '@stylexjs/stylex'; + export const colors = stylex.defineConsts({ + primary: 'blue', + secondary: 'green', + }); + export type Colors = keyof typeof colors; + `, + filename: 'colors.stylex.const.ts', + options: [{ enforceDefineConstsExtension: true }], + }, + { + code: ` + import * as stylex from '@stylexjs/stylex'; + type Colors = keyof typeof colors; + export const colors = stylex.defineVars({ + primary: 'blue', + secondary: 'green', + }); + export type { Colors }; + `, + filename: 'colors.stylex.ts', + }, + { + code: ` + import * as stylex from '@stylexjs/stylex'; + type Colors = keyof typeof colors; + export const colors = stylex.defineVars({ + primary: 'blue', + secondary: 'green', + }); + export { type Colors }; + `, + filename: 'colors.stylex.ts', + }, + ], + + invalid: [ + { + code: ` + import * as stylex from '@stylexjs/stylex'; + export const colors = stylex.defineVars({ primary: 'blue' }); + export type Colors = keyof typeof colors; + export const helper = someFunction(); + `, + filename: 'colors.stylex.ts', + errors: [{ message: invalidExportFromThemeFiles }], + }, + ], + }, +); diff --git a/packages/@stylexjs/eslint-plugin/src/stylex-enforce-extension.js b/packages/@stylexjs/eslint-plugin/src/stylex-enforce-extension.js index 38702c164..ac03485d7 100644 --- a/packages/@stylexjs/eslint-plugin/src/stylex-enforce-extension.js +++ b/packages/@stylexjs/eslint-plugin/src/stylex-enforce-extension.js @@ -431,6 +431,9 @@ const stylexEnforceExtension = { }); }, 'ExportNamedDeclaration, ExportDefaultDeclaration'(node: Node): void { + if ((node as any).exportKind === 'type') { + return; + } reportedDefaultExportError = false; checkExports(node); if (!reportedDefaultExportError) {