Skip to content

Commit b974e98

Browse files
authored
docs: harmonize markdown docs with prettier linting (#266)
1 parent 8c9d1a0 commit b974e98

15 files changed

+93
-81
lines changed

CONTRIBUTING.md

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,47 @@ Thanks for taking the time to contribute! :smile:
44

55
## Preparation
66

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`
1010

1111
## Rule references
1212

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
1414

1515
## New rule
1616

1717
To add a new rule:
1818

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
2121
- select "ESLint Plugin"
2222
- 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:
2424
- `docs/rules/<rule-id>.md`
2525
- `lib/rules/<rule-id>.js`
2626
- `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`
2929
- Add a `meta.messages` property (see [MessageIds](https://eslint.org/docs/latest/extend/custom-rules#messageids))
3030
- 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
4141

4242
## Document generation
4343

4444
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
4748

4849
## Merging pull requests
4950

@@ -66,7 +67,7 @@ This information is for Cypress.io Members or Collaborators who merge pull reque
6667
```
6768

6869
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).
7071
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.

FLAT-CONFIG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Cypress ESLint Plugin - Flat Config
22

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).
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).

README.md

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ Prerequisites: [ESLint](https://www.npmjs.com/package/eslint) `v9`. Lower versio
1111
```sh
1212
npm install eslint eslint-plugin-cypress --save-dev
1313
```
14+
1415
or
16+
1517
```sh
1618
yarn add eslint eslint-plugin-cypress --dev
1719
```
@@ -36,15 +38,16 @@ import pluginCypress from 'eslint-plugin-cypress/flat' # deprecated
3638

3739
There are two specific configurations available:
3840

39-
| Configuration | Content |
40-
| --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
41+
| Configuration | Content |
42+
| --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
4143
| `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). |
4345

4446
## Rules
4547

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

50+
<!-- prettier-ignore-start -->
4851
<!-- begin auto-generated rules list -->
4952

5053
💼 Configurations enabled in.\
@@ -66,6 +69,7 @@ These rules enforce some of the [best practices recommended for using Cypress](h
6669
| [unsafe-to-chain-command](docs/rules/unsafe-to-chain-command.md) | disallow actions within chains ||
6770

6871
<!-- end auto-generated rules list -->
72+
<!-- prettier-ignore-end -->
6973

7074
## Usage examples
7175

@@ -74,25 +78,27 @@ In the following sections, different examples of possible configuration file con
7478
### Cypress
7579

7680
All rules are available by importing from `eslint-plugin-cypress` and can be individually activated.
81+
7782
- [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`
7883

7984
```js
8085
import pluginCypress from 'eslint-plugin-cypress'
8186
export default [
8287
{
8388
plugins: {
84-
cypress: pluginCypress
89+
cypress: pluginCypress,
8590
},
8691
rules: {
87-
'cypress/unsafe-to-chain-command': 'error'
88-
}
89-
}
92+
'cypress/unsafe-to-chain-command': 'error',
93+
},
94+
},
9095
]
9196
```
9297

9398
### Cypress recommended
9499

95100
The `eslint-plugin-cypress` [recommended rules](#rules) `configs.recommended` are activated, except for
101+
96102
- [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`
97103

98104
```js
@@ -101,9 +107,9 @@ export default [
101107
pluginCypress.configs.recommended,
102108
{
103109
rules: {
104-
'cypress/no-unnecessary-waiting': 'off'
105-
}
106-
}
110+
'cypress/no-unnecessary-waiting': 'off',
111+
},
112+
},
107113
]
108114
```
109115

@@ -113,9 +119,7 @@ The `configs.globals` are activated.
113119

114120
```js
115121
import pluginCypress from 'eslint-plugin-cypress'
116-
export default [
117-
pluginCypress.configs.globals
118-
]
122+
export default [pluginCypress.configs.globals]
119123
```
120124

121125
## Disable rules
@@ -174,6 +178,7 @@ During test spec development, [Mocha exclusive tests](https://mochajs.org/#exclu
174178
[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`.
175179

176180
The settings for individual `mocha` rules from the `configs.recommended` option are changed.
181+
177182
- [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`
178183
- [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`
179184

@@ -192,9 +197,9 @@ export default [
192197
'mocha/no-exclusive-tests': 'error',
193198
'mocha/no-pending-tests': 'error',
194199
'mocha/no-mocha-arrows': 'off',
195-
'cypress/no-unnecessary-waiting': 'off'
196-
}
197-
}
200+
'cypress/no-unnecessary-waiting': 'off',
201+
},
202+
},
198203
]
199204
```
200205

@@ -220,7 +225,7 @@ export default [
220225
rules: {
221226
'cypress/no-unnecessary-waiting': 'off',
222227
},
223-
}
228+
},
224229
]
225230
```
226231

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

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

