Skip to content

Commit

Permalink
eslint auto-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbreiding committed May 27, 2020
1 parent 0964b4e commit cdb1ce0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
23 changes: 14 additions & 9 deletions lib/rules/assertion-before-screenshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const assertionCommands = [
// not an assertion, but unlikely to require waiting for render
'scrollIntoView',
'scrollTo',
];
]

module.exports = {
meta: {
Expand All @@ -42,19 +42,22 @@ module.exports = {
},
}

function isRootCypress(node) {
while(node.type === 'CallExpression') {
function isRootCypress (node) {
while (node.type === 'CallExpression') {
if (node.callee.type !== 'MemberExpression') return false

if (node.callee.object.type === 'Identifier' &&
node.callee.object.name === 'cy') {
return true
}

node = node.callee.object
}

return false
}

function getPreviousInChain(node) {
function getPreviousInChain (node) {
return node.type === 'CallExpression' &&
node.callee.type === 'MemberExpression' &&
node.callee.object.type === 'CallExpression' &&
Expand All @@ -63,7 +66,7 @@ function getPreviousInChain(node) {
node.callee.object.callee.property.name
}

function getCallExpressionCypressCommand(node) {
function getCallExpressionCypressCommand (node) {
return isRootCypress(node) &&
node.callee.property.type === 'Identifier' &&
node.callee.property.name
Expand All @@ -73,14 +76,14 @@ function isCallingCyScreenshot (node) {
return getCallExpressionCypressCommand(node) === 'screenshot'
}

function getPreviousCypressCommand(node) {
function getPreviousCypressCommand (node) {
const previousInChain = getPreviousInChain(node)

if (previousInChain) {
return previousInChain
}

while(node.parent && !node.parent.body) {
while (node.parent && !node.parent.body) {
node = node.parent
}

Expand All @@ -93,18 +96,20 @@ function getPreviousCypressCommand(node) {
// in the case of a function declaration it won't be found
if (index < 0) return null

if (index === 0) return getPreviousCypressCommand(node.parent);
if (index === 0) return getPreviousCypressCommand(node.parent)

const previousStatement = body[index - 1]

if (previousStatement.type !== 'ExpressionStatement' ||
previousStatement.expression.type !== 'CallExpression')
previousStatement.expression.type !== 'CallExpression') {
return null
}

return getCallExpressionCypressCommand(previousStatement.expression)
}

function isPreviousAnAssertion (node) {
const previousCypressCommand = getPreviousCypressCommand(node)

return assertionCommands.indexOf(previousCypressCommand) >= 0
}
5 changes: 5 additions & 0 deletions lib/rules/no-assigning-return-values.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@
// safely get nested object property
function get (obj, propertyString = '') {
const properties = propertyString.split('.')

for (let i = 0; i < properties.length; i++) {
const value = (obj || {})[properties[i]]

if (value == null) return value

obj = value
}

return obj
}

Expand Down Expand Up @@ -57,6 +61,7 @@ function isCypressCommandDeclaration (declarator) {

if (!object) return
}

const commandName = get(declarator, 'init.callee.property.name')

if (commandName && whitelistedCommands[commandName]) return
Expand Down

0 comments on commit cdb1ce0

Please sign in to comment.