eslint-plugin-xstate
Advanced tools
Comparing version 0.10.0 to 0.10.1
'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": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
63113
1601