Skip to content

Commit 3f22c8e

Browse files
committed
Merge remote-tracking branch 'origin/fix/issue-with-unsafe-to-chain-command-that-is-not-action' into fix/issue-with-unsafe-to-chain-command-that-is-not-action
2 parents edc37e4 + 4d239b0 commit 3f22c8e

31 files changed

+13941
-19950
lines changed

.eslintrc.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
module.exports = {
2+
"env": {
3+
"node": true,
4+
"es6": true
5+
},
6+
"plugins": [
7+
"eslint-plugin",
8+
"n",
9+
"mocha"
10+
],
11+
"extends": [
12+
"eslint:recommended",
13+
"plugin:eslint-plugin/recommended",
14+
"plugin:n/recommended",
15+
"plugin:mocha/recommended"
16+
],
17+
"rules": {
18+
"eslint-plugin/require-meta-docs-url":
19+
["error", { "pattern": "https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/{{name}}.md" }],
20+
"eslint-plugin/require-meta-docs-description": "error",
21+
"n/no-extraneous-require":
22+
["error", { "allowModules": ["jest-config"] }],
23+
"no-redeclare": "off",
24+
"mocha/no-mocha-arrows": "off",
25+
"mocha/no-setup-in-describe": "off"
26+
},
27+
"parserOptions": {
28+
"ecmaVersion": 2020
29+
}
30+
}

.eslintrc.json

Lines changed: 0 additions & 8 deletions
This file was deleted.

.husky/pre-commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
npm run lint

.node-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
20.12.2

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
20.12.2

