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: strict report for stylex.create argument as object expression #141

Merged

Conversation

kotarella1110
Copy link
Contributor

@kotarella1110 kotarella1110 commented Dec 12, 2023

What changed / motivation ?

I have fixed to report when a value other than an ObjectExpression is specified as an argument for stylex.create.

Additional Context

スクリーンショット 2023-12-13 0 58 04

Pre-flight checklist

@facebook-github-bot
Copy link

Hi @kotarella1110!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@kotarella1110 kotarella1110 force-pushed the fix/eslint-object-expression-report branch from 61fa5e5 to dfdfa3c Compare December 12, 2023 16:02
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Dec 12, 2023
@necolas necolas requested a review from nmn December 12, 2023 17:54
Copy link
Contributor

@nmn nmn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this change can be made without a bigger refactor, but I'll let the tests run in case this is accounted for.

@@ -2347,8 +2347,7 @@ const stylexValidStyles = {
node &&
node.type === 'CallExpression' &&
isStylexCallee(node.callee) &&
node.arguments.length === 1 &&
node.arguments[0].type === 'ObjectExpression'
node.arguments.length === 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rest of the code still depends on it being an object expression.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting! The tests are still working.

@nmn
Copy link
Contributor

nmn commented Dec 12, 2023

I'll merge for now since the tests are still passing. The bigger refactor can wait.

@nmn nmn merged commit ca1dc8b into facebook:main Dec 12, 2023
9 checks passed
@kotarella1110 kotarella1110 deleted the fix/eslint-object-expression-report branch December 13, 2023 01:15
@kotarella1110
Copy link
Contributor Author

kotarella1110 commented Dec 13, 2023

@nmn

I don't think this change can be made without a bigger refactor, but I'll let the tests run in case this is accounted for.

What do you mean?

The only fix to this PR is that the following code is executed when a value other than ObjectExpression is specified as the argument to stylex.create.

const namespaces = node.arguments[0];
// const loc: ?AST['SourceLocation'] = namespaces.loc;
if (namespaces.type !== 'ObjectExpression') {
return context.report(
({
node: namespaces,
loc: namespaces.loc,
message: 'Styles must be represented as JavaScript objects',
}: Rule.ReportDescriptor),
);
}

Prior to this fix, the following code would not report a problem, but now it does.

stylex.create("test")
stylex.create(1)
const foo = {}
stylex.create(foo)

@nmn
Copy link
Contributor

nmn commented Dec 13, 2023

@kotarella1110 That's my misunderstanding. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants