rlaffers / eslint-plugin-xstate

ESLint plugin to check for common mistakes and enforce good practices when using XState.
MIT License
48 stars 4 forks source link

Wrong "xstate/no-imperative-action" inside actions.pure() #4

Closed VanTanev closed 3 years ago

VanTanev commented 3 years ago

Describe the bug "xstate/no-imperative-action" is triggered with valid use of send()

Actual behavior

import { actions, send, createMachine } from 'xstate'

export const machine = createMachine<any, any>(
    {
        on: {
            EVENT: {
                actions: actions.pure(() => {
                    return [
                      // getting eslint xstate/no-imperative-action
                      send({ type: 'BLAH' })
                    ]
                }),
            },
        },
    },
)

Versions (please complete the following information):

Additional context If I use actions.send() it works, but I think that's because the eslint plugin doesn't actually execute in that case?

rlaffers commented 3 years ago

Thanks for the report. Definitely looks like a bug.

rlaffers commented 3 years ago

It is detected as a violation, because actions.pure is not recognized as THE pure action creator (which is the only context in which calling other action creators is sensible). I will add "actions.pure" into the list to allow for this usage.

rlaffers commented 3 years ago

:tada: This issue has been resolved in version 0.10.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

VanTanev commented 3 years ago

Thank you!