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

False positive on invoke where src is a machine factory function #7

Closed
VanTanev opened this issue Aug 16, 2021 · 4 comments
Closed
Labels
bug Something isn't working released

Comments

@VanTanev
Copy link
Contributor

Describe the bug

const createInvokeMachine = () => createMachine({ /* ... */ })

const machine = createMachine({
  invoke: {
    // error: [eslint xstate/invoke-usage] The` value of the "src" property in the "invoke" object must be a machine, function, string or an object.
    src: createInvokeMachine()
  },
});

Expected behavior
Machine creation functions should be allowed as an argument to src.

Discussion
I am not sure how powerful ESlint is here - can it actually track that a creation function returns a machine, across imports? It seems like it won't be able to.

Maybe it's fine to allow the rule to accept a function call expression?

Versions (please complete the following information):

  • Node version: v14.17.3
  • ESLint version: 7.23.0
  • eslint-plugin-xstate version: 0.12.2
@VanTanev VanTanev added the bug Something isn't working label Aug 16, 2021
@rlaffers
Copy link
Owner

rlaffers commented Aug 16, 2021

I am not sure how powerful ESlint is here - can it actually track that a creation function returns a machine, across imports? It seems like it won't be able to.

That's right. Since this is a static code analysis tool (it builds an AST) ESlint does not execute functions to track down the return value.
The best we can do here is to allow functions as a src value. The message actually says functions are allowed so I'm going to check why this fails.
Function calls need to be allowed.

@rlaffers
Copy link
Owner

🎉 This issue has been resolved in version 0.13.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@VanTanev
Copy link
Contributor Author

Thanks for the lightning-fast reaction!

Hope you have a great day :)

@rlaffers
Copy link
Owner

No problem and thank you for the report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released
Projects
None yet
Development

No branches or pull requests

2 participants