CONTRIBUTING.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Contributing to cypress-io/eslint-plugin-cypress
2+
3+
Thanks for taking the time to contribute! :smile:
4+
5+
To add a new rule:
6+
* Fork and clone this repository
7+
* Generate a new rule (a [yeoman generator](https://github.com/eslint/generator-eslint) is available)
8+
* Write test scenarios then implement logic
9+
* Describe the rule in the generated `docs` file
10+
* Run `npm test` to run [Jest](https://jestjs.io/) or
11+
* Run `npm start` to run [Jest](https://jestjs.io/) in [watchAll](https://jestjs.io/docs/cli#--watchall) mode where it remains active and reruns when source changes are made
12+
* Make sure all tests are passing
13+
* Add the rule to the [README](README.md) file
14+
* Create a PR
15+
16+
Use the following commit message conventions: https://github.com/semantic-release/semantic-release#commit-message-format

README.md

Lines changed: 59 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Note: If you installed ESLint globally then you must also install `eslint-plugin
66

77
## Installation
88

9+
Prerequisites: [ESLint](https://www.npmjs.com/package/eslint) `v7` or `v8`. ESLint `v9` is **not** supported yet.
10+
911
```sh
1012
npm install eslint-plugin-cypress --save-dev
1113
```
@@ -36,6 +38,7 @@ You can add rules:
3638
"cypress/assertion-before-screenshot": "warn",
3739
"cypress/no-force": "warn",
3840
"cypress/no-async-tests": "error",
41+
"cypress/no-async-before": "error",
3942
"cypress/no-pause": "error"
4043
}
4144
}
@@ -112,20 +115,62 @@ For more, see the [ESLint rules](https://eslint.org/docs/user-guide/configuring/
112115

113116
These rules enforce some of the [best practices recommended for using Cypress](https://on.cypress.io/best-practices).
114117

115-
Rules with a check mark (✅) are enabled by default while using the `plugin:cypress/recommended` config.
118+
<!-- begin auto-generated rules list -->
119+
120+
💼 Configurations enabled in.\
121+
✅ Set in the `recommended` configuration.
122+
123+
| Name | Description | 💼 |
124+
| :----------------------------------------------------------------------- | :--------------------------------------------------------- | :- |
125+
| [assertion-before-screenshot](docs/rules/assertion-before-screenshot.md) | require screenshots to be preceded by an assertion | |
126+
| [no-assigning-return-values](docs/rules/no-assigning-return-values.md) | disallow assigning return values of `cy` calls ||
127+
| [no-async-before](docs/rules/no-async-before.md) | disallow using `async`/`await` in Cypress `before` methods | |
128+
| [no-async-tests](docs/rules/no-async-tests.md) | disallow using `async`/`await` in Cypress test cases ||
129+
| [no-force](docs/rules/no-force.md) | disallow using `force: true` with action commands | |
130+
| [no-pause](docs/rules/no-pause.md) | disallow using `cy.pause()` calls | |
131+
| [no-unnecessary-waiting](docs/rules/no-unnecessary-waiting.md) | disallow waiting for arbitrary time periods ||
132+
| [require-data-selectors](docs/rules/require-data-selectors.md) | require `data-*` attribute selectors | |
133+
| [unsafe-to-chain-command](docs/rules/unsafe-to-chain-command.md) | disallow actions within chains ||
134+
135+
<!-- end auto-generated rules list -->
136+
137+
## Mocha and Chai
138+
139+
Cypress is built on top of [Mocha](https://on.cypress.io/guides/references/bundled-libraries#Mocha) and [Chai](https://on.cypress.io/guides/references/bundled-libraries#Chai). See the following sections for information on using ESLint plugins [eslint-plugin-mocha](https://www.npmjs.com/package/eslint-plugin-mocha) and [eslint-plugin-chai-friendly](https://www.npmjs.com/package/eslint-plugin-chai-friendly) together with `eslint-plugin-cypress`.
140+
141+
## Mocha `.only` and `.skip`
142+
143+
During test spec development, [Mocha exclusive tests](https://mochajs.org/#exclusive-tests) `.only` or [Mocha inclusive tests](https://mochajs.org/#inclusive-tests) `.skip` may be used to control which tests are executed, as described in the Cypress documentation [Excluding and Including Tests](https://on.cypress.io/guides/core-concepts/writing-and-organizing-tests#Excluding-and-Including-Tests). To apply corresponding rules, you can install and use [eslint-plugin-mocha](https://www.npmjs.com/package/eslint-plugin-mocha). The rule [mocha/no-exclusive-tests](https://github.com/lo1tuma/eslint-plugin-mocha/blob/main/docs/rules/no-exclusive-tests.md) detects the use of `.only` and the [mocha/no-skipped-tests](https://github.com/lo1tuma/eslint-plugin-mocha/blob/main/docs/rules/no-skipped-tests.md) rule detects the use of `.skip`:
144+
145+
```sh
146+
npm install --save-dev eslint-plugin-mocha
147+
```
148+
149+
In your `.eslintrc.json`:
150+
151+
```json
152+
{
153+
"plugins": [
154+
"cypress",
155+
"mocha"
156+
],
157+
"rules": {
158+
"mocha/no-exclusive-tests": "warn",
159+
"mocha/no-skipped-tests": "warn"
160+
}
161+
}
162+
```
116163

117-
**NOTE**: These rules currently require eslint 5.0 or greater. If you would like support added for eslint 4.x, please 👍 [this issue](https://github.com/cypress-io/eslint-plugin-cypress/issues/14).
164+
Or you can simply use the `cypress/recommended` and `mocha/recommended` configurations together, for example:
118165

119-
| | Rule ID | Description |
120-
| :-- | :------------------------------------------------------------------------- | :-------------------------------------------------------------- |
121-
|| [no-assigning-return-values](./docs/rules/no-assigning-return-values.md) | Prevent assigning return values of cy calls |
122-
|| [no-unnecessary-waiting](./docs/rules/no-unnecessary-waiting.md) | Prevent waiting for arbitrary time periods |
123-
|| [no-async-tests](./docs/rules/no-async-tests.md) | Prevent using async/await in Cypress test case |
124-
|| [unsafe-to-chain-command](./docs/rules/unsafe-to-chain-command.md) | Prevent chaining from unsafe to chain commands |
125-
| | [no-force](./docs/rules/no-force.md) | Disallow using `force: true` with action commands |
126-
| | [assertion-before-screenshot](./docs/rules/assertion-before-screenshot.md) | Ensure screenshots are preceded by an assertion |
127-
| | [require-data-selectors](./docs/rules/require-data-selectors.md) | Only allow data-\* attribute selectors (require-data-selectors) |
128-
| | [no-pause](./docs/rules/no-pause.md) | Disallow `cy.pause()` parent command |
166+
```json
167+
{
168+
"extends": [
169+
"plugin:cypress/recommended",
170+
"plugin:mocha/recommended"
171+
]
172+
}
173+
```
129174

130175
## Chai and `no-unused-expressions`
131176

@@ -158,16 +203,6 @@ Or you can simply add its `recommended` config:
158203
}
159204
```
160205

161-
## Contribution Guide
162-
163-
To add a new rule:
164-
* Fork and clone this repository
165-
* Generate a new rule (a [yeoman generator](https://github.com/eslint/generator-eslint) is available)
166-
* Run `yarn start` or `npm start`
167-
* Write test scenarios then implement logic
168-
* Describe the rule in the generated `docs` file
169-
* Make sure all tests are passing
170-
* Add the rule to this README
171-
* Create a PR
206+
## Contributing
172207

173-
Use the following commit message conventions: https://github.com/semantic-release/semantic-release#commit-message-format
208+
Please see our [Contributing Guideline](./CONTRIBUTING.md) which explains how to contribute rules or other fixes and features to the repo.

circle.yml

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@ workflows:
55
main:
66
jobs:
77
- lint
8-
- test-v4
9-
- test-v5
10-
- test-v6
8+
- test-v7
9+
- test-v8
1110
- release:
1211
requires:
1312
- lint
14-
- test-v4
15-
- test-v5
16-
- test-v6
13+
- test-v7
14+
- test-v8
1715
filters:
1816
branches:
1917
only:
@@ -22,60 +20,66 @@ workflows:
2220
jobs:
2321
lint:
2422
docker:
25-
- image: circleci/node:16
23+
- image: cimg/node:20.12.2
2624
steps:
2725
- checkout
2826
- run:
2927
name: Install dependencies
30-
command: npm install
28+
command: npm ci
29+
- run:
30+
name: Show ESLint version
31+
command: npx eslint --version
3132
- run:
3233
name: Lint code
3334
command: npm run lint
3435

35-
test-v4:
36+
test-v7:
3637
docker:
37-
- image: circleci/node:16
38+
- image: cimg/node:20.12.2
3839
steps:
3940
- checkout
4041
- run:
4142
name: Install dependencies
42-
command: npm install
43+
command: npm ci
4344
- run:
44-
name: Test ESLint 4
45-
command: npm run test:v4
46-
47-
test-v5:
48-
docker:
49-
- image: circleci/node:16
50-
steps:
51-
- checkout
45+
name: Remove unneeded plugins # minimum [email protected] required
46+
command: npm uninstall eslint-plugin-eslint-plugin eslint-plugin-n
5247
- run:
53-
name: Install dependencies
54-
command: npm install
48+
name: Install ESLint 7
49+
command: npm install eslint@7
50+
- run:
51+
name: Show ESLint version
52+
command: npx eslint --version
5553
- run:
56-
name: Test ESLint 5
57-
command: npm run test
54+
name: Test ESLint 7
55+
command: npm test
5856

59-
test-v6:
57+
test-v8:
6058
docker:
61-
- image: circleci/node:16
59+
- image: cimg/node:20.12.2
6260
steps:
6361
- checkout
6462
- run:
6563
name: Install dependencies
66-
command: npm install
64+
command: npm ci
65+
- run:
66+
name: Install ESLint 8
67+
command: npm install eslint@8
68+
- run:
69+
name: Show ESLint version
70+
command: npx eslint --version
6771
- run:
68-
name: Test ESLint 6
69-
command: npm run test:v6
72+
name: Test ESLint 8
73+
command: npm test
7074

7175
release:
7276
docker:
73-
- image: circleci/node:16
77+
- image: cimg/node:20.12.2
7478
steps:
7579
- checkout
7680
- run:
7781
name: Install dependencies
78-
command: npm install
82+
command: npm ci
7983
- run:
8084
name: Run semantic release
8185
command: npm run semantic-release

docs/rules/assertion-before-screenshot.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1-
## Assertion Before Screenshot
1+
# Require screenshots to be preceded by an assertion (`cypress/assertion-before-screenshot`)
22

3+
<!-- end auto-generated rule header -->
34
If you take screenshots without assertions then you may get different screenshots depending on timing.
45

56
For example, if clicking a button makes some network calls and upon success, renders something, then the screenshot may sometimes have the new render and sometimes not.
67

8+
## Rule Details
9+
710
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.
811

9-
Invalid:
12+
Examples of **incorrect** code for this rule:
1013

1114
```js
1215
cy.visit('myUrl');
1316
cy.screenshot();
1417
```
1518

16-
Valid:
19+
Examples of **correct** code for this rule:
1720

1821
```js
1922
cy.visit('myUrl');
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1-
## No Assigning Return Values
1+
# Disallow assigning return values of `cy` calls (`cypress/no-assigning-return-values`)
2+
3+
💼 This rule is enabled in the ✅ `recommended` config.
4+
5+
<!-- end auto-generated rule header -->
6+
## Further Reading
27

38
See [the Cypress Best Practices guide](https://on.cypress.io/best-practices#Assigning-Return-Values).

0 commit comments

Comments
 (0)