Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

eslint-plugin-xstate

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-xstate - npm Package Compare versions

Comparing version 0.10.0 to 0.10.1

137

lib/rules/no-inline-implementation.js
'use strict'
const getDocsUrl = require('../utils/getDocsUrl')
const isInsideMachineDeclaration = require('../utils/isInsideMachineDeclaration')
const {

@@ -32,2 +31,34 @@ isFunctionExpression,

// states: { idle: { on: { EVENT: { target: 'active' }}}}
const propertyOfEventTransition =
'CallExpression[callee.name=/^createMachine$|^Machine$/] Property[key.name="on"] > ObjectExpression > Property > ObjectExpression > Property'
// states: { idle: { on: { EVENT: [{ target: 'active' }]}}}
const propertyOfEventTransitionInArray =
'CallExpression[callee.name=/^createMachine$|^Machine$/] Property[key.name="on"] > ObjectExpression > Property > ArrayExpression > ObjectExpression > Property'
// states: { idle: { on: [ { event: 'EVENT', target: 'active' } ]}}
const propertyOfAltEventTransitionInArray =
'CallExpression[callee.name=/^createMachine$|^Machine$/] Property[key.name="on"] > ArrayExpression > ObjectExpression > Property'
const srcPropertyInsideInvoke =
'CallExpression[callee.name=/^createMachine$|^Machine$/] Property[key.name="invoke"] > ObjectExpression > Property[key.name="src"]'
const srcPropertyInsideInvokeArray =
'CallExpression[callee.name=/^createMachine$|^Machine$/] Property[key.name="invoke"] > ArrayExpression > ObjectExpression > Property[key.name="src"]'
const entryExitProperty =
'CallExpression[callee.name=/^createMachine$|^Machine$/] Property[key.name=/^entry$|^exit$/]'
// invoke: { onDone: { target: 'active' }}
const propertyOfOnDoneOnErrorTransition =
'CallExpression[callee.name=/^createMachine$|^Machine$/] Property[key.name=/^onDone$|^onError$/] > ObjectExpression > Property'
// invoke: { onDone: [{ target: 'active' }] }
const propertyOfOnDoneOnErrorTransitionInArray =
'CallExpression[callee.name=/^createMachine$|^Machine$/] Property[key.name=/^onDone$|^onError$/] > ArrayExpression > ObjectExpression > Property'
const activitiesProperty =
'CallExpression[callee.name=/^createMachine$|^Machine$/] Property[key.name="activities"]'
const defaultOptions = {

@@ -74,5 +105,2 @@ allowKnownActionCreators: false,

function checkServiceSrc(node) {
if (!isInsideMachineDeclaration(node)) {
return
}
if (

@@ -99,63 +127,60 @@ !isStringLiteral(node.value) &&

return {
'Property[key.name="on"] > ObjectExpression > Property > ObjectExpression > Property':
function (node) {
if (!isInsideMachineDeclaration(node)) {
return
}
if (
node.key.name === 'cond' &&
(isFunctionExpression(node.value) ||
isIdentifier(node.value) ||
isCallExpression(node.value))
) {
context.report({
node,
messageId: 'moveGuardToOptions',
})
return
}
function checkTransitionProperty(node) {
if (
node.key.name === 'cond' &&
(isFunctionExpression(node.value) ||
isIdentifier(node.value) ||
isCallExpression(node.value))
) {
context.report({
node,
messageId: 'moveGuardToOptions',
})
return
}
if (node.key.name === 'actions') {
if (isInlineAction(node.value, options.allowKnownActionCreators)) {
if (node.key.name === 'actions') {
if (isInlineAction(node.value, options.allowKnownActionCreators)) {
context.report({
node,
messageId: 'moveActionToOptions',
})
} else if (isArrayExpression(node.value)) {
node.value.elements.forEach((element) => {
if (isInlineAction(element, options.allowKnownActionCreators)) {
context.report({
node,
node: element,
messageId: 'moveActionToOptions',
})
return
} else if (isArrayExpression(node.value)) {
node.value.elements.forEach((element) => {
if (isInlineAction(element, options.allowKnownActionCreators)) {
context.report({
node: element,
messageId: 'moveActionToOptions',
})
}
})
return
}
}
})
}
}
}
if (
node.key.name === 'activities' &&
(isFunctionExpression(node.value) ||
isIdentifier(node.value) ||
isArrayWithFunctionExpressionOrIdentifier(node.value))
) {
context.report({
node,
messageId: 'moveActivityToOptions',
})
}
},
return {
[propertyOfEventTransition]: checkTransitionProperty,
[propertyOfEventTransitionInArray]: checkTransitionProperty,
[propertyOfAltEventTransitionInArray]: checkTransitionProperty,
[propertyOfOnDoneOnErrorTransition]: checkTransitionProperty,
[propertyOfOnDoneOnErrorTransitionInArray]: checkTransitionProperty,
'Property[key.name="invoke"] > ObjectExpression > Property[key.name="src"]':
checkServiceSrc,
'Property[key.name="invoke"] > ArrayExpression > ObjectExpression > Property[key.name="src"]':
checkServiceSrc,
'Property[key.name=/^entry$|^exit$/]': function (node) {
if (!isInsideMachineDeclaration(node)) {
return
[activitiesProperty]: function (node) {
if (
isFunctionExpression(node.value) ||
isIdentifier(node.value) ||
isArrayWithFunctionExpressionOrIdentifier(node.value)
) {
context.report({
node,
messageId: 'moveActivityToOptions',
})
}
},
[srcPropertyInsideInvoke]: checkServiceSrc,
[srcPropertyInsideInvokeArray]: checkServiceSrc,
[entryExitProperty]: function (node) {
if (isInlineAction(node.value, options.allowKnownActionCreators)) {

@@ -162,0 +187,0 @@ context.report({

{
"name": "eslint-plugin-xstate",
"version": "0.10.0",
"version": "0.10.1",
"description": "ESLint rules for XState",

@@ -5,0 +5,0 @@ "keywords": [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc