Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Process two-value shorthands appropriately #665

Merged
merged 1 commit into from
Aug 15, 2024
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
20 changes: 8 additions & 12 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 @@ -523,10 +523,8 @@ eslintTester.run('stylex-valid-shorthands', rule.default, {
import stylex from 'stylex';
const styles = stylex.create({
main: {
marginTop: '10em',
marginRight: '1em',
marginBottom: '10em',
marginLeft: '1em',
marginBlock: '10em',
marginInline: '1em',
},
});
`,
Expand Down Expand Up @@ -671,10 +669,8 @@ eslintTester.run('stylex-valid-shorthands', rule.default, {
import stylex from 'stylex';
const styles = stylex.create({
main: {
paddingTop: '10em',
paddingRight: '1em',
paddingBottom: '10em',
paddingLeft: '1em',
paddingBlock: '10em',
paddingInline: '1em',
},
});
`,
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
Loading