Repository: cypress-io/eslint-plugin-cypress
Pull request #79 (2021-04-23 12:44:27)

fix: Fix crashing bug in no-force rule when using spread operator
This was causing my Eslint to crash, I think on the cy.document({ log: false }) nodes if someone is interested in that, so just quickly fixed it

chrisbreiding: Thanks! Could you add [a test for it](https://github.com/cypress-io/eslint-plugin-cypress/blob/master/tests/lib/rules/no-force.js) please?
emilgoldsmith: Hi chris. I can, but it would have to wait at least until my next free
weekend which is in at least 2 weeks, you or someone else are welcome to
add it and merge it before if you have the bandwidth earlier though

On Mon, 26 Apr 2021 at 16.30, Chris Breiding ***@***.***>
wrote:

> Thanks! Could you add a test for it
> <https://github.com/cypress-io/eslint-plugin-cypress/blob/master/tests/lib/rules/no-force.js>
> please?
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/cypress-io/eslint-plugin-cypress/pull/79#issuecomment-826881805>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AEKO66VLG5KZYJSDBMXCJ3DTKV2IVANCNFSM43OSPQFQ>
> .
>

emilgoldsmith: Actually I have some time now on this random Monday as I'm recovering from a full on weekend so this is actually a nice little task, so I'll do that now :)
emilgoldsmith: Okay added!

It looks like it was the spread operator that was causing issues,  I used a trimmed down version for exactly what fails of the example that had failed in my own code as the test case. 

I had to first debug that it wasn't parsing the spread operator, which was because the test ecmaVersion was too low so I upped that, and I also noticed that there were a lot of redundant error options for the valid test cases which aren't even part of the spec so I removed those, hope that's okay too



Patch:
diff --git a/lib/rules/no-force.js b/lib/rules/no-force.js
index 123f6e2..ddf460e 100644
--- a/lib/rules/no-force.js
+++ b/lib/rules/no-force.js
@@ -42,7 +42,7 @@ module.exports = {
 
       return node.arguments && node.arguments.length &&
       node.arguments.some((arg) => {
-        return arg.type === 'ObjectExpression' && arg.properties.some((propNode) => propNode.key.name === 'force')
+        return arg.type === 'ObjectExpression' && arg.properties.some((propNode) => propNode.key && propNode.key.name === 'force')
       })
     }
 


Test patch:
diff --git a/tests/lib/rules/no-force.js b/tests/lib/rules/no-force.js
index ad6aa0c..8643925 100644
--- a/tests/lib/rules/no-force.js
+++ b/tests/lib/rules/no-force.js
@@ -9,7 +9,7 @@ const rule = require('../../../lib/rules/no-force')
 const RuleTester = require('eslint').RuleTester
 
 const errors = [{ messageId: 'unexpected' }]
-const parserOptions = { ecmaVersion: 6 }
+const parserOptions = { ecmaVersion: 2018 }
 
 //------------------------------------------------------------------------------
 // Tests
@@ -24,12 +24,13 @@ ruleTester.run('no-force', rule, {
     { code: `cy.get('button').click({multiple: true})`, parserOptions },
     { code: `cy.get('button').dblclick()`, parserOptions },
     { code: `cy.get('input').type('somth')`, parserOptions },
-    { code: `cy.get('input').type('somth', {anyoption: true})`, parserOptions, errors },
-    { code: `cy.get('input').trigger('click', {anyoption: true})`, parserOptions, errors },
-    { code: `cy.get('input').rightclick({anyoption: true})`, parserOptions, errors },
-    { code: `cy.get('input').check()`, parserOptions, errors },
-    { code: `cy.get('input').select()`, parserOptions, errors },
-    { code: `cy.get('input').focus()`, parserOptions, errors },
+    { code: `cy.get('input').type('somth', {anyoption: true})`, parserOptions },
+    { code: `cy.get('input').trigger('click', {anyoption: true})`, parserOptions },
+    { code: `cy.get('input').rightclick({anyoption: true})`, parserOptions },
+    { code: `cy.get('input').check()`, parserOptions },
+    { code: `cy.get('input').select()`, parserOptions },
+    { code: `cy.get('input').focus()`, parserOptions },
+    { code: `cy.document().trigger("keydown", { ...event })`, parserOptions },
   ],
 
   invalid: [