cypress-example-kitchensink icon indicating copy to clipboard operation
cypress-example-kitchensink copied to clipboard

Several advanced examples fail cypress/unsafe-to-chain-command lint rule

Open MikeMcC399 opened this issue 2 years ago • 9 comments

If the eslint rule cypress/unsafe-to-chain-command from eslint-plugin-cypress: Rules is enabled, then the following 6 examples in cypress/e2e/2-advanced-examples fail linting with the message:

"error It is unsafe to chain further commands that rely on the subject after this command. It is best to split the chain, chaining again from cy. in a next command line cypress/unsafe-to-chain-command"

"✖ 57 problems (51 errors, 0 warnings)"

Here is a portion of actions.cy.js which fails linting:

    cy.get('.action-email')
      .type('[email protected]').should('have.value', '[email protected]')

      // .type() with special character sequences
      .type('{leftarrow}{rightarrow}{uparrow}{downarrow}')
      .type('{del}{selectall}{backspace}')

      // .type() with key modifiers
      .type('{alt}{option}') //these are equivalent
      .type('{ctrl}{control}') //these are equivalent
      .type('{meta}{command}{cmd}') //these are equivalent
      .type('{shift}')

      // Delay each keypress by 0.1 sec
      .type('[email protected]', { delay: 100 })
      .should('have.value', '[email protected]') 

Expectation

Since the rule cypress/unsafe-to-chain-command is part of plugin:cypress/recommended rules according to eslint-plugin-cypress: Rules I would expect standard examples to pass this lint test.

Steps to reproduce

Add "cypress/unsafe-to-chain-command": "error" to rules of .eslintrc, similar to the following

  "rules": {
    "cypress/unsafe-to-chain-command": "error"
  }

Execute:

npm run lint

Reproducible example on https://github.com/MikeMcC399/cypress-example-kitchensink/tree/test/unsafe-to-chain

Environment

Next steps

  • [ ] Correct the examples

MikeMcC399 avatar May 02 '23 12:05 MikeMcC399

Hi @MikeMcC399 👋, thanks for logging this issue. I took a cursory look at the reported errors and the rule appears to be correct so we should do #2 and update the examples.

mschile avatar May 02 '23 20:05 mschile

Hi @mschile

Thank you very much for qualifying this issue!

I can't provide a solution for this issue, so I would be happy for the core team to make the changes in the examples.

MikeMcC399 avatar May 03 '23 04:05 MikeMcC399

  • I have proposed a fix for a related issue in https://github.com/cypress-io/cypress-example-kitchensink/pull/662. For the waiting issue I propose to ignore the rule.

MikeMcC399 avatar May 03 '23 05:05 MikeMcC399

@mschile

unsafe-to-chain is currently disabled in this repo pending update of the examples to conform to linting rules.

The latest new release from Aug 8, 2023 [email protected] causes additional 8 problems to be flagged if the rule is enabled:

✖ 59 problems (59 errors, 0 warnings)

instead of the previous

✖ 51 problems (51 errors, 0 warnings)

It would be good for the examples to be updated so that they can be used as a reference for what is correct. Perhaps this fix could be scheduled some time soon?

  • See also https://github.com/cypress-io/eslint-plugin-cypress/issues/140

MikeMcC399 avatar Aug 09 '23 10:08 MikeMcC399

Updating to [email protected] (current latest) causes now 59 "unsafe to chain" errors when checking with

  "rules": {
    "cypress/unsafe-to-chain-command": "error"
  }

The rule is currently disabled and waiting for the examples to be corrected so they conform to the chaining rules as described in the https://docs.cypress.io/api/table-of-contents documentation.

https://github.com/cypress-io/cypress-example-kitchensink/blob/a3327d9af69f78cc3f7d52e7477c5f067f07c8f3/.eslintrc#L17-L18

MikeMcC399 avatar Sep 20 '23 16:09 MikeMcC399

Unfortunately I'm unable to provide a PR to resolve this issue, which remains unaddressed.

Steps to reproduce

Comment out

https://github.com/cypress-io/cypress-example-kitchensink/blob/b49f532c383335ee8d5d8c1fa403b50e4cef496a/.eslintrc#L18

and then execute

npm run lint

shows

✖ 57 problems (57 errors, 0 warnings)

MikeMcC399 avatar Nov 22 '23 08:11 MikeMcC399

+1

enchorb avatar Jan 30 '24 21:01 enchorb

@MikeMcC399 I'd be fine with an update to the example recipes to reflect our new conventions. We just never revisited this.

jennifer-shehane avatar Feb 02 '24 16:02 jennifer-shehane

@jennifer-shehane

@MikeMcC399 I'd be fine with an update to the example recipes to reflect our new conventions. We just never revisited this.

This issue is still open because as I said previously I don't have the skills for this and nobody else has picked it up.

MikeMcC399 avatar Feb 02 '24 17:02 MikeMcC399

  • Thanks to @rubysolo for addressing this issue in #802 !

MikeMcC399 avatar Mar 12 '24 08:03 MikeMcC399

:tada: This issue has been resolved in version 2.0.3 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

cypress-app-bot avatar Mar 12 '24 14:03 cypress-app-bot