Skip to content

Commit

Permalink
Merge pull request #9 from fluidly/reducer-must-handle-switch-organis…
Browse files Browse the repository at this point in the history
…ation-2

Reducer must handle switch organisation
  • Loading branch information
miketownsend committed Nov 18, 2019
2 parents 61507cd + cf73edd commit b43098b
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 96 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -23,7 +23,7 @@
"devDependencies": {
"babel-eslint": "^9.0.0",
"date-fns": "^2.0.0",
"eslint": "^5.5.0",
"eslint": "^6.6.0",
"jest": "^23.5.0",
"prettier": "^1.14.2",
"pretty-quick": "^1.6.0"
Expand Down
17 changes: 5 additions & 12 deletions rules/reducer-must-handle-switch-organisation.js
Expand Up @@ -16,21 +16,16 @@ const getNodeChildren = node => {

const getNodeChildrenRaw = node => {
if (!node) return
if (node.type === 'Literal') return
if (node.type === 'ReturnStatement') return
if (node.type === 'VariableDeclaration') return
if (node.type === 'CallExpression') return

if (node.body) return node.body

if (node.type === 'IfStatement')
return [node.test, node.consequent, node.alternate]
if (node.type === 'MethodDefinition') return [node.value]
if (node.type === 'SwitchStatement') return node.cases
if (node.type === 'SwitchCase') return [node.test, ...node.consequent]
if (node.type === 'ExpressionStatement') return [node.expression]

console.log(
'UNKNOWN',
node.type,
omit(['expression', 'parent', 'loc', '_babelType', 'start', 'end'])(node)
)
return
}

module.exports = {
Expand All @@ -44,9 +39,7 @@ module.exports = {

const findSwitchOrganisationConstant = node => {
if (!node) return
console.log('Node', file, node.type)

// if this is an identifier, return true if it is SWITCH_ORGANISATION
if (
node.type === 'Identifier' &&
node.name === 'SWITCH_ORGANISATION' &&
Expand Down

0 comments on commit b43098b

Please sign in to comment.