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 @@ -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: [
{
Expand Down Expand Up @@ -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: `
Expand Down
12 changes: 12 additions & 0 deletions packages/@stylexjs/eslint-plugin/src/stylex-valid-shorthands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Loading