Skip to content

Commit

Permalink
Merge branch 'main' into valid-shorthands-spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
mellyeliu authored Aug 16, 2024
2 parents 16fea59 + 680e095 commit 1cf81e4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 24 deletions.
44 changes: 20 additions & 24 deletions packages/eslint-plugin/__tests__/stylex-valid-shorthands-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ eslintTester.run('stylex-valid-shorthands', rule.default, {
import stylex from 'stylex';
const styles = stylex.create({
main: {
margin: '10em 1em',
margin: '10em 1em 5em 2em',
},
});
`,
Expand All @@ -498,15 +498,15 @@ eslintTester.run('stylex-valid-shorthands', rule.default, {
main: {
marginTop: '10em',
marginInlineEnd: '1em',
marginBottom: '10em',
marginInlineStart: '1em',
marginBottom: '5em',
marginInlineStart: '2em',
},
});
`,
errors: [
{
message:
'Property shorthands using multiple values like "margin: 10em 1em" are not supported in StyleX. Separate into individual properties.',
'Property shorthands using multiple values like "margin: 10em 1em 5em 2em" are not supported in StyleX. Separate into individual properties.',
},
],
},
Expand All @@ -520,16 +520,14 @@ eslintTester.run('stylex-valid-shorthands', rule.default, {
});
`,
output: `
import stylex from 'stylex';
const styles = stylex.create({
main: {
marginTop: '10em',
marginRight: '1em',
marginBottom: '10em',
marginLeft: '1em',
},
});
`,
import stylex from 'stylex';
const styles = stylex.create({
main: {
marginBlock: '10em',
marginInline: '1em',
},
});
`,
errors: [
{
message:
Expand Down Expand Up @@ -668,16 +666,14 @@ eslintTester.run('stylex-valid-shorthands', rule.default, {
});
`,
output: `
import stylex from 'stylex';
const styles = stylex.create({
main: {
paddingTop: '10em',
paddingRight: '1em',
paddingBottom: '10em',
paddingLeft: '1em',
},
});
`,
import stylex from 'stylex';
const styles = stylex.create({
main: {
paddingBlock: '10em',
paddingInline: '1em',
},
});
`,
errors: [
{
message:
Expand Down
14 changes: 14 additions & 0 deletions packages/eslint-plugin/src/stylex-valid-shorthands.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,13 @@ const shorthandAliases = {

const [top, right = top, bottom = top, left = right] = splitValues;

if (splitValues.length === 2) {
return [
['marginBlock', top],
['marginInline', right],
];
}

return preferInline
? [
['marginTop', top],
Expand Down Expand Up @@ -234,6 +241,13 @@ const shorthandAliases = {
const [top, right = top, bottom = top, left = right] =
splitDirectionalShorthands(rawValue, allowImportant);

if (splitValues.length === 2) {
return [
['paddingBlock', top],
['paddingInline', right],
];
}

return preferInline
? [
['paddingTop', top],
Expand Down

0 comments on commit 1cf81e4

Please sign in to comment.