Several advanced examples fail cypress/unsafe-to-chain-command lint rule
MikeMcC399 opened this issue · comments
If the eslint rule cypress/unsafe-to-chain-command
from eslint-plugin-cypress: Rules is enabled, then the following five 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"
"✖ 51 problems (51 errors, 0 warnings)"
Here is a portion of actions.cy.js which fails linting:
cy.get('.action-email')
.type('fake@email.com').should('have.value', 'fake@email.com')
// .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('slow.typing@email.com', { delay: 100 })
.should('have.value', 'slow.typing@email.com')
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
- eslint@8.38.0
- eslint-plugin-cypress@2.13.2 (current
latest
)
Next steps
-
Review if the rule
cypress/unsafe-to-chain-command
is correctly reporting an error in the examples, then if this is correct, decide -
should the examples be changed?
-
or should the rule be disabled in the examples
/* eslint-disable cypress/unsafe-to-chain-command */
- If the rule is incorrect, then change the rule in eslint-plugin-cypress: Rules
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.
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.
- I have proposed a fix for a related issue in #662. For the waiting issue I propose to ignore the rule.
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 eslint-plugin-cypress@2.14.0 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 cypress-io/eslint-plugin-cypress#140