You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+25-24Lines changed: 25 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,46 +4,47 @@ Thanks for taking the time to contribute! :smile:
4
4
5
5
## Preparation
6
6
7
-
* Fork and clone this repository
8
-
* Branch from the default `master` branch using a descriptive new branch name
9
-
* Install dependencies with `npm ci`
7
+
- Fork and clone this repository
8
+
- Branch from the default `master` branch using a descriptive new branch name
9
+
- Install dependencies with `npm ci`
10
10
11
11
## Rule references
12
12
13
-
* Refer to the [ESLint documentation](https://eslint.org/docs/latest/) and the [Custom Rules](https://eslint.org/docs/latest/extend/custom-rules) page
13
+
- Refer to the [ESLint documentation](https://eslint.org/docs/latest/) and the [Custom Rules](https://eslint.org/docs/latest/extend/custom-rules) page
14
14
15
15
## New rule
16
16
17
17
To add a new rule:
18
18
19
-
* Follow the instructions in the ESLint [generator-eslint](https://www.npmjs.com/package/generator-eslint) documentation to install [Yeoman](https://www.npmjs.com/package/yo) and the generator
20
-
* Run the new rule generator `yo eslint:rule` and answer the questions
19
+
- Follow the instructions in the ESLint [generator-eslint](https://www.npmjs.com/package/generator-eslint) documentation to install [Yeoman](https://www.npmjs.com/package/yo) and the generator
20
+
- Run the new rule generator `yo eslint:rule` and answer the questions
21
21
- select "ESLint Plugin"
22
22
- for "Type a short description of this rule" provide text which starts with one of "enforce", "require" or "disallow" (all lower case)
23
-
* Yeoman creates three boilerplate files:
23
+
- Yeoman creates three boilerplate files:
24
24
-`docs/rules/<rule-id>.md`
25
25
-`lib/rules/<rule-id>.js`
26
26
-`test/rules/<rule-id>.js`
27
-
* Run `npm run lint-fix`
28
-
* Address the linting errors by editing `lib/rules/<rule-id>.js`
27
+
- Run `npm run lint-fix`
28
+
- Address the linting errors by editing `lib/rules/<rule-id>.js`
29
29
- Add a `meta.messages` property (see [MessageIds](https://eslint.org/docs/latest/extend/custom-rules#messageids))
30
30
- Select the appropriate `meta.type` property using `problem`, `suggestion`, or `layout`
31
-
* Complete the new rule by adding content to the three files previously created
32
-
* Run `eslint-doc-generator` to generate automated documentation sections (see [Document generation](#document-generation) below)
33
-
* Review documentation changes
34
-
* Run `npm run lint`
35
-
* Run `npm run format`
36
-
* Run `npm test` to run [Vitest](https://vitest.dev/)
37
-
* Make sure all tests are passing
38
-
* Add the rule to [flat.js](https://github.com/cypress-io/eslint-plugin-cypress/blob/master/lib/flat.js)
39
-
* Create a git commit with a commit message similar to: `feat: add rule <description>` (see [commit message conventions](https://github.com/semantic-release/semantic-release#commit-message-format))
40
-
* Create a PR from your branch
31
+
- Complete the new rule by adding content to the three files previously created
32
+
- Run `eslint-doc-generator` to generate automated documentation sections (see [Document generation](#document-generation) below)
33
+
- Review documentation changes
34
+
- Run `npm run lint`
35
+
- Run `npm run format`
36
+
- Run `npm test` to run [Vitest](https://vitest.dev/)
37
+
- Make sure all tests are passing
38
+
- Add the rule to [flat.js](https://github.com/cypress-io/eslint-plugin-cypress/blob/master/lib/flat.js)
39
+
- Create a git commit with a commit message similar to: `feat: add rule <description>` (see [commit message conventions](https://github.com/semantic-release/semantic-release#commit-message-format))
40
+
- Create a PR from your branch
41
41
42
42
## Document generation
43
43
44
44
This plugin uses the ESLint [eslint-doc-generator](https://www.npmjs.com/package/eslint-doc-generator) to generate consistent documentation.
45
-
* Install with `npm install eslint-doc-generator -g`
46
-
* Run `eslint-doc-generator` in the root directory of the plugin
45
+
46
+
- Install with `npm install eslint-doc-generator -g`
47
+
- Run `eslint-doc-generator` in the root directory of the plugin
47
48
48
49
## Merging pull requests
49
50
@@ -66,7 +67,7 @@ This information is for Cypress.io Members or Collaborators who merge pull reque
66
67
```
67
68
68
69
1. New versions of this module will be released automatically by the CI pipeline when any PR with a triggering commit message is merged to the `master` branch: see the `release` job of [circle.yml](circle.yml).
69
-
This will create a new [GitHub release](https://github.com/cypress-io/eslint-plugin-cypress/releases) and publish it to [eslint-plugin-cypress](https://www.npmjs.com/package/eslint-plugin-cypress) on the [npm registry](https://docs.npmjs.com/about-the-public-npm-registry).
70
+
This will create a new [GitHub release](https://github.com/cypress-io/eslint-plugin-cypress/releases) and publish it to [eslint-plugin-cypress](https://www.npmjs.com/package/eslint-plugin-cypress) on the [npm registry](https://docs.npmjs.com/about-the-public-npm-registry).
70
71
1. The module's CI is configured to use the [default Angular release rules](https://github.com/semantic-release/commit-analyzer/blob/master/lib/default-release-rules.js).
71
-
This means that only `feat:`, `fix:` and `perf:` trigger a new release.
72
-
Other Angular commit types listed in the [Angular commit message guidelines](https://github.com/angular/angular/blob/main/contributing-docs/commit-message-guidelines.md) can be used for documentation purposes, however they are ignored by the currently configured release process.
72
+
This means that only `feat:`, `fix:` and `perf:` trigger a new release.
73
+
Other Angular commit types listed in the [Angular commit message guidelines](https://github.com/angular/angular/blob/main/contributing-docs/commit-message-guidelines.md) can be used for documentation purposes, however they are ignored by the currently configured release process.
Please refer to the [README](./README.md) document which describes how to use `eslint-plugin-cypress` with an ESLint `v9` (default) [flat configuration](https://eslint.org/docs/latest/use/configure/configuration-files).
3
+
Please refer to the [README](./README.md) document which describes how to use `eslint-plugin-cypress` with an ESLint `v9` (default) [flat configuration](https://eslint.org/docs/latest/use/configure/configuration-files).
|`configs.globals`| defines globals `cy`, `Cypress`, `expect`, `assert` and `chai` used in Cypress test specs as well as `globals.browser` and `globals.mocha` from [globals](https://www.npmjs.com/package/globals). There are no default rules enabled in this configuration. |
42
-
|`configs.recommended`| enables [recommended Rules](#rules). It includes also `configs.global` (see above). |
44
+
|`configs.recommended`| enables [recommended Rules](#rules). It includes also `configs.global` (see above). |
43
45
44
46
## Rules
45
47
46
48
These rules enforce some of the [best practices recommended for using Cypress](https://on.cypress.io/best-practices).
47
49
50
+
<!-- prettier-ignore-start -->
48
51
<!-- begin auto-generated rules list -->
49
52
50
53
💼 Configurations enabled in.\
@@ -66,6 +69,7 @@ These rules enforce some of the [best practices recommended for using Cypress](h
66
69
|[unsafe-to-chain-command](docs/rules/unsafe-to-chain-command.md)| disallow actions within chains | ✅ |
67
70
68
71
<!-- end auto-generated rules list -->
72
+
<!-- prettier-ignore-end -->
69
73
70
74
## Usage examples
71
75
@@ -74,25 +78,27 @@ In the following sections, different examples of possible configuration file con
74
78
### Cypress
75
79
76
80
All rules are available by importing from `eslint-plugin-cypress` and can be individually activated.
81
+
77
82
-[cypress/unsafe-to-chain-command](https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/unsafe-to-chain-command.md) is activated and set to `error`
78
83
79
84
```js
80
85
importpluginCypressfrom'eslint-plugin-cypress'
81
86
exportdefault [
82
87
{
83
88
plugins: {
84
-
cypress: pluginCypress
89
+
cypress: pluginCypress,
85
90
},
86
91
rules: {
87
-
'cypress/unsafe-to-chain-command':'error'
88
-
}
89
-
}
92
+
'cypress/unsafe-to-chain-command':'error',
93
+
},
94
+
},
90
95
]
91
96
```
92
97
93
98
### Cypress recommended
94
99
95
100
The `eslint-plugin-cypress`[recommended rules](#rules)`configs.recommended` are activated, except for
101
+
96
102
-[cypress/no-unnecessary-waiting](https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/no-unnecessary-waiting.md) which is set to `off`
97
103
98
104
```js
@@ -101,9 +107,9 @@ export default [
101
107
pluginCypress.configs.recommended,
102
108
{
103
109
rules: {
104
-
'cypress/no-unnecessary-waiting':'off'
105
-
}
106
-
}
110
+
'cypress/no-unnecessary-waiting':'off',
111
+
},
112
+
},
107
113
]
108
114
```
109
115
@@ -113,9 +119,7 @@ The `configs.globals` are activated.
113
119
114
120
```js
115
121
importpluginCypressfrom'eslint-plugin-cypress'
116
-
exportdefault [
117
-
pluginCypress.configs.globals
118
-
]
122
+
exportdefault [pluginCypress.configs.globals]
119
123
```
120
124
121
125
## Disable rules
@@ -174,6 +178,7 @@ During test spec development, [Mocha exclusive tests](https://mochajs.org/#exclu
174
178
[eslint-plugin-mocha@^11](https://www.npmjs.com/package/eslint-plugin-mocha) is added to the example [Cypress recommended](#cypress-recommended). This version of the plugin supports only flat file configurations with the option `configs.recommended`.
175
179
176
180
The settings for individual `mocha` rules from the `configs.recommended` option are changed.
181
+
177
182
-[mocha/no-exclusive-tests](https://github.com/lo1tuma/eslint-plugin-mocha/blob/main/docs/rules/no-exclusive-tests.md) and [mocha/no-pending-tests](https://github.com/lo1tuma/eslint-plugin-mocha/blob/main/docs/rules/no-pending-tests.md) are set to `error` instead of `warn`
178
183
-[mocha/no-mocha-arrows](https://github.com/lo1tuma/eslint-plugin-mocha/blob/main/docs/rules/no-mocha-arrows.md) is set to `off` instead of `error`
# Require screenshots to be preceded by an assertion (`cypress/assertion-before-screenshot`)
2
2
3
3
<!-- end auto-generated rule header -->
4
+
4
5
If you take screenshots without assertions then you may get different screenshots depending on timing.
5
6
6
7
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.
@@ -12,14 +13,14 @@ This rule checks there is an assertion making sure your application state is cor
Copy file name to clipboardExpand all lines: docs/rules/no-async-tests.md
+5-6Lines changed: 5 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,6 +3,7 @@
3
3
💼 This rule is enabled in the ✅ `recommended` config.
4
4
5
5
<!-- end auto-generated rule header -->
6
+
6
7
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.
7
8
An `async` function returns a promise under the hood, so a test using an `async` function will also error.
8
9
@@ -14,7 +15,7 @@ Examples of **incorrect** code for this rule:
14
15
15
16
```js
16
17
describe('my feature', () => {
17
-
it('my test case', async () => {
18
+
it('my test case', async () => {
18
19
awaitcy.get('.myClass')
19
20
// other operations
20
21
})
@@ -23,10 +24,8 @@ describe('my feature', () => {
23
24
24
25
```js
25
26
describe('my feature', () => {
26
-
it('my test case', async () => {
27
-
cy
28
-
.get('.myClass')
29
-
.click()
27
+
it('my test case', async () => {
28
+
cy.get('.myClass').click()
30
29
31
30
awaitsomeAsyncFunction()
32
31
})
@@ -37,7 +36,7 @@ Examples of **correct** code for this rule:
Copy file name to clipboardExpand all lines: docs/rules/no-debug.md
+3-2Lines changed: 3 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,16 @@
1
1
# Disallow using `cy.debug()` calls (`cypress/no-debug`)
2
2
3
3
<!-- end auto-generated rule header -->
4
+
4
5
It is recommended to remove any [cy.debug](https://on.cypress.io/debug) commands before committing specs to avoid other developers getting unexpected results.
0 commit comments