Skip to content

Commit

Permalink
refactor in the "chaining" rule
Browse files Browse the repository at this point in the history
  • Loading branch information
ganimomer committed Dec 9, 2018
1 parent 85084a9 commit c8b0ff3
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/rules/chaining.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,18 @@ module.exports = {
}
}

function reportOnSingleChain(node) {
if (isMethodCall(node) && (isEndOfChain(node) || isBeforeChainBreaker(node))) {
context.report({node, messageId: 'single'})
}
}

const callExpressionVisitors = {
always: node => {
if (isNestedNLevels(node, ruleDepth, true)) {
context.report({node, messageId: 'always'})
} else if (lodashContext.isLodashChainStart(node)) {
const firstCall = node.parent.parent
if (isMethodCall(firstCall) && (isEndOfChain(firstCall) || isBeforeChainBreaker(firstCall))) {
context.report({node: firstCall, messageId: 'single'})
}
reportOnSingleChain(node.parent.parent)
}
},
never: node => {
Expand All @@ -87,10 +90,7 @@ module.exports = {
if (isNestedNLevels(node, ruleDepth, false)) {
context.report({node, messageId: 'always'})
} else if (lodashContext.isLodashChainStart(node)) {
const firstCall = node.parent.parent
if (isMethodCall(firstCall) && (isEndOfChain(firstCall) || isBeforeChainBreaker(firstCall))) {
context.report({node: firstCall, messageId: 'single'})
}
reportOnSingleChain(node.parent.parent)
}
}
}
Expand Down

0 comments on commit c8b0ff3

Please sign in to comment.