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 @@ -553,6 +553,55 @@ eslintTester.run('stylex-valid-shorthands', rule.default, {
});
`,
},
// flex: single values are valid (not multi-value shorthands)
{
code: `
import * as stylex from '@stylexjs/stylex';
const styles = stylex.create({
main: { flex: 1 },
})
`,
},
{
code: `
import * as stylex from '@stylexjs/stylex';
const styles = stylex.create({
main: { flex: '2' },
})
`,
},
{
code: `
import * as stylex from '@stylexjs/stylex';
const styles = stylex.create({
main: { flex: 'auto' },
})
`,
},
{
code: `
import * as stylex from '@stylexjs/stylex';
const styles = stylex.create({
main: { flex: 'none' },
})
`,
},
{
code: `
import * as stylex from '@stylexjs/stylex';
const styles = stylex.create({
main: { flex: 'initial' },
})
`,
},
{
code: `
import * as stylex from '@stylexjs/stylex';
const styles = stylex.create({
main: { flex: '100px' },
})
`,
},
],
invalid: [
{
Expand Down Expand Up @@ -2177,168 +2226,6 @@ eslintTester.run('stylex-valid-shorthands', rule.default, {
},
],
},
// flex: single number expands to grow/shrink/basis
{
code: `
import * as stylex from '@stylexjs/stylex';
const styles = stylex.create({
main: {
flex: 1,
},
});
`,
output: `
import * as stylex from '@stylexjs/stylex';
const styles = stylex.create({
main: {
flexGrow: '1',
flexShrink: '1',
flexBasis: '0%',
},
});
`,
errors: [
{
message:
'Property shorthands using multiple values like "flex: 1" are not supported in StyleX. Separate into individual properties.',
},
],
},
// flex: string single number
{
code: `
import * as stylex from '@stylexjs/stylex';
const styles = stylex.create({
main: {
flex: '2',
},
});
`,
output: `
import * as stylex from '@stylexjs/stylex';
const styles = stylex.create({
main: {
flexGrow: '2',
flexShrink: '1',
flexBasis: '0%',
},
});
`,
errors: [
{
message:
'Property shorthands using multiple values like "flex: 2" are not supported in StyleX. Separate into individual properties.',
},
],
},
// flex: auto keyword
{
code: `
import * as stylex from '@stylexjs/stylex';
const styles = stylex.create({
main: {
flex: 'auto',
},
});
`,
output: `
import * as stylex from '@stylexjs/stylex';
const styles = stylex.create({
main: {
flexGrow: '1',
flexShrink: '1',
flexBasis: 'auto',
},
});
`,
errors: [
{
message:
'Property shorthands using multiple values like "flex: auto" are not supported in StyleX. Separate into individual properties.',
},
],
},
// flex: none keyword
{
code: `
import * as stylex from '@stylexjs/stylex';
const styles = stylex.create({
main: {
flex: 'none',
},
});
`,
output: `
import * as stylex from '@stylexjs/stylex';
const styles = stylex.create({
main: {
flexGrow: '0',
flexShrink: '0',
flexBasis: 'auto',
},
});
`,
errors: [
{
message:
'Property shorthands using multiple values like "flex: none" are not supported in StyleX. Separate into individual properties.',
},
],
},
// flex: initial keyword
{
code: `
import * as stylex from '@stylexjs/stylex';
const styles = stylex.create({
main: {
flex: 'initial',
},
});
`,
output: `
import * as stylex from '@stylexjs/stylex';
const styles = stylex.create({
main: {
flexGrow: '0',
flexShrink: '1',
flexBasis: 'auto',
},
});
`,
errors: [
{
message:
'Property shorthands using multiple values like "flex: initial" are not supported in StyleX. Separate into individual properties.',
},
],
},
// flex: single basis value (with unit)
{
code: `
import * as stylex from '@stylexjs/stylex';
const styles = stylex.create({
main: {
flex: '100px',
},
});
`,
output: `
import * as stylex from '@stylexjs/stylex';
const styles = stylex.create({
main: {
flexGrow: '1',
flexShrink: '1',
flexBasis: '100px',
},
});
`,
errors: [
{
message:
'Property shorthands using multiple values like "flex: 100px" are not supported in StyleX. Separate into individual properties.',
},
],
},
// flex: two numbers (grow shrink)
{
code: `
Expand Down Expand Up @@ -2527,6 +2414,32 @@ eslintTester.run('stylex-valid-shorthands', rule.default, {
},
],
},
// gridGap: single numeric value expands to rowGap + columnGap
{
code: `
import * as stylex from '@stylexjs/stylex';
const styles = stylex.create({
main: {
gridGap: 10,
},
});
`,
output: `
import * as stylex from '@stylexjs/stylex';
const styles = stylex.create({
main: {
rowGap: 10,
columnGap: 10,
},
});
`,
errors: [
{
message:
'Property shorthands using multiple values like "gridGap: 10" are not supported in StyleX. Separate into individual properties.',
},
],
},
// gridGap: two values splits to rowGap + columnGap
{
code: `
Expand Down Expand Up @@ -2682,32 +2595,6 @@ eslintTester.run('stylex-valid-shorthands', rule.default, {
},
],
},
// gridGap: single numeric value expands to rowGap + columnGap
{
code: `
import * as stylex from '@stylexjs/stylex';
const styles = stylex.create({
main: {
gridGap: 10,
},
});
`,
output: `
import * as stylex from '@stylexjs/stylex';
const styles = stylex.create({
main: {
rowGap: 10,
columnGap: 10,
},
});
`,
errors: [
{
message:
'Property shorthands using multiple values like "gridGap: 10" are not supported in StyleX. Separate into individual properties.',
},
],
},
// gap: with comma returns CANNOT_FIX (no autofix)
{
code: `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
createSpecificTransformer,
createDirectionalTransformer,
} from './utils/splitShorthands.js';
import { CANNOT_FIX } from './utils/splitShorthands.js';
import { CANNOT_FIX, isSingleToken } from './utils/splitShorthands.js';
import getSourceCode from './utils/getSourceCode';
import getNodeIndentation from './utils/getNodeIndentation';
import createImportTracker from './utils/createImportTracker';
Expand Down Expand Up @@ -187,6 +187,10 @@ const stylexValidShorthands = {
return;
}

if (key === 'flex' && isSingleToken(String(v))) {
return;
}

const newValues = shorthandAliasesForKey(v, allowImportant, preferInline);

const isUnfixableError =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1391,3 +1391,9 @@ export function splitDirectionalShorthands(

return nodes;
}

export function isSingleToken(value: string): boolean {
const { value: baseValue } = extractImportant(value);
const { parts } = splitTopLevelValueTokens(baseValue);
return parts.length <= 1;
}
Loading