Socket
Socket
Sign inDemoInstall

eslint-plugin-cypress

Package Overview
Dependencies
1
Maintainers
3
Versions
42
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.0.2 to 3.0.3

.eslintrc.js

9

docs/rules/assertion-before-screenshot.md

@@ -1,3 +0,4 @@

## Assertion Before Screenshot
# Require screenshots to be preceded by an assertion (`cypress/assertion-before-screenshot`)
<!-- end auto-generated rule header -->
If you take screenshots without assertions then you may get different screenshots depending on timing.

@@ -7,5 +8,7 @@

## Rule Details
This rule checks there is an assertion making sure your application state is correct before doing a screenshot. This makes sure the result of the screenshot will be consistent.
Invalid:
Examples of **incorrect** code for this rule:

@@ -17,3 +20,3 @@ ```js

Valid:
Examples of **correct** code for this rule:

@@ -20,0 +23,0 @@ ```js

@@ -1,3 +0,8 @@

## No Assigning Return Values
# Disallow assigning return values of `cy` calls (`cypress/no-assigning-return-values`)
💼 This rule is enabled in the ✅ `recommended` config.
<!-- end auto-generated rule header -->
## Further Reading
See [the Cypress Best Practices guide](https://on.cypress.io/best-practices#Assigning-Return-Values).

@@ -1,4 +0,5 @@

# Prevent using async/await in Cypress test cases (no-async-tests)
# Disallow using `async`/`await` in Cypress `before` methods (`cypress/no-async-before`)
Cypress commands that return a promise may cause side effects in before/beforeEach hooks, possibly causing unexpected behavior.
<!-- end auto-generated rule header -->
Cypress commands that return a promise may cause side effects in `before`/`beforeEach` hooks, possibly causing unexpected behavior.

@@ -41,3 +42,2 @@ ## Rule Details

})
```

@@ -47,3 +47,3 @@

If there are genuine use-cases for using `async/await` in your before then you may not want to include this rule (or at least demote it to a warning).
If there are genuine use-cases for using `async/await` in your `before` hooks then you may not want to include this rule (or at least demote it to a warning).

@@ -50,0 +50,0 @@ ## Further Reading

@@ -1,5 +0,9 @@

# Prevent using async/await in Cypress test cases (no-async-tests)
# Disallow using `async`/`await` in Cypress test cases (`cypress/no-async-tests`)
Cypress tests [that return a promise will error](https://docs.cypress.io/guides/references/error-messages.html#Cypress-detected-that-you-returned-a-promise-from-a-command-while-also-invoking-one-or-more-cy-commands-in-that-promise) and cannot run successfully. An `async` function returns a promise under the hood, so a test using an `async` function will also error.
💼 This rule is enabled in the ✅ `recommended` config.
<!-- end auto-generated rule header -->
Cypress tests [that return a promise will error](https://docs.cypress.io/guides/references/error-messages.html#Cypress-detected-that-you-returned-a-promise-from-a-command-while-also-invoking-one-or-more-cy-commands-in-that-promise) and cannot run successfully.
An `async` function returns a promise under the hood, so a test using an `async` function will also error.
## Rule Details

@@ -41,3 +45,2 @@

})
```

@@ -44,0 +47,0 @@

@@ -1,3 +0,4 @@

# disallow using of 'force: true' option (no-force)
# Disallow using `force: true` with action commands (`cypress/no-force`)
<!-- end auto-generated rule header -->
Using `force: true` on inputs appears to be confusing rather than helpful.

@@ -11,3 +12,3 @@ It usually silences the actual problem instead of providing a way to overcome it.