67
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
1213
Examples of **incorrect** code for this rule:
1314

1415
```js
15-
cy.visit('myUrl');
16-
cy.screenshot();
16+
cy.visit('myUrl')
17+
cy.screenshot()
1718
```
1819

1920
Examples of **correct** code for this rule:
2021

2122
```js
22-
cy.visit('myUrl');
23-
cy.get('[data-test-id="my-element"]').should('be.visible');
24-
cy.screenshot();
23+
cy.visit('myUrl')
24+
cy.get('[data-test-id="my-element"]').should('be.visible')
25+
cy.screenshot()
2526
```

docs/rules/no-assigning-return-values.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
💼 This rule is enabled in the ✅ `recommended` config.
44

55
<!-- end auto-generated rule header -->
6+
67
## Further Reading
78

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

docs/rules/no-async-before.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Disallow using `async`/`await` in Cypress `before` methods (`cypress/no-async-before`)
22

33
<!-- end auto-generated rule header -->
4+
45
Cypress commands that return a promise may cause side effects in `before`/`beforeEach` hooks, possibly causing unexpected behavior.
56

67
## Rule Details
@@ -11,7 +12,7 @@ Examples of **incorrect** code for this rule:
1112

1213
```js
1314
describe('my feature', () => {
14-
before('my test case', async () => {
15+
before('my test case', async () => {
1516
await cy.get('.myClass')
1617
// other operations
1718
})
@@ -20,10 +21,8 @@ describe('my feature', () => {
2021

2122
```js
2223
describe('my feature', () => {
23-
before('my test case', async () => {
24-
cy
25-
.get('.myClass')
26-
.click()
24+
before('my test case', async () => {
25+
cy.get('.myClass').click()
2726

2827
await someAsyncFunction()
2928
})
@@ -34,7 +33,7 @@ Examples of **correct** code for this rule:
3433

3534
```js
3635
describe('my feature', () => {
37-
before('my test case', () => {
36+
before('my test case', () => {
3837
cy.get('.myClass')
3938
// other operations
4039
})

docs/rules/no-async-tests.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
💼 This rule is enabled in the ✅ `recommended` config.
44

55
<!-- end auto-generated rule header -->
6+
67
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.
78
An `async` function returns a promise under the hood, so a test using an `async` function will also error.
89

@@ -14,7 +15,7 @@ Examples of **incorrect** code for this rule:
1415

1516
```js
1617
describe('my feature', () => {
17-
it('my test case', async () => {
18+
it('my test case', async () => {
1819
await cy.get('.myClass')
1920
// other operations
2021
})
@@ -23,10 +24,8 @@ describe('my feature', () => {
2324

2425
```js
2526
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()
3029

3130
await someAsyncFunction()
3231
})
@@ -37,7 +36,7 @@ Examples of **correct** code for this rule:
3736

3837
```js
3938
describe('my feature', () => {
40-
it('my test case', () => {
39+
it('my test case', () => {
4140
cy.get('.myClass')
4241
// other operations
4342
})

docs/rules/no-chained-get.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Disallow chain of `cy.get()` calls (`cypress/no-chained-get`)
22

33
<!-- end auto-generated rule header -->
4+
45
This rule disallows the usage of chained `.get()` calls as `cy.get()` always starts its search from the cy.root element.
56

67
## Rule Details
@@ -14,6 +15,5 @@ cy.get('parent').get('child')
1415
Examples of **correct** code for this rule:
1516

1617
```js
17-
cy.get('parent')
18-
.find('child')
18+
cy.get('parent').find('child')
1919
```

docs/rules/no-debug.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
# Disallow using `cy.debug()` calls (`cypress/no-debug`)
22

33
<!-- end auto-generated rule header -->
4+
45
It is recommended to remove any [cy.debug](https://on.cypress.io/debug) commands before committing specs to avoid other developers getting unexpected results.
56

67
## Rule Details
78

89
Examples of **incorrect** code for this rule:
910

1011
```js
11-
cy.debug();
12-
cy.get('selector').debug();
12+
cy.debug()
13+
cy.get('selector').debug()
1314
```
1415

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

0 commit comments

Comments
 (0)