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

Issue:
cy.focused().type("text") shows cypress/unsafe-to-chain-command error
After an update to 2.14.0, the  cypress/unsafe-to-chain-command rule is triggered by code as
`cy.focused().type("text")`.
This should be no problem however, as the cypress docu states `cy.focused() is a query, and it is safe to chain further commands` (https://docs.cypress.io/api/commands/focused)

Pull request description:
fix: issue with unsafe to chain command that is not an action
On version v2.14.0 it seems there is a change in the **unsafe-to-chain-command** rule that causes the following issue:

https://github.com/cypress-io/eslint-plugin-cypress/issues/140

This is probably a quick fix on this without changing the Regex used by additional methods. The test covers the case where there is a command that is not considered an action for Cypress.

- closes #140

Patch:
diff --git a/lib/rules/unsafe-to-chain-command.js b/lib/rules/unsafe-to-chain-command.js
index 9fce903..712bef6 100644
--- a/lib/rules/unsafe-to-chain-command.js
+++ b/lib/rules/unsafe-to-chain-command.js
@@ -19,7 +19,7 @@ const unsafeToChainActions = [
   'check',
   'dblclick',
   'each',
-  'focus$',
+  'focus',
   'rightclick',
   'screenshot',
   'scrollIntoView',
@@ -130,7 +130,7 @@ const isRootCypress = (node) => {
  */
 const isActionUnsafeToChain = (node, additionalMethods = []) => {
   const unsafeActionsRegex = new RegExp([
-    ...unsafeToChainActions,
+    ...unsafeToChainActions.map((action) => `^${action}$`),
     ...additionalMethods.map((method) => method instanceof RegExp ? method.source : method),
   ].join('|'))
 


Test patch:
diff --git a/tests/lib/rules/unsafe-to-chain-command.js b/tests/lib/rules/unsafe-to-chain-command.js
index c79b8e6..470bebd 100644
--- a/tests/lib/rules/unsafe-to-chain-command.js
+++ b/tests/lib/rules/unsafe-to-chain-command.js
@@ -18,6 +18,10 @@ ruleTester.run('action-ends-chain', rule, {
       code: 'cy.focused().should("be.visible");',
       parserOptions,
     },
+    {
+      code: 'cy.submitBtn().click();',
+      parserOptions,
+    },
   ],
 
   invalid: [