This rule aims to disallow using of the `force` option on:[`.click()`](https://on.cypress.io/click),
This rule disallows using the `force` option on:[`.click()`](https://on.cypress.io/click),
[`.dblclick()`](https://on.cypress.io/dblclick), [`.type()`](https://on.cypress.io/type),

@@ -17,6 +18,6 @@ [`.rightclick()`](https://on.cypress.io/rightclick), [`.select()`](https://on.cypress.io/select),

and [`.trigger()`](https://on.cypress.io/trigger).
Examples of **incorrect** code for this rule:
```js
cy.get('button').click({force: true})

@@ -31,3 +32,2 @@ cy.get('button').dblclick({force: true})

cy.get('input').focus({force: true})
```

@@ -38,3 +38,2 @@

```js
cy.get('button').click()

@@ -49,8 +48,6 @@ cy.get('button').click({multiple: true})

cy.get('input').focus()
```
## When Not To Use It
If you don't mind using `{ force: true }` with action commands, then turn this rule off.

@@ -1,7 +0,10 @@

## Do not use `cy.pause` command
# Disallow using `cy.pause()` calls (`cypress/no-pause`)
It is recommended to remove [cy.pause](https://on.cypress.io/pause) command before committing the specs to avoid other developers getting unexpected results.
<!-- end auto-generated rule header -->
It is recommended to remove any [cy.pause](https://on.cypress.io/pause) commands before committing specs to avoid other developers getting unexpected results.
Invalid:
## Rule Details
Examples of **incorrect** code for this rule:
```js

@@ -11,3 +14,3 @@ cy.pause();

Valid:
Examples of **correct** code for this rule:

@@ -14,0 +17,0 @@ ```js

@@ -1,3 +0,8 @@

## No Unnecessary Waiting
# Disallow waiting for arbitrary time periods (`cypress/no-unnecessary-waiting`)
💼 This rule is enabled in the ✅ `recommended` config.
<!-- end auto-generated rule header -->
## Further Reading
See [the Cypress Best Practices guide](https://on.cypress.io/best-practices#Unnecessary-Waiting).

@@ -1,11 +0,12 @@

## Only allow `data-*` attribute selectors (require-data-selectors)
only allow `cy.get` to allow selectors that target `data-*` attributes
# Require `data-*` attribute selectors (`cypress/require-data-selectors`)
See [the Cypress Best Practices guide](https://docs.cypress.io/guides/references/best-practices.html#Selecting-Elements).
<!-- end auto-generated rule header -->
Require `cy.get` to use only selectors that target `data-*` attributes.
> Note: If you use this rule, consider only using the `warn` error level, since using `data-*` attribute selectors may not always be possible.
### Rule Details
## Rule Details
examples of **incorrect** code with `require-data-selectors`:
Examples of **incorrect** code for this rule:
```js

@@ -19,3 +20,4 @@ cy.get(".a")

examples of **correct** code with `require-data-selectors`:
Examples of **correct** code for this rule:
```js

@@ -25,1 +27,5 @@ cy.get('[data-cy=submit]').click()

```
## Further Reading
See [the Cypress Best Practices guide](https://docs.cypress.io/guides/references/best-practices.html#Selecting-Elements).

@@ -1,3 +0,18 @@

## Unsafe to chain command
# Disallow actions within chains (`cypress/unsafe-to-chain-command`)
💼 This rule is enabled in the ✅ `recommended` config.
<!-- end auto-generated rule header -->
### Options
<!-- begin auto-generated rule options list -->
| Name | Description | Type | Default |
| :-------- | :---------------------------------------------------------- | :---- | :------ |
| `methods` | An additional list of methods to check for unsafe chaining. | Array | `[]` |
<!-- end auto-generated rule options list -->
## Further Reading
See [retry-ability guide](https://docs.cypress.io/guides/core-concepts/retry-ability#Actions-should-be-at-the-end-of-chains-not-the-middle).
{
"name": "eslint-plugin-cypress",
"version": "3.0.2",
"version": "3.0.3",
"description": "An ESLint plugin for projects using Cypress",

@@ -32,5 +32,5 @@ "main": "index.js",

"eslint-plugin-n": "^17.2.1",
"husky": "^8.0.3",
"husky": "^9.0.11",
"jest": "^29.7.0",
"semantic-release": "19.0.3"
"semantic-release": "23.0.8"
},

@@ -44,4 +44,4 @@ "scripts": {

"test-watch": "jest --watchAll",
"prepare": "husky install"
"prepare": "husky"
}
}

@@ -118,15 +118,21 @@ # Cypress ESLint Plugin [![CircleCI](https://circleci.com/gh/cypress-io/eslint-plugin-cypress/tree/master.svg?style=svg)](https://circleci.com/gh/cypress-io/eslint-plugin-cypress/tree/master)

Rules with a check mark (✅) are enabled by default while using the `plugin:cypress/recommended` config.
<!-- begin auto-generated rules list -->
| | Rule ID | Description |
| :-- | :------------------------------------------------------------------------- | :-------------------------------------------------------------- |
| ✅ | [no-assigning-return-values](./docs/rules/no-assigning-return-values.md) | Prevent assigning return values of cy calls |
| ✅ | [no-unnecessary-waiting](./docs/rules/no-unnecessary-waiting.md) | Prevent waiting for arbitrary time periods |
| ✅ | [no-async-tests](./docs/rules/no-async-tests.md) | Prevent using async/await in Cypress test case |
| ✅ | [unsafe-to-chain-command](./docs/rules/unsafe-to-chain-command.md) | Prevent chaining from unsafe to chain commands |
| | [no-force](./docs/rules/no-force.md) | Disallow using `force: true` with action commands |
| | [assertion-before-screenshot](./docs/rules/assertion-before-screenshot.md) | Ensure screenshots are preceded by an assertion |
| | [require-data-selectors](./docs/rules/require-data-selectors.md) | Only allow data-\* attribute selectors (require-data-selectors) |
| | [no-pause](./docs/rules/no-pause.md) | Disallow `cy.pause()` parent command |
💼 Configurations enabled in.\
✅ Set in the `recommended` configuration.
| Name | Description | 💼 |
| :----------------------------------------------------------------------- | :--------------------------------------------------------- | :- |
| [assertion-before-screenshot](docs/rules/assertion-before-screenshot.md) | require screenshots to be preceded by an assertion | |
| [no-assigning-return-values](docs/rules/no-assigning-return-values.md) | disallow assigning return values of `cy` calls | ✅ |
| [no-async-before](docs/rules/no-async-before.md) | disallow using `async`/`await` in Cypress `before` methods | |
| [no-async-tests](docs/rules/no-async-tests.md) | disallow using `async`/`await` in Cypress test cases | ✅ |
| [no-force](docs/rules/no-force.md) | disallow using `force: true` with action commands | |
| [no-pause](docs/rules/no-pause.md) | disallow using `cy.pause()` calls | |
| [no-unnecessary-waiting](docs/rules/no-unnecessary-waiting.md) | disallow waiting for arbitrary time periods | ✅ |
| [require-data-selectors](docs/rules/require-data-selectors.md) | require `data-*` attribute selectors | |
| [unsafe-to-chain-command](docs/rules/unsafe-to-chain-command.md) | disallow actions within chains | ✅ |
<!-- end auto-generated rules list -->
## Mocha and Chai

@@ -133,0 +139,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc