diff --git a/packages/@stylexjs/eslint-plugin/__tests__/stylex-valid-shorthands-test.js b/packages/@stylexjs/eslint-plugin/__tests__/stylex-valid-shorthands-test.js index 037d159a7..c44b4dcb4 100644 --- a/packages/@stylexjs/eslint-plugin/__tests__/stylex-valid-shorthands-test.js +++ b/packages/@stylexjs/eslint-plugin/__tests__/stylex-valid-shorthands-test.js @@ -498,6 +498,61 @@ eslintTester.run('stylex-valid-shorthands', rule.default, { }) `, }, + // gap: single value is not a shorthand, no expansion needed + { + code: ` + import * as stylex from '@stylexjs/stylex'; + const styles = stylex.create({ + main: { + gap: '10px', + }, + }); + `, + }, + // gap: single numeric value is not a shorthand + { + code: ` + import * as stylex from '@stylexjs/stylex'; + const styles = stylex.create({ + main: { + gap: 10, + }, + }); + `, + }, + // gap: numeric zero is not a shorthand + { + code: ` + import * as stylex from '@stylexjs/stylex'; + const styles = stylex.create({ + main: { + gap: 0, + }, + }); + `, + }, + // gap: var() single value is not a shorthand + { + code: ` + import * as stylex from '@stylexjs/stylex'; + const styles = stylex.create({ + main: { + gap: 'var(--spacing)', + }, + }); + `, + }, + // gap: calc() single value is not a shorthand + { + code: ` + import * as stylex from '@stylexjs/stylex'; + const styles = stylex.create({ + main: { + gap: 'calc(10px + 1rem)', + }, + }); + `, + }, ], invalid: [ { @@ -2420,136 +2475,6 @@ eslintTester.run('stylex-valid-shorthands', rule.default, { }, ], }, - // gap: single value expands to rowGap + columnGap - { - code: ` - import * as stylex from '@stylexjs/stylex'; - const styles = stylex.create({ - main: { - gap: '10px', - }, - }); - `, - output: ` - import * as stylex from '@stylexjs/stylex'; - const styles = stylex.create({ - main: { - rowGap: '10px', - columnGap: '10px', - }, - }); - `, - errors: [ - { - message: - 'Property shorthands using multiple values like "gap: 10px" are not supported in StyleX. Separate into individual properties.', - }, - ], - }, - // gap: single numeric value expands to rowGap + columnGap - { - code: ` - import * as stylex from '@stylexjs/stylex'; - const styles = stylex.create({ - main: { - gap: 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 "gap: 10" are not supported in StyleX. Separate into individual properties.', - }, - ], - }, - // gap: numeric zero expands to rowGap + columnGap - { - code: ` - import * as stylex from '@stylexjs/stylex'; - const styles = stylex.create({ - main: { - gap: 0, - }, - }); - `, - output: ` - import * as stylex from '@stylexjs/stylex'; - const styles = stylex.create({ - main: { - rowGap: 0, - columnGap: 0, - }, - }); - `, - errors: [ - { - message: - 'Property shorthands using multiple values like "gap: 0" are not supported in StyleX. Separate into individual properties.', - }, - ], - }, - // gap: var() value expands to rowGap + columnGap - { - code: ` - import * as stylex from '@stylexjs/stylex'; - const styles = stylex.create({ - main: { - gap: 'var(--spacing)', - }, - }); - `, - output: ` - import * as stylex from '@stylexjs/stylex'; - const styles = stylex.create({ - main: { - rowGap: 'var(--spacing)', - columnGap: 'var(--spacing)', - }, - }); - `, - errors: [ - { - message: - 'Property shorthands using multiple values like "gap: var(--spacing)" are not supported in StyleX. Separate into individual properties.', - }, - ], - }, - // gap: calc() value expands to rowGap + columnGap - { - code: ` - import * as stylex from '@stylexjs/stylex'; - const styles = stylex.create({ - main: { - gap: 'calc(10px + 1rem)', - }, - }); - `, - output: ` - import * as stylex from '@stylexjs/stylex'; - const styles = stylex.create({ - main: { - rowGap: 'calc(10px + 1rem)', - columnGap: 'calc(10px + 1rem)', - }, - }); - `, - errors: [ - { - message: - 'Property shorthands using multiple values like "gap: calc(10px + 1rem)" are not supported in StyleX. Separate into individual properties.', - }, - ], - }, // gap: two values splits to rowGap + columnGap { code: ` diff --git a/packages/@stylexjs/eslint-plugin/src/stylex-valid-shorthands.js b/packages/@stylexjs/eslint-plugin/src/stylex-valid-shorthands.js index beb34b984..3e5554623 100644 --- a/packages/@stylexjs/eslint-plugin/src/stylex-valid-shorthands.js +++ b/packages/@stylexjs/eslint-plugin/src/stylex-valid-shorthands.js @@ -204,6 +204,18 @@ const stylexValidShorthands = { return; } + if ( + key === 'gap' && + newValues.length === 2 && + newValues.every( + ([, val]) => + val === property.value.value || + val === Number(property.value.value), + ) + ) { + return; + } + context.report({ node: property, message: `Property shorthands using multiple values like "${key}: ${String(property.value.value)}" are not supported in StyleX. Separate into individual properties.`, diff --git a/packages/@stylexjs/eslint-plugin/src/stylex-valid-styles.js b/packages/@stylexjs/eslint-plugin/src/stylex-valid-styles.js index b647f3f29..e4727433a 100644 --- a/packages/@stylexjs/eslint-plugin/src/stylex-valid-styles.js +++ b/packages/@stylexjs/eslint-plugin/src/stylex-valid-styles.js @@ -86,6 +86,7 @@ const showError = const shorthandExpansionMap: { [string]: string } = { animation: 'animation', font: 'font', + gap: 'gap', gridArea: 'grid-area', gridColumn: 'grid-column', gridRow: 'grid-row',