Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: unsafe-to-chain-command: Fix the false positive of 'focus' regex matching 'focused' #142

Merged
merged 2 commits into from Sep 18, 2023
Merged

fix: unsafe-to-chain-command: Fix the false positive of 'focus' regex matching 'focused' #142

merged 2 commits into from Sep 18, 2023

Conversation

dominicfraser
Copy link
Contributor

@dominicfraser dominicfraser commented Sep 15, 2023

Addresses/ illustrates #140.

In #137 the unsafe-to-chain-command added a list of values to use as default unsafe commands.

Part of this list was

const unsafeToChainActions = [
  'blur',
  'clear',
  'click',
  'focus',
]

This is then used to create a regex

const isActionUnsafeToChain = (node, additionalMethods = []) => {
  const unsafeActionsRegex = new RegExp([
    ...unsafeToChainActions,
    ...additionalMethods.map((method) => method instanceof RegExp ? method.source : method),
  ].join('|'))

Using just the above this could be seen as

/blur|clear|click|focus/

However this regex is over zealous, it matches on focused as well as focus.

Focus is a safe command to chain. It is a query, not an action.

It is specified as safe in https://docs.cypress.io/api/commands/focused#Syntax.

This PR illustrates the problem, with a potential solution. If the implementation is reverted the test fails.

@CLAassistant
Copy link

CLAassistant commented Sep 15, 2023

CLA assistant check
All committers have signed the CLA.

@cypress-app-bot
Copy link

@nagash77
Copy link
Contributor

@dominicfraser good catch! Can you sign the CLA and I will get this merged in. Thanks for your PR!

@dominicfraser dominicfraser changed the title unsafe-to-chain-command: illustrate the false positive of 'focus' regex matching 'focused' unsafe-to-chain-command: Fix the false positive of 'focus' regex matching 'focused' Sep 15, 2023
@dominicfraser
Copy link
Contributor Author

No problem!

@nagash77 nagash77 merged commit d5b89f4 into cypress-io:master Sep 18, 2023
7 checks passed
@dominicfraser dominicfraser deleted the chain_command_focused_false_positive branch September 18, 2023 12:57
@dqiubread
Copy link

@nagash77 any idea when a new release can be cut for this?

@nagash77 nagash77 changed the title unsafe-to-chain-command: Fix the false positive of 'focus' regex matching 'focused' fix: unsafe-to-chain-command: Fix the false positive of 'focus' regex matching 'focused' Sep 18, 2023
@MikeMcC399
Copy link
Collaborator

The release is tagged as https://github.com/cypress-io/eslint-plugin-cypress/releases/tag/v2.15.0 however the release failed as far as publishing to npm is concerned:

$ npm view eslint-plugin-cypress dist-tags
{ latest: '2.14.0' }

https://app.circleci.com/pipelines/github/cypress-io/eslint-plugin-cypress/170/workflows/e8b32fd1-8ac5-4395-908f-c42d60408a3c/jobs/674

@dqiubread
Copy link

The Circleci error looks like its an error with permissions

@MikeMcC399
Copy link
Collaborator

@dqiubread

The Circleci error looks like its an error with permissions

@dqiubread
Copy link

@dqiubread

The Circleci error looks like its an error with permissions

I see it now thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants