Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ ruleTester.run('stylex-enforce-extension', rule.default, {
import * as stylex from '@stylexjs/stylex';
export const vars = stylex.defineVars({ color: 'red' });
export const consts = stylex.defineConsts({ color: 'red' });
export default stylex.defineVars({ background: 'blue' });
`,
filename: 'myComponent.stylex.jsx',
},
Expand Down Expand Up @@ -172,6 +171,82 @@ ruleTester.run('stylex-enforce-extension', rule.default, {
filename: 'testComponent.custom.jsx',
options: [{ themeFileExtension: '.custom' }],
},
{
code: `
import * as stylex from '@stylexjs/stylex';
export const vars = stylex.defineVars({ color: 'red' });
export const somethingElse = someFunction();
`,
filename: 'myComponent.stylex.jsx',
options: [{ legacyAllowMixedExports: true }],
},
{
code: `
import * as stylex from '@stylexjs/stylex';
export const consts = stylex.defineConsts({ color: 'red' });
export const somethingElse = someFunction();
`,
filename: 'myComponent.stylex.jsx',
options: [{ legacyAllowMixedExports: true }],
},
{
code: `
import * as stylex from '@stylexjs/stylex';
export const vars = stylex.defineVars({ color: 'red' });
export const somethingElse = someFunction();
`,
filename: 'myComponent.stylex.tsx',
options: [{ legacyAllowMixedExports: true }],
},
{
code: `
import * as stylex from '@stylexjs/stylex';
export const consts = stylex.defineConsts({ color: 'red' });
export const somethingElse = someFunction();
`,
filename: 'myComponent.stylex.tsx',
options: [{ legacyAllowMixedExports: true }],
},
{
code: `
import * as stylex from '@stylexjs/stylex';
export const vars = stylex.defineVars({ color: 'red' });
export const somethingElse = someFunction();
`,
filename: 'myComponent.stylex.ts',
options: [{ legacyAllowMixedExports: true }],
},
{
code: `
import * as stylex from '@stylexjs/stylex';
export const consts = stylex.defineConsts({ color: 'red' });
export const somethingElse = someFunction();
`,
filename: 'myComponent.stylex.js',
options: [{ legacyAllowMixedExports: true }],
},
{
code: `
import * as stylex from '@stylexjs/stylex';
export const consts = stylex.defineConsts({ color: 'red' });
export const somethingElse = someFunction();
`,
filename: 'myComponent.custom.ts',
options: [
{ legacyAllowMixedExports: true, themeFileExtension: '.custom' },
],
},
{
code: `
import * as stylex from '@stylexjs/stylex';
export const consts = stylex.defineConsts({ color: 'red' });
export const somethingElse = someFunction();
`,
filename: 'myComponent.custom.js',
options: [
{ legacyAllowMixedExports: true, themeFileExtension: '.custom' },
],
},
],

invalid: [
Expand Down Expand Up @@ -200,39 +275,29 @@ ruleTester.run('stylex-enforce-extension', rule.default, {
import * as stylex from '@stylexjs/stylex';
export const vars = stylex.defineVars({ color: 'red' });
export const somethingElse = someFunction();
export default stylex.defineVars({ background: 'blue' });
`,
filename: 'myComponent.stylex.jsx',
errors: [
{ message: invalidExportFromThemeFiles },
{ message: invalidExportFromThemeFiles },
],
errors: [{ message: invalidExportFromThemeFiles }],
},
{
code: `
import * as stylex from '@stylexjs/stylex';
export const consts = stylex.defineConsts({ color: 'red' });
export const somethingElse = someFunction();
export default stylex.defineConsts({ background: 'blue' });
`,
filename: 'myComponent.stylex.jsx',
errors: [
{ message: invalidExportFromThemeFiles },
{ message: invalidExportFromThemeFiles },
],
errors: [{ message: invalidExportFromThemeFiles }],
},
{
code: `
import * as stylex from '@stylexjs/stylex';
export const vars = someFunction();
export const somethingElse = someFunction();
export default stylex.defineVars({ background: 'blue' });
`,
filename: 'myComponent.stylex.jsx',
errors: [
{ message: invalidFilenameWithoutRestrictedExports('.stylex.jsx') },
{ message: invalidFilenameWithoutRestrictedExports('.stylex.jsx') },
{ message: invalidExportFromThemeFiles },
],
},
{
Expand Down Expand Up @@ -429,5 +494,25 @@ ruleTester.run('stylex-enforce-extension', rule.default, {
},
],
},
{
code: `
import * as stylex from '@stylexjs/stylex';
export const vars = stylex.defineVars({ color: 'red' });
export const somethingElse = someFunction();
`,
filename: 'myComponent.stylex.jsx',
options: [{ legacyAllowMixedExports: false }],
errors: [{ message: invalidExportFromThemeFiles }],
},
{
code: `
import * as stylex from '@stylexjs/stylex';
export const consts = stylex.defineConsts({ color: 'red' });
export const somethingElse = someFunction();
`,
filename: 'myComponent.stylex.jsx',
options: [{ legacyAllowMixedExports: false }],
errors: [{ message: invalidExportFromThemeFiles }],
},
],
});
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ const stylexEnforceExtension = {
type: 'string',
default: '.stylex',
},
// This is a legacy option that allows mixed exports in theme files. This is for internal legacy patterns and should not be used by external users.
legacyAllowMixedExports: {
type: 'boolean',
default: false,
},
},
additionalProperties: false,
},
Expand All @@ -57,8 +62,10 @@ const stylexEnforceExtension = {
let hasOtherExports = false;
const fileName = context.getFilename();
const options = context.options[0] || {};
const { validImports: importsToLookFor = ['stylex', '@stylexjs/stylex'] } =
options;
const {
validImports: importsToLookFor = ['stylex', '@stylexjs/stylex'],
legacyAllowMixedExports = false,
} = options;

const themeFileExtension = (
options.themeFileExtension || '.stylex'
Expand Down Expand Up @@ -115,7 +122,7 @@ const stylexEnforceExtension = {
fileName.endsWith(ext),
);

if (hasRestrictedExports && hasOtherExports) {
if (hasRestrictedExports && hasOtherExports && !legacyAllowMixedExports) {
context.report({
node,
message:
Expand Down