Repository: cypress-io/eslint-plugin-cypress (js)

Issue:
cypress/no-pause is not working if the command is chained
I using Intellij with eslint in my Project.

If I use pause as a parent command the linter works fine.

cy.pause();

If I use pause as a child command nothing is highlighted.

cy.get('p').pause();

Pull request:
feat: apply no-pause rule recursively
## Issue

The `cypress/no-pause` rule only applies to a parent node. 

## Changes

Convert the `isCypressCall` function into a recursive function to detect chained calls such as `cy.get("...").pause();`.

Closes #147 

Patch:
diff --git a/docs/rules/no-pause.md b/docs/rules/no-pause.md
index 49ead92..d15079d 100644
--- a/docs/rules/no-pause.md
+++ b/docs/rules/no-pause.md
@@ -9,11 +9,11 @@ Examples of **incorrect** code for this rule:
 
 ```js
 cy.pause();
+cy.get('selector').pause();
 ```
 
 Examples of **correct** code for this rule:
 
 ```js
-// only the parent cy.pause command is detected
-cy.get('selector').pause();
+cy.get('selector')
 ```
diff --git a/lib/rules/no-pause.js b/lib/rules/no-pause.js
index 93aa7f8..b7f2b51 100644
--- a/lib/rules/no-pause.js
+++ b/lib/rules/no-pause.js
@@ -35,12 +35,15 @@ module.exports = {
     }
 
     function isCypressCall (node) {
-      return node.callee &&
-        node.callee.type === 'MemberExpression' &&
-        node.callee.object.type === 'Identifier' &&
-        node.callee.object.name === 'cy'
+      if (!node.callee || node.callee.type !== 'MemberExpression') {
+        return false;
+      }
+      if (node.callee.object.type === 'Identifier' && node.callee.object.name === 'cy') {
+        return true;
+      }
+      return isCypressCall(node.callee.object);
     }
-
+    
     //----------------------------------------------------------------------
     // Public
     //----------------------------------------------------------------------


Test patch:
diff --git a/tests/lib/rules/no-pause.js b/tests/lib/rules/no-pause.js
index 24c2b50..5d296d1 100644
--- a/tests/lib/rules/no-pause.js
+++ b/tests/lib/rules/no-pause.js
@@ -20,14 +20,18 @@ const ruleTester = new RuleTester()
 ruleTester.run('no-pause', rule, {
 
   valid: [
-    // for now, we do not detect .pause() child command
-    { code: `cy.get('button').pause()`, parserOptions },
     { code: `pause()`, parserOptions },
     { code: `cy.get('button').dblclick()`, parserOptions },
   ],
-
+  
   invalid: [
     { code: `cy.pause()`, parserOptions, errors },
     { code: `cy.pause({ log: false })`, parserOptions, errors },
+    { code: `cy.get('button').pause()`, parserOptions, errors },
+    { 
+      code: `cy.get('a').should('have.attr', 'href').and('match', /dashboard/).pause()`, 
+      parserOptions, 
+      errors 
+    }
   ],
